Prefix for bundle activation function
authorMarkus Jung <markus.jung@samsung.com>
Wed, 16 Sep 2015 10:54:51 +0000 (19:54 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 18 Sep 2015 01:02:46 +0000 (01:02 +0000)
This patch introduces a prefix for the activator functions of C++ bundles.
Multiple bundles can now be linked into one application.

Change-Id: I7f345bf1a81eac9616adbf9b975a7f8565c8c172
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2581
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
12 files changed:
service/resource-encapsulation/include/RCSResourceContainer.h
service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp
service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DISensorBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp
service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml
service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerInvalidConfig.xml
service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp
service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTestConfig.xml
service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/src/TestBundleActivator.cpp

index 1cc72ed..e167e48 100644 (file)
@@ -102,11 +102,12 @@ namespace OIC
                  * @param bundleId Id of the Bundle
                  * @param bundleUri Uri of the bundle
                  * @param bundlePath Path of the bundle
+                 * @param activator Activation prefix for .so bundles, or activator class name for .jar bundles
                  * @param params  key-value pairs in string form for other Bundle parameters
                  *
                  */
                 virtual void addBundle(const std::string &bundleId, const std::string &bundleUri, const std::string &bundlePath,
-                                       std::map<std::string, std::string> params) = 0;
+                                       const std::string &activator, std::map<std::string, std::string> params) = 0;
                 /**
                  * API for removing the bundle from the container
                  *
index b266840..8142033 100644 (file)
@@ -102,25 +102,25 @@ void BMISensorBundleActivator::destroyResource(BundleResource *resource)
     }
 }
 
-extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+extern "C" void bmisensor_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
                                        std::string bundleId)
 {
     bundle = new BMISensorBundleActivator();
     bundle->activateBundle(resourceContainer, bundleId);
 }
 
-extern "C" void externalDeactivateBundle()
+extern "C" void bmisensor_externalDeactivateBundle()
 {
     bundle->deactivateBundle();
     delete bundle;
 }
 
-extern "C" void externalCreateResource(resourceInfo resourceInfo)
+extern "C" void bmisensor_externalCreateResource(resourceInfo resourceInfo)
 {
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void bmisensor_externalDestroyResource(BundleResource *pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
-}
\ No newline at end of file
+}
index 3be5edf..e7d34f9 100644 (file)
@@ -83,7 +83,7 @@ int main()
     cout << "Press enter to add SO bundle " << endl;
     getchar();
     std::map<string, string> bundleParams;
-    container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", bundleParams);
+    container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", "test", bundleParams);
 
     std::list<RCSBundleInfo *> bundles = container->listBundles();
     std::list<RCSBundleInfo *>::iterator bundleIt;
index 921d6ea..79821d5 100644 (file)
@@ -103,25 +103,25 @@ void DISensorBundleActivator::destroyResource(BundleResource *resource)
     }
 }
 
-extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+extern "C" void disensor_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
                                        std::string bundleId)
 {
     bundle = new DISensorBundleActivator();
     bundle->activateBundle(resourceContainer, bundleId);
 }
 
-extern "C" void externalDeactivateBundle()
+extern "C" void disensor_externalDeactivateBundle()
 {
     bundle->deactivateBundle();
     delete bundle;
 }
 
-extern "C" void externalCreateResource(resourceInfo resourceInfo)
+extern "C" void disensor_externalCreateResource(resourceInfo resourceInfo)
 {
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void disensor_externalDestroyResource(BundleResource *pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }
index ab7f40b..67b364f 100644 (file)
@@ -106,25 +106,25 @@ void HueSampleBundleActivator::destroyResource(BundleResource *pBundleResource)
     }
 }
 
-extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+extern "C" void huesample_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
                                        std::string bundleId)
 {
     bundle = new HueSampleBundleActivator();
     bundle->activateBundle(resourceContainer, bundleId);
 }
 
-extern "C" void externalDeactivateBundle()
+extern "C" void huesample_externalDeactivateBundle()
 {
     bundle->deactivateBundle();
     delete bundle;
 }
 
-extern "C" void externalCreateResource(resourceInfo resourceInfo)
+extern "C" void huesample_externalCreateResource(resourceInfo resourceInfo)
 {
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void huesample_externalDestroyResource(BundleResource *pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }
index 5d917b8..e9d7263 100644 (file)
@@ -41,6 +41,7 @@
     <bundle>
         <id>oic.bundle.BMISensor</id>
         <path>libBMISensorBundle.so</path>
+        <activator>bmisensor</activator>
         <version>1.0.0</version>
         <resources>
             <resourceInfo>
@@ -73,6 +74,7 @@
     <bundle>
         <id>oic.bundle.hueSample</id>
         <path>libHueBundle.so</path>
+        <activator>huesample</activator>
         <version>1.0.0</version>
         <resources>
             <resourceInfo>
index 3844d29..3c01c5a 100644 (file)
@@ -90,7 +90,7 @@ namespace OIC
             void stopBundle(const std::string &bundleId);
 
             void addBundle(const std::string &bundleId, const std::string &bundleUri,
-                    const std::string &bundlePath, std::map< string, string > params);
+                    const std::string &bundlePath, const std::string &activator, std::map< string, string > params);
             void removeBundle(const std::string &bundleId);
 
             std::list< RCSBundleInfo * > listBundles();
index 2ffccf4..de0362e 100644 (file)
@@ -474,8 +474,8 @@ namespace OIC
         }
 
         void ResourceContainerImpl::addBundle(const std::string &bundleId,
-                                              const std::string &bundleUri, const std::string &bundlePath,
-                                              std::map< string, string > params)
+                const std::string &bundleUri, const std::string &bundlePath,
+                const std::string &activator, std::map< string, string > params)
         {
             (void) bundleUri;
 
@@ -487,9 +487,10 @@ namespace OIC
                 RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
                 bundleInfo->setID(bundleId);
                 bundleInfo->setPath(bundlePath);
-                if (params.find(BUNDLE_ACTIVATOR) != params.end())
+                bundleInfo->setActivatorName(activator);
+                if (params.find("libraryPath") != params.end())
                 {
-                    string activatorName = params[BUNDLE_ACTIVATOR];
+                    string activatorName = params["activator"]; // modify activator for Java bundle
                     std::replace(activatorName.begin(), activatorName.end(), '.', '/');
                     ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
                     ((BundleInfoInternal *)bundleInfo)->setLibraryPath(params[BUNDLE_LIBRARY_PATH]);
@@ -601,19 +602,29 @@ namespace OIC
             deactivator_t *bundleDeactivator = NULL;
             resourceCreator_t *resourceCreator = NULL;
             resourceDestroyer_t *resourceDestroyer = NULL;
-
+            BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal*) bundleInfo;
             void *bundleHandle = NULL;
             bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
 
             if (bundleHandle != NULL)
             {
-                bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
-                bundleDeactivator = (deactivator_t *) dlsym(bundleHandle,
-                                    "externalDeactivateBundle");
-                resourceCreator = (resourceCreator_t *) dlsym(bundleHandle,
-                                  "externalCreateResource");
-                resourceDestroyer = (resourceDestroyer_t *) dlsym(bundleHandle,
-                                    "externalDestroyResource");
+                bundleActivator =
+                        (activator_t *) dlsym(bundleHandle,
+                                ("" + bundleInfoInternal->getActivatorName()
+                                        + "_externalActivateBundle").c_str());
+                bundleDeactivator =
+                        (deactivator_t *) dlsym(bundleHandle,
+                                ("" + bundleInfoInternal->getActivatorName()
+                                        + "_externalDeactivateBundle").c_str());
+                resourceCreator =
+                        (resourceCreator_t *) dlsym(bundleHandle,
+                                ("" + bundleInfoInternal->getActivatorName()
+                                        + "_externalCreateResource").c_str());
+                resourceDestroyer =
+                        (resourceDestroyer_t *) dlsym(bundleHandle,
+                                ("" + bundleInfoInternal->getActivatorName()
+                                        + "_externalDestroyResource").c_str());
+
 
                 if ((error = dlerror()) != NULL)
                 {
@@ -988,4 +999,4 @@ namespace OIC
         }
 #endif
     }
-}
\ No newline at end of file
+}
index 07f42b8..d3420e2 100644 (file)
@@ -3,6 +3,7 @@
     <bundle>
         <id>oic.bundle.test</id>
         <path>libTestBundle.so</path>
+        <activator>test</activator>
         <version>1.0.0</version>
     <!--</bundle>-->
 </container>
\ No newline at end of file
index e760572..ba070ff 100644 (file)
@@ -202,7 +202,7 @@ TEST_F(ResourceContainerTest, AddNewSoBundleToContainer)
     std::list<RCSBundleInfo *> bundles;
 
     bundles = m_pResourceContainer->listBundles();
-    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", bundleParams);
+    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so","test", bundleParams);
 
     EXPECT_EQ(bundles.size() + 1, m_pResourceContainer->listBundles().size());
     EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isLoaded());
@@ -224,9 +224,9 @@ TEST_F(ResourceContainerTest, AddBundleAlreadyRegistered)
     std::map<string, string> bundleParams;
     std::list<RCSBundleInfo *> bundles;
 
-    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", bundleParams);
+    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", "test", bundleParams);
     bundles = m_pResourceContainer->listBundles();
-    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", bundleParams);
+    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", "test",  bundleParams);
 
     EXPECT_EQ(bundles.size(), m_pResourceContainer->listBundles().size());
 }
@@ -403,6 +403,7 @@ class ResourceContainerImplTest: public TestWithMock
 TEST_F(ResourceContainerImplTest, SoBundleLoadedWhenRegisteredWithRegisterBundleAPI)
 {
     m_pBundleInfo->setPath("libTestBundle.so");
+    m_pBundleInfo->setActivatorName("test");
     m_pBundleInfo->setVersion("1.0");
     m_pBundleInfo->setLibraryPath(".");
     m_pBundleInfo->setID("oic.bundle.test");
@@ -461,6 +462,7 @@ TEST_F(ResourceContainerImplTest, SoBundleActivatedWithValidBundleInfo)
 {
     m_pBundleInfo->setPath("libTestBundle.so");
     m_pBundleInfo->setVersion("1.0");
+    m_pBundleInfo->setActivatorName("test");
     m_pBundleInfo->setLibraryPath("../.");
     m_pBundleInfo->setID("oic.bundle.test");
 
@@ -473,6 +475,7 @@ TEST_F(ResourceContainerImplTest, SoBundleActivatedWithValidBundleInfo)
 TEST_F(ResourceContainerImplTest, BundleNotActivatedWhenNotRegistered)
 {
     m_pBundleInfo->setPath("libTestBundle.so");
+    m_pBundleInfo->setActivatorName("test");
     m_pBundleInfo->setVersion("1.0");
     m_pBundleInfo->setLibraryPath("../.");
     m_pBundleInfo->setID("oic.bundle.test");
@@ -487,6 +490,7 @@ TEST_F(ResourceContainerImplTest, SoBundleActivatedWithBundleID)
     m_pBundleInfo->setPath("libTestBundle.so");
     m_pBundleInfo->setVersion("1.0");
     m_pBundleInfo->setLibraryPath("../.");
+    m_pBundleInfo->setActivatorName("test");
     m_pBundleInfo->setID("oic.bundle.test");
 
     m_pResourceContainer->registerBundle(m_pBundleInfo);
@@ -501,6 +505,7 @@ TEST_F(ResourceContainerImplTest, BundleDeactivatedWithBundleInfo)
     m_pBundleInfo->setPath("libTestBundle.so");
     m_pBundleInfo->setVersion("1.0");
     m_pBundleInfo->setLibraryPath("../.");
+    m_pBundleInfo->setActivatorName("test");
     m_pBundleInfo->setID("oic.bundle.test");
 
     m_pResourceContainer->registerBundle(m_pBundleInfo);
@@ -530,6 +535,7 @@ TEST_F(ResourceContainerImplTest, SoBundleDeactivatedWithBundleID)
     m_pBundleInfo->setPath("libTestBundle.so");
     m_pBundleInfo->setVersion("1.0");
     m_pBundleInfo->setLibraryPath("../.");
+    m_pBundleInfo->setActivatorName("test");
     m_pBundleInfo->setID("oic.bundle.test");
 
     m_pResourceContainer->registerBundle(m_pBundleInfo);
@@ -817,4 +823,4 @@ TEST_F(RemoteResourceUnitTest, onStateCBCalled)
     ptr->startMonitoring();
     testObject->ChangeResourceState();
     EXPECT_TRUE(isCalled);
-}
\ No newline at end of file
+}
index d7e4671..f262d8d 100644 (file)
@@ -4,6 +4,7 @@
         <id>oic.bundle.test</id>
         <path>libTestBundle.so</path>
         <libraryPath>.</libraryPath>
+        <activator>test</activator>
         <version>1.0.0</version>
                <resources>
                        <resourceInfo>
index 47b1afa..8d5c965 100644 (file)
@@ -68,25 +68,25 @@ void TestBundleActivator::destroyResource(BundleResource *pBundleResource)
     m_pResourceContainer->unregisterResource(pBundleResource);
 }
 
-extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+extern "C" void test_externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
                                        std::string bundleId)
 {
     bundle = new TestBundleActivator();
     bundle->activateBundle(resourceContainer, bundleId);
 }
 
-extern "C" void externalDeactivateBundle()
+extern "C" void test_externalDeactivateBundle()
 {
     bundle->deactivateBundle();
     delete bundle;
 }
 
-extern "C" void externalCreateResource(resourceInfo resourceInfo)
+extern "C" void test_externalCreateResource(resourceInfo resourceInfo)
 {
     bundle->createResource(resourceInfo);
 }
 
-extern "C" void externalDestroyResource(BundleResource *pBundleResource)
+extern "C" void test_externalDestroyResource(BundleResource *pBundleResource)
 {
     bundle->destroyResource(pBundleResource);
 }