1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 459971 New SerialPort support. First step is Mac library.

Java classes are defined and a pretty simple native library for
Mac is there. Tested with Arduino so I know reading works. This
implementation should work for Linux as well. Windows is going to
be the hard one.

Not checking in the binaries yet until I get more testing with them.

Also remove ppc native libraries for Mac since that hasn't been
supported in a long time.

Change-Id: If4ffbc6e73a7656a47c2f45b875be0842c482b05
This commit is contained in:
Doug Schaefer 2015-02-16 12:19:18 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent 52c80c124e
commit 275feb6874
14 changed files with 457 additions and 73 deletions

View file

@ -0,0 +1 @@
*.o

View file

@ -13,42 +13,26 @@
# makefile for libspawner.so
# See http://developer.apple.com/documentation/Java/Conceptual/Java141Development/Core_APIs/chapter_6_section_4.html
JAVA_HOME = /Library/Java/Home
ifeq ($(JAVA_HOME),)
$(warning JAVA_HOME not set in environment)
endif
JAVA_HOME = $(shell echo /Library/Java/JavaVirtualMachines/jdk1.8.0_*.jdk/Contents/Home)
# Defaults which can be overridden.
OS = macosx
ARCH_PPC = ppc
ARCH_X86 = x86
ARCH_X86_64 = x86_64
JDK_INCLUDES= $(JAVA_HOME)/include
CC=gcc
LD=libtool
CPPFLAGS = -I. -I$(JDK_INCLUDES) #-I$(JDK_OS_INCLUDES)
CPPFLAGS = -I. -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
CFLAGS +=-fPIC -D_REENTRANT
ARCH_FLAG_PPC = -arch ppc
ARCH_FLAG_X86 = -arch i386
ARCH_FLAG_X86_64 = -arch x86_64
INSTALL_DIR_PPC = ../os/$(OS)/$(ARCH_PPC)
INSTALL_DIR_X86 = ../os/$(OS)/$(ARCH_X86)
INSTALL_DIR_X86_64 = ../os/$(OS)/$(ARCH_X86_64)
LIB_NAME_SPAWNER = libspawner.dylib
LIB_NAME_FULL_SPAWNER_PPC = $(INSTALL_DIR_PPC)/libspawner.jnilib
LIB_NAME_FULL_SPAWNER_X86 = $(INSTALL_DIR_X86)/libspawner.jnilib
LIB_NAME_FULL_SPAWNER_X86_64 = $(INSTALL_DIR_X86_64)/libspawner.jnilib
OBJS_SPAWNER_PPC = spawner_$(ARCH_PPC).o \
io_$(ARCH_PPC).o \
exec_unix_$(ARCH_PPC).o \
exec_pty_$(ARCH_PPC).o \
openpty_$(ARCH_PPC).o \
pfind_$(ARCH_PPC).o
OBJS_SPAWNER_X86 = spawner_$(ARCH_X86).o \
io_$(ARCH_X86).o \
exec_unix_$(ARCH_X86).o \
@ -62,32 +46,27 @@ OBJS_SPAWNER_X86_64 = spawner_$(ARCH_X86_64).o \
openpty_$(ARCH_X86_64).o \
pfind_$(ARCH_X86_64).o
LIB_NAME_PTY = libpty.so
LIB_NAME_FULL_PTY_PPC = $(INSTALL_DIR_PPC)/libpty.jnilib
LIB_NAME_FULL_PTY_X86 = $(INSTALL_DIR_X86)/libpty.jnilib
LIB_NAME_FULL_PTY_X86_64 = $(INSTALL_DIR_X86_64)/libpty.jnilib
OBJS_PTY_PPC = openpty_$(ARCH_PPC).o pty_$(ARCH_PPC).o ptyio_$(ARCH_PPC).o
OBJS_PTY_X86 = openpty_$(ARCH_X86).o pty_$(ARCH_X86).o ptyio_$(ARCH_X86).o
OBJS_PTY_X86_64 = openpty_$(ARCH_X86_64).o pty_$(ARCH_X86_64).o ptyio_$(ARCH_X86_64).o
OBJS_PPC = $(OBJS_SPAWNER_PPC) $(OBJS_PTY_PPC)
OBJS_X86 = $(OBJS_SPAWNER_X86) $(OBJS_PTY_X86)
OBJS_X86_64 = $(OBJS_SPAWNER_X86_64) $(OBJS_PTY_X86_64)
LIB_NAME_FULL_SERIAL_X86 = $(INSTALL_DIR_X86)/libserial.jnilib
LIB_NAME_FULL_SERIAL_X86_64 = $(INSTALL_DIR_X86_64)/libserial.jnilib
OBJS_SERIAL_X86 = serial_$(ARCH_X86).o
OBJS_SERIAL_X86_64 = serial_$(ARCH_X86_64).o
all: ppc x86 x86_64
OBJS_X86 = $(OBJS_SPAWNER_X86) $(OBJS_PTY_X86) $(OBJS_SERIAL_X86)
OBJS_X86_64 = $(OBJS_SPAWNER_X86_64) $(OBJS_PTY_X86_64) $(OBJS_SERIAL_X86_64)
ppc: $(LIB_NAME_FULL_SPAWNER_PPC) $(LIB_NAME_FULL_PTY_PPC)
all: x86 x86_64
x86: $(LIB_NAME_FULL_SPAWNER_X86) $(LIB_NAME_FULL_PTY_X86)
x86: $(LIB_NAME_FULL_SPAWNER_X86) $(LIB_NAME_FULL_PTY_X86) $(LIB_NAME_FULL_SERIAL_X86)
x86_64: $(LIB_NAME_FULL_SPAWNER_X86_64) $(LIB_NAME_FULL_PTY_X86_64)
x86_64: $(LIB_NAME_FULL_SPAWNER_X86_64) $(LIB_NAME_FULL_PTY_X86_64) $(LIB_NAME_FULL_SERIAL_X86_64)
rebuild: clean all
$(LIB_NAME_FULL_SPAWNER_PPC) : $(OBJS_SPAWNER_PPC)
mkdir -p $(INSTALL_DIR_PPC)
$(CC) -dynamiclib $(ARCH_FLAG_PPC) -o $(LIB_NAME_FULL_SPAWNER_PPC) $(OBJS_SPAWNER_PPC) -lc -framework JavaVM
$(LIB_NAME_FULL_SPAWNER_X86) : $(OBJS_SPAWNER_X86)
mkdir -p $(INSTALL_DIR_X86)
$(CC) -dynamiclib $(ARCH_FLAG_X86) -o $(LIB_NAME_FULL_SPAWNER_X86) $(OBJS_SPAWNER_X86) -lc -framework JavaVM
@ -96,10 +75,6 @@ $(LIB_NAME_FULL_SPAWNER_X86_64) : $(OBJS_SPAWNER_X86_64)
mkdir -p $(INSTALL_DIR_X86_64)
$(CC) -dynamiclib $(ARCH_FLAG_X86_64) -o $(LIB_NAME_FULL_SPAWNER_X86_64) $(OBJS_SPAWNER_X86_64) -lc -framework JavaVM
$(LIB_NAME_FULL_PTY_PPC): $(OBJS_PTY_PPC)
mkdir -p $(INSTALL_DIR_PPC)
$(CC) -dynamiclib $(ARCH_FLAG_PPC) -o $(LIB_NAME_FULL_PTY_PPC) $(OBJS_PTY_PPC) -lc -framework JavaVM
$(LIB_NAME_FULL_PTY_X86): $(OBJS_PTY_X86)
mkdir -p $(INSTALL_DIR_X86)
$(CC) -dynamiclib $(ARCH_FLAG_X86) -o $(LIB_NAME_FULL_PTY_X86) $(OBJS_PTY_X86) -lc -framework JavaVM
@ -108,32 +83,13 @@ $(LIB_NAME_FULL_PTY_X86_64): $(OBJS_PTY_X86_64)
mkdir -p $(INSTALL_DIR_X86_64)
$(CC) -dynamiclib $(ARCH_FLAG_X86_64) -o $(LIB_NAME_FULL_PTY_X86_64) $(OBJS_PTY_X86_64) -lc -framework JavaVM
spawner_$(ARCH_PPC).o: spawner.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ spawner.c
$(LIB_NAME_FULL_SERIAL_X86): $(OBJS_SERIAL_X86)
mkdir -p $(INSTALL_DIR_X86)
$(CC) -dynamiclib $(ARCH_FLAG_X86) -o $(LIB_NAME_FULL_SERIAL_X86) $(OBJS_SERIAL_X86) -lc -framework JavaVM
io_$(ARCH_PPC).o: io.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ io.c
exec_unix_$(ARCH_PPC).o: exec_unix.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ exec_unix.c
exec_pty_$(ARCH_PPC).o: exec_pty.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ exec_pty.c
openpty_$(ARCH_PPC).o: openpty.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ openpty.c
pfind_$(ARCH_PPC).o: pfind.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ pfind.c
openpty_$(ARCH_PPC).o: openpty.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ openpty.c
pty_$(ARCH_PPC).o: pty.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ pty.c
ptyio_$(ARCH_PPC).o: ptyio.c
$(CC) $(CFLAGS) $(ARCH_FLAG_PPC) $(CPPFLAGS) -c -o $@ ptyio.c
$(LIB_NAME_FULL_SERIAL_X86_64): $(OBJS_SERIAL_X86_64)
mkdir -p $(INSTALL_DIR_X86_64)
$(CC) -dynamiclib $(ARCH_FLAG_X86_64) -o $(LIB_NAME_FULL_SERIAL_X86_64) $(OBJS_SERIAL_X86_64) -lc -framework JavaVM
spawner_$(ARCH_X86).o: spawner.c
$(CC) $(CFLAGS) $(ARCH_FLAG_X86) $(CPPFLAGS) -c -o $@ spawner.c
@ -159,6 +115,9 @@ pty_$(ARCH_X86).o: pty.c
ptyio_$(ARCH_X86).o: ptyio.c
$(CC) $(CFLAGS) $(ARCH_FLAG_X86) $(CPPFLAGS) -c -o $@ ptyio.c
serial_$(ARCH_X86).o: serial.c
$(CC) $(CFLAGS) $(ARCH_FLAG_X86) $(CPPFLAGS) -c -o $@ serial.c
spawner_$(ARCH_X86_64).o: spawner.c
$(CC) $(CFLAGS) $(ARCH_FLAG_X86_64) $(CPPFLAGS) -c -o $@ spawner.c
@ -183,7 +142,9 @@ pty_$(ARCH_X86_64).o: pty.c
ptyio_$(ARCH_X86_64).o: ptyio.c
$(CC) $(CFLAGS) $(ARCH_FLAG_X86_64) $(CPPFLAGS) -c -o $@ ptyio.c
serial_$(ARCH_X86_64).o: serial.c
$(CC) $(CFLAGS) $(ARCH_FLAG_X86_64) $(CPPFLAGS) -c -o $@ serial.c
clean :
$(RM) $(OBJS_PPC) $(LIB_NAME_FULL_SPAWNER_PPC) $(LIB_NAME_FULL_PTY_PPC)
$(RM) $(OBJS_X86) $(LIB_NAME_FULL_SPAWNER_X86) $(LIB_NAME_FULL_PTY_X86)
$(RM) $(OBJS_X86_64) $(LIB_NAME_FULL_SPAWNER_X86_64) $(LIB_NAME_FULL_PTY_X86_64)

