Everyware™ Software Framework
· Overview
· System Manager Service Example
This example shows how to use the System Manager Service as well as create a bundle that uses two services rather than just one. We will start with a new project that is very similar to the project used in the Hello World Using the ESF Log Service example.
In this example you will learn how to:
The System Manager (SM) Service is described here. Reading before proceeding is suggested so you have a basic understanding of what the SM Service does. Then begin by creating a new Plug-in Project in Eclipse. If you need a refresher on this you can revisit it here. This is the basic information on the project.
Below is the Activator code for this project.
package com.esf.example.system.manager.bundle;
import org.eclipse.soda.sat.core.framework.BaseBundleActivator;
import com.esf.core.logger.service.IEsfLoggerService;
import com.esf.core.system.manager.service.ISystemManagerService;
import com.esf.example.system.manager.SystemManagerExample;
public class Activator extends BaseBundleActivator {
private SystemManagerExample systemManagerExample;
protected void activate() {
systemManagerExample = new SystemManagerExample();
systemManagerExample.bind(getIEsfLoggerService(), getISystemManagerService());
}
protected void deactivate() {
systemManagerExample.unbind();
systemManagerExample = null;
}
private IEsfLoggerService getIEsfLoggerService() {
return (IEsfLoggerService) getImportedService(IEsfLoggerService.SERVICE_NAME);
}
private ISystemManagerService getISystemManagerService() {
return (ISystemManagerService) getImportedService(ISystemManagerService.SERVICE_NAME);
}
protected String[] getImportedServiceNames() {
return new String[] {
IEsfLoggerService.SERVICE_NAME,
ISystemManagerService.SERVICE_NAME
};
}
}
Note a few changes from the hello world example. The first is that we have added a private method called getISystemManagerService() which gets the ISystemManagerService from the OSGi framework. We then call this method from the call to SystemManagerExample.bind() to pass in references to both of our required services. The final change was to getImportedServiceNames(). Again, this method is called by SAT to allow us to tell SAT what we require in order to start. Since we are now dependent on two services we must add both to the list.
Now we can look at the main implementation class. This is shown below.
package com.esf.example.system.manager;
import java.util.ArrayList;
import com.esf.core.logger.service.IEsfLoggerService;
import com.esf.core.system.manager.service.EsfSerialPort;
import com.esf.core.system.manager.service.ISystemManagerService;
public class SystemManagerExample {
private static final String LABEL = "com.esf.example.system.manager.SystemManagerExample: ";
private IEsfLoggerService esfLoggerService;
private ISystemManagerService systemManagerService;
public void bind(IEsfLoggerService esfLoggerService, ISystemManagerService systemManagerService) {
this.esfLoggerService = esfLoggerService;
this.systemManagerService = systemManagerService;
displayProperties();
}
public void unbind() {
this.systemManagerService = null;
this.esfLoggerService = null;
}
private void displayProperties() {
try {
esfLoggerService.logInfo(LABEL + "systemManagerService.getCompany(): " + systemManagerService.getCompany());
esfLoggerService.logInfo(LABEL + "systemManagerService.getEntity(): " + systemManagerService.getEntity());
esfLoggerService.logInfo(LABEL + "systemManagerService.getEsfBaseBundleDirectory(): " + systemManagerService.getEsfBaseBundleDirectory());
esfLoggerService.logInfo(LABEL + "systemManagerService.getEsfConfigDirectory(): " + systemManagerService.getEsfConfigDirectory());
esfLoggerService.logInfo(LABEL + "systemManagerService.getEsfHome(): " + systemManagerService.getEsfHome());
esfLoggerService.logInfo(LABEL + "systemManagerService.getFileSeparator(): " + systemManagerService.getFileSeparator());
esfLoggerService.logInfo(LABEL + "systemManagerService.getJavaHome(): " + systemManagerService.getJavaHome());
esfLoggerService.logInfo(LABEL + "systemManagerService.getJavaProfile(): " + systemManagerService.getJavaProfile());
esfLoggerService.logInfo(LABEL + "systemManagerService.getJavaVmName(): " + systemManagerService.getJavaVmName());
esfLoggerService.logInfo(LABEL + "systemManagerService.getJavaVmVersion(): " + systemManagerService.getJavaVmVersion());
esfLoggerService.logInfo(LABEL + "systemManagerService.getOsArch(): " + systemManagerService.getOsArch());
esfLoggerService.logInfo(LABEL + "systemManagerService.getOsDistro(): " + systemManagerService.getOsDistro());
esfLoggerService.logInfo(LABEL + "systemManagerService.getOsDistroVersion(): " + systemManagerService.getOsDistroVersion());
esfLoggerService.logInfo(LABEL + "systemManagerService.getOsName(): " + systemManagerService.getOsName());
esfLoggerService.logInfo(LABEL + "systemManagerService.getOsVersion(): " + systemManagerService.getOsVersion());
esfLoggerService.logInfo(LABEL + "systemManagerService.getPlatform(): " + systemManagerService.getPlatform());
esfLoggerService.logInfo(LABEL + "systemManagerService.getPrimaryMacAddress(): " + systemManagerService.getPrimaryMacAddress());
esfLoggerService.logInfo(LABEL + "systemManagerService.getProductVersion(): " + systemManagerService.getProductVersion());
esfLoggerService.logInfo(LABEL + "systemManagerService.getProject(): " + systemManagerService.getProject());
esfLoggerService.logInfo(LABEL + "systemManagerService.getTemporaryConfigDirectory(): " + systemManagerService.getTemporaryConfigDirectory());
ArrayList comPorts = systemManagerService.getComPorts();
ArrayList ethernetInterfaces = systemManagerService.getEthernetInterfaces();
for(int i=0; i<comPorts.size(); i++) {
EsfSerialPort port = (EsfSerialPort) comPorts.get(i);
esfLoggerService.logInfo(LABEL + "systemManagerService.getComPorts().get(" + i + ").getUsbPort(): " + port.getUsbPort());
esfLoggerService.logInfo(LABEL + "systemManagerService.getComPorts().get(" + i + ").getDeviceNode(): " + port.getDeviceNode());
}
for(int i=0; i<ethernetInterfaces.size(); i++) {
esfLoggerService.logInfo(LABEL + "systemManagerService.getEthernetInterfaces().get(" + i + "): " + (String)ethernetInterfaces.get(i));
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
This class has the bind() and unbind() methods as our hello world example did. However, we are also calling a new private method called displayProperties() from bind. This means upon bundle startup, when bind is called, this will also be run. This is a simple method to show the usage of the System Managers API. All methods return Strings except the getComPorts() method. This returns EsfSerialPort Objects to keep the relationship of USB ports to device nodes one to one. In WRL (so in turn ESF) serial ports can be dynamic. In most embedded systems the link between the physical/static USB port is more important than the dynamic device node name. Using this ensures that in application code you can reference by USB port number so you will know what is connected on the other side of the USB to Serial port.
Note once the class is fully written you must remember to set the Activator and update the manifest with the proper dependencies. It is easy to forget these steps. This is shown if figures one and two.

Figure 1 Adding the Activator to the Manifest

Figure 2 Adding the Required Dependencies to the Manifest
This is the output after placing the exported bundle into the /etc/jvm/esf/dropins/ directory and starting ESF. Note this output will vary from system to system as it should to reflect the state of the system.
[INFO] 2010-07-26 16:45:32.491 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getCompany(): eurotech
[INFO] 2010-07-26 16:45:32.493 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getEntity(): eurotech
[INFO] 2010-07-26 16:45:32.493 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getEsfBaseBundleDirectory(): /opt/jvm/esf/bundlefiles/
[INFO] 2010-07-26 16:45:32.494 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getEsfConfigDirectory(): /opt/jvm/esf/configuration/.esf/
[INFO] 2010-07-26 16:45:32.494 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getEsfHome(): /opt/jvm/esf/
[INFO] 2010-07-26 16:45:32.495 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getFileSeparator(): /
[INFO] 2010-07-26 16:45:32.495 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getJavaHome(): /opt/jvm/
[INFO] 2010-07-26 16:45:32.496 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getJavaProfile(): harmony
[INFO] 2010-07-26 16:45:32.496 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getJavaVmName(): J9
[INFO] 2010-07-26 16:45:32.497 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getJavaVmVersion(): 2.4
[INFO] 2010-07-26 16:45:32.497 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getOsArch(): x86
[INFO] 2010-07-26 16:45:32.498 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getOsDistro(): wrl
[INFO] 2010-07-26 16:45:32.499 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getOsDistroVersion(): 3.0.2
[INFO] 2010-07-26 16:45:32.499 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getOsName(): Linux
[INFO] 2010-07-26 16:45:32.500 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getOsVersion(): 2.6.27.25-WR3.0ar_standard
[INFO] 2010-07-26 16:45:32.501 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getPlatform(): helios
[INFO] 2010-07-26 16:45:32.502 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getPrimaryMacAddress(): 00600c01a916
[INFO] 2010-07-26 16:45:32.503 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getProductVersion(): 1.0.0
[INFO] 2010-07-26 16:45:32.503 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getProject(): denali
[INFO] 2010-07-26 16:45:32.504 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getTemporaryConfigDirectory(): /tmp/.esf/
[INFO] 2010-07-26 16:45:32.505 - com.esf.example.system.manager.SystemManagerExample: systemManagerService.getEthernetInterfaces().get(0): eth0
The code for this example can be downloaded here.
Copyright © 2010 Eurotech Inc. All rights reserved.