private static Message msg;
public static boolean startBundleFlag;
private static boolean isStarted = false;
- public static boolean isInitialized = false;
PowerManager pm = null;
PowerManager.WakeLock wl = null;
msg = Message.obtain();
msg.what = 0;
resourceContainerActivityInstance.getHandler().sendMessage(msg);
+
+ // initialize the information of the bundles
+ // which registered at the starting time of the container
+ List<RcsBundleInfo> bundleList = containerInstance.listBundles();
+ Iterator<RcsBundleInfo> it = bundleList.iterator();
+
+ while (it.hasNext())
+ {
+ String id = ((RcsBundleInfo) it.next()).getID();
+ if (id.equals(ExampleBundleDescription.DIBundle.mBundleId)) {
+ ExampleBundleDescription.DIBundle.isStarted = true;
+ }
+ else if (id.equals(ExampleBundleDescription.DIAndroidBundle.mBundleId)) {
+ ExampleBundleDescription.DIAndroidBundle.isStarted = true;
+ }
+ }
}
}
return false;
}
- // Add BMI Bundles
- public void addBMIBundle() {
- Map<String, String> bundleParams = new HashMap<String, String>();
-
- if (bundleExists("oic.bundle.BMISensor"))
- logMessage = "Bundle already added" + "\n";
+ // add Bundles
+ public void addBundle(BundleInformation bundle) {
+ if (bundleExists(bundle.mBundleId))
+ logMessage = "Bundle \'" + bundle.mBundleId + "\' already added" + "\n";
else {
containerInstance
- .addBundle(
- "oic.bundle.BMISensor",
- "",
- "/data/data/org.iotivity.service.sample.resourcecontainer/files/libBMISensorBundle.so",
- "bmisensor", bundleParams);
+ .addBundle(bundle.mBundleId, bundle.mBundleUri,
+ bundle.mBundlePath, bundle.mActivator, bundle.mBundleParams);
logMessage = "bundle to add : " + "\n";
- logMessage = logMessage + "ID :" + "oic.bundle.BMISensor" + "\n";
- logMessage = logMessage + "Uri: " + "xyz" + "\n";
+ logMessage = logMessage + "ID : " + bundle.mBundleId + "\n";
+ logMessage = logMessage + "Uri: " + bundle.mBundleUri + "\n";
logMessage = logMessage
+ "Path : "
- + "/data/data/org.iotivity.service.sample.server/files/libBMISensorBundle.so"
+ + bundle.mBundlePath
+ "\n\n";
logMessage = logMessage + "bundle added successfully" + "\n";
- }
+ }
ResourceContainerActivity.setMessageLog(logMessage);
msg = Message.obtain();
resourceContainerActivityInstance.getHandler().sendMessage(msg);
}
- // Remove Bundle BMI
- public void removeBMIBundle() {
+ // remove Bundles
+ public void removeBundle(BundleInformation bundle) {
- if (!bundleExists("oic.bundle.BMISensor"))
- logMessage = "BMI Bundle not added" + "\n";
+ if (!bundleExists(bundle.mBundleId))
+ logMessage = "Bundle \'" + bundle.mBundleId + "\' not added" + "\n";
else {
- containerInstance.removeBundle("oic.bundle.BMISensor");
+ containerInstance.removeBundle(bundle.mBundleId);
- startBundleFlag = false;
+ bundle.isStarted = false;
logMessage = "bundle to remove : " + "\n";
- logMessage = logMessage + "ID :" + "oic.bundle.BMISensor" + "\n\n";
+ logMessage = logMessage + "ID : " + bundle.mBundleId + "\n\n";
logMessage = logMessage + " bundle removed successfully" + "\n";
}
resourceContainerActivityInstance.getHandler().sendMessage(msg);
}
- // Start Bundle BMI
- public void startBMIBundle() {
+ // start Bundles
+ public void startBundle(BundleInformation bundle) {
- if (!bundleExists("oic.bundle.BMISensor")) {
- logMessage = "BMI bundle not added" + "\n";
- } else if (true == startBundleFlag) {
- logMessage = "Bundle already started" + "\n";
+ if (!bundleExists(bundle.mBundleId)) {
+ logMessage = "Bundle \'" + bundle.mBundleId + "\' not added" + "\n";
+ } else if (bundle.isStarted) {
+ logMessage = "Bundle \'" + bundle.mBundleId + "\' already started" + "\n";
} else {
- startBundleFlag = true;
- containerInstance.startBundle("oic.bundle.BMISensor");
+ bundle.isStarted = true;
+ containerInstance.startBundle(bundle.mBundleId);
logMessage = " bundle to start" + "\n";
- logMessage += " ID : oic.bundle.BMISensor" + "\n\n";
+ logMessage += " ID : " + bundle.mBundleId + "\n\n";
logMessage += " bundle started successfully" + "\n";
}
resourceContainerActivityInstance.getHandler().sendMessage(msg);
}
- // Stop Bundle BMI
- public void stopBMIBundle() {
+ // Stop Bundles
+ public void stopBundle(BundleInformation bundle) {
- if (!bundleExists("oic.bundle.BMISensor")) {
- logMessage = "BMI Bundle not added" + "\n";
+ if (!bundleExists(bundle.mBundleId)) {
+ logMessage = "Bundle \'" + bundle.mBundleId + "\' not added" + "\n";
}
- else if (false == startBundleFlag) {
- logMessage = "Bundle is not Started" + "\n";
+ else if (!bundle.isStarted) {
+ logMessage = "Bundle \'" + bundle.mBundleId + "\' is not Started" + "\n";
} else {
- containerInstance.stopBundle("oic.bundle.BMISensor");
- startBundleFlag = false;
- logMessage = " bundle to stop" + "\n";
- logMessage = logMessage + " ID : oic.bundle.BMISensor" + "\n\n";
- logMessage = logMessage + " bundle stopped successfully" + "\n";
+ containerInstance.stopBundle(bundle.mBundleId);
+ bundle.isStarted = false;
+ logMessage = " bundle to stop" + "\n";
+ logMessage = logMessage + " ID : " + bundle.mBundleId + "\n\n";
+ logMessage = logMessage + " bundle stopped successfully" + "\n";
}
ResourceContainerActivity.setMessageLog(logMessage);
msg.what = 1;
resourceContainerActivityInstance.getHandler().sendMessage(msg);
}
+}
- public void addAndroidResource(){
- logMessage = "Add android resource " + "\n";
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
+class ExampleBundleDescription
+{
+ static final BundleInformation BMIBundle =
+ new BundleInformation ("oic.bundle.BMISensor", "",
+ "/data/data/org.iotivity.service.sample.resourcecontainer/files/" +
+ "libBMISensorBundle.so",
+ "bmisensor", new HashMap<String, String>());
+
+ static final BundleInformation DIBundle =
+ new BundleInformation ("oic.bundle.discomfortIndexSensor", "",
+ "/data/data/org.iotivity.service.sample.resourcecontainer/files/" +
+ "libDISensorBundle.so",
+ "disensor", new HashMap<String, String>());
+
+ static final BundleInformation DIAndroidBundle =
+ new BundleInformation ("oic.android.sample", "",
+ "org.iotivity.service.sample.androidbundle.apk",
+ "org.iotivity.service.sample.androidbundle.SampleActivator",
+ new HashMap<String, String>());
}
+
+class BundleInformation
+{
+ String mBundleId;
+ String mBundleUri;
+ String mBundlePath;
+ String mActivator;
+ Map<String, String> mBundleParams;
+
+ Boolean isStarted;
+
+ public BundleInformation(String id, String uri, String path, String activator, Map<String, String> params)
+ {
+ mBundleId = id;
+ mBundleUri = uri;
+ mBundlePath = path;
+ mActivator = activator;
+ mBundleParams = params;
+ isStarted = false;
+ }
+}
\ No newline at end of file
* for updating UI.
*/
public class ResourceContainerActivity extends Activity {
- // private static final String LOG_TAG =
- // ResourceContainerActivity.class.getSimpleName();
private final String LOG_TAG = "[RCSampleServerApp] "
+ this.getClass()
private Context context;
public ExpandableListAdapter listAdapter;
public ExpandableListView expListView;
+ private int lastExpandedPosition = -1;
+
public List<String> sensors;
public List<String> diApiList;
public List<String> bmiApiList;
bmiApiList.add("5. Remove BMI sensor bundle");
// Adding child data [discomfort Index sensor]
- diApiList.add("1. List bundle resources");
+ diApiList.add("1. Add DI sensor bundle");
+ diApiList.add("2. Start DI sensor bundle");
+ diApiList.add("3. List bundle resources");
+ diApiList.add("4. Stop DI sensor bundle");
+ diApiList.add("5. Remove DI sensor bundle");
// Adding child data [discomfort Index sensor - android]
- diAndroidApiList.add("1. List bundle resources");
+ diAndroidApiList.add("1. Add Android DI sensor bundle");
+ diAndroidApiList.add("2. Start Android DI sensor bundle");
+ diAndroidApiList.add("3. List bundle resources");
+ diAndroidApiList.add("4. Stop Android DI sensor bundle");
+ diAndroidApiList.add("5. Remove Android DI sensor bundle");
listChild.put(sensors.get(0), bmiApiList);
listChild.put(sensors.get(1), diApiList);
}
});
- // Listener for the expandable list
+
+ expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
+ @Override
+ public void onGroupExpand(int groupPosition) {
+ if (lastExpandedPosition != -1
+ && groupPosition != lastExpandedPosition) {
+ expListView.collapseGroup(lastExpandedPosition);
+ }
+ lastExpandedPosition = groupPosition;
+ }
+ });
+
expListView
.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent,
View v, int groupPosition, int childPosition,
long id) {
- if (0 == groupPosition) {
- if (childPosition == 0) {
- resourceContainerInstance.addBMIBundle();
- } else if (childPosition == 1) {
- resourceContainerInstance.startBMIBundle();
- } else if (childPosition == 2) {
- resourceContainerInstance
- .listBundleResources("oic.bundle.BMISensor");
- } else if (childPosition == 3) {
- resourceContainerInstance.stopBMIBundle();
- } else if (childPosition == 4) {
- resourceContainerInstance.removeBMIBundle();
- }
+ BundleInformation bundleToTest;
+
+ switch (groupPosition) {
+ case 0:
+ bundleToTest = ExampleBundleDescription.BMIBundle;
+ break;
+
+ case 1:
+ bundleToTest = ExampleBundleDescription.DIBundle;
+ break;
+
+ case 2:
+ bundleToTest = ExampleBundleDescription.DIAndroidBundle;
+ break;
+
+ default:
+ return false;
}
- else if (1 == groupPosition) {
- if (childPosition == 0) {
- resourceContainerInstance
- .listBundleResources("oic.bundle.discomfortIndexSensor");
- }
- } else if (2 == groupPosition) {
- if (childPosition == 0) {
+ switch (childPosition) {
+ case 0:
+ resourceContainerInstance.addBundle(bundleToTest);
+ break;
+
+ case 1:
+ resourceContainerInstance.startBundle(bundleToTest);
+ break;
+
+ case 2:
resourceContainerInstance
- .listBundleResources("oic.android.sample");
- }
+ .listBundleResources(bundleToTest.mBundleId);
+ break;
+
+ case 3:
+ resourceContainerInstance.stopBundle(bundleToTest);
+ break;
+
+ case 4:
+ resourceContainerInstance.removeBundle(bundleToTest);
+ break;
+
+ default:
+ return false;
}
- return false;
+ return true;
}
});
}