View file

@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <jni.h>
JNIEXPORT jlong JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_open0
(JNIEnv *env, jobject jobj, jstring portName, jint baudRate, jint byteSize, jint parity, jint stopBits)
{
const char * cportName = (*env)->GetStringUTFChars(env, portName, NULL);
int fd = open(cportName, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd >= 0) {
// Turn off NDELAY
int flags = fcntl(fd, F_GETFL, 0);
flags &= ~O_NDELAY;
fcntl(fd, F_SETFL, flags);
struct termios newtio;
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = CLOCAL | CREAD;
cfsetispeed(&newtio, baudRate);
cfsetospeed(&newtio, baudRate);
switch (byteSize) {
case 5:
newtio.c_cflag |= CS5;
break;
case 6:
newtio.c_cflag |= CS6;
break;
case 7:
newtio.c_cflag |= CS7;
break;
case 8:
newtio.c_cflag |= CS8;
break;
}
switch (parity) {
case 0: // None
break;
case 1: // Even
newtio.c_cflag |= PARENB;
break;
case 2: // Odd
newtio.c_cflag |= (PARENB | PARODD);
break;
}
switch (stopBits) {
case 0: // 1
break;
case 1: // 2
newtio.c_cflag |= CSTOPB;
break;
}
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
}
return fd;
}
JNIEXPORT void JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_close0
(JNIEnv *env, jobject jobj, jlong handle)
{
close(handle);
}
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_read0
(JNIEnv *env, jobject jobj, jlong handle)
{
char buff;
int res = read(handle, &buff, 1);
return res < 0 ? -1 : buff;
}
JNIEXPORT void JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_write0
(JNIEnv *env, jobject jobj, jlong handle, jint b)
{
char buff = b;
write(handle, &buff, 1);
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>

View file

@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -77,7 +77,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16

View file

@ -9,7 +9,8 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.core;native=split;mandatory:=native,
org.eclipse.cdt.utils;native=split;mandatory:=native,
org.eclipse.cdt.utils.pty;version="5.7",
org.eclipse.cdt.utils.serial,
org.eclipse.cdt.utils.spawner;version="5.7"
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-RequiredExecutionEnvironment: JavaSE-1.7

View file

@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.utils.serial;
public enum BaudRate {
B0(0),
B50(50),
B75(75),
B110(110),
B134(134),
B150(150),
B200(200),
B300(300),
B600(600),
B1200(1200),
B1800(1800),
B2400(2400),
B4800(4800),
B7200(7200),
B9600(9600),
B14400(14400),
B19200(19200),
B28800(28800),
B38400(38400),
B57600(57600),
B76800(76800),
B115200(115200),
B230400(230400);
private final int rate;
private BaudRate(int rate) {
this.rate = rate;
}
public int getRate() {
return rate;
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.utils.serial;
public enum ByteSize {
B5(5),
B6(6),
B7(7),
B8(8);
private final int size;
private ByteSize(int size) {
this.size = size;
}
public int getSize() {
return size;
}
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.utils.serial;
public enum Parity {
None,
Even,
Odd
}

View file

@ -0,0 +1,185 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.utils.serial;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.Platform;
public class SerialPort {
private final String portName;
private boolean isOpen;
private BaudRate baudRate = BaudRate.B115200;
private ByteSize byteSize = ByteSize.B8;
private Parity parity = Parity.None;
private StopBits stopBits = StopBits.S1;
private long handle;
private static final String PORT_OPEN = "Port is open";
static {
System.loadLibrary("serial"); //$NON-NLS-1$
}
/**
* Create a serial port that connect to the given serial device.
*
* @param portName name for the serial device.
*/
public SerialPort(String portName) {
this.portName = portName;
}
/**
* List the available serial ports.
*
* @return serial ports
*/
public static String[] list() {
if (Platform.getOS().equals(Platform.OS_MACOSX)) {
File dev = new File("/dev"); //$NON-NLS-1$
final Pattern pattern = Pattern.compile("tty\\.(usbserial|usbmodem).*"); //$NON-NLS-1$
File[] files = dev.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return pattern.matcher(name).matches();
}
});
if (files == null) {
return new String[0];
}
String[] names = new String[files.length];
for (int i = 0; i < files.length; i++) {
names[i] = files[i].getAbsolutePath();
}
return names;
} else {
return new String[0];
}
}
/**
* Return the name for this serial port.
*
* @return serial port name
*/
public String getPortName() {
return portName;
}
public void open() throws IOException {
handle = open0(portName, baudRate.getRate(), byteSize.getSize(), parity.ordinal(), stopBits.ordinal());
isOpen = true;
}
private native long open0(String portName, int baudRate, int byteSize, int parity, int stopBits) throws IOException;
public void close() throws IOException {
close0(handle);
isOpen = false;
}
private native void close0(long handle) throws IOException;
public boolean isOpen() {
return isOpen;
}
public void setBaudRate(BaudRate rate) throws IOException {
if (isOpen) {
throw new IOException(PORT_OPEN);
}
this.baudRate = rate;
}
public BaudRate getBaudRate() {
return baudRate;
}
public void setByteSize(ByteSize size) throws IOException {
if (isOpen) {
throw new IOException(PORT_OPEN);
}
this.byteSize = size;
}
public ByteSize getByteSize() {
return byteSize;
}
public void setParity(Parity parity) throws IOException {
if (isOpen) {
throw new IOException(PORT_OPEN);
}
this.parity = parity;
}
public Parity getParity() {
return parity;
}
public void setStopBit(StopBits stopBits) throws IOException {
if (isOpen) {
throw new IOException(PORT_OPEN);
}
this.stopBits = stopBits;
}
public StopBits getStopBits() {
return stopBits;
}
public InputStream getInputStream() {
return new InputStream() {
@Override
public int read() throws IOException {
if (isOpen()) {
return read0(handle);
} else {
return -1;
}
}
@Override
public void close() throws IOException {
SerialPort.this.close();
}
};
}
private native int read0(long handle) throws IOException;
public OutputStream getOutputStream() {
return new OutputStream() {
@Override
public void write(int b) throws IOException {
if (isOpen()) {
write0(handle, b);
}
}
@Override
public void close() throws IOException {
SerialPort.this.close();
}
};
}
private native void write0(long handle, int b) throws IOException;
}

View file

@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.utils.serial;
public enum StopBits {
S1,
S2
}

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.remote.internal.core;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class Activator implements BundleActivator {
@ -41,4 +42,15 @@ public class Activator implements BundleActivator {
Activator.context = null;
}
/**
* Return the OSGi service with the given service interface.
*
* @param service service interface
* @return the specified service or null if it's not registered
*/
public static <T> T getService(Class<T> service) {
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
}