From 0f1f93d81eb24b9d09df8eb878ad1d35f6665f70 Mon Sep 17 00:00:00 2001 From: Markus Jung Date: Wed, 16 Sep 2015 19:54:51 +0900 Subject: [PATCH] Prefix for bundle activation function 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/2581 Tested-by: jenkins-iotivity Reviewed-by: Hun-je Yeon Reviewed-by: Madan Lanka --- .../include/RCSResourceContainer.h | 3 +- .../src/BMISensorBundleActivator.cpp | 10 +++--- .../resourceContainer/examples/ContainerSample.cpp | 2 +- .../src/DISensorBundleActivator.cpp | 8 ++--- .../src/HueSampleBundleActivator.cpp | 8 ++--- .../examples/ResourceContainerConfig.xml | 2 ++ .../include/ResourceContainerImpl.h | 2 +- .../src/ResourceContainerImpl.cpp | 37 ++++++++++++++-------- .../unittests/ResourceContainerInvalidConfig.xml | 1 + .../unittests/ResourceContainerTest.cpp | 14 +++++--- .../unittests/ResourceContainerTestConfig.xml | 1 + .../TestBundle/src/TestBundleActivator.cpp | 8 ++--- 12 files changed, 59 insertions(+), 37 deletions(-) diff --git a/service/resource-encapsulation/include/RCSResourceContainer.h b/service/resource-encapsulation/include/RCSResourceContainer.h index 1cc72ed..e167e48 100644 --- a/service/resource-encapsulation/include/RCSResourceContainer.h +++ b/service/resource-encapsulation/include/RCSResourceContainer.h @@ -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 params) = 0; + const std::string &activator, std::map params) = 0; /** * API for removing the bundle from the container * diff --git a/service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorBundleActivator.cpp b/service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorBundleActivator.cpp index b266840..8142033 100644 --- a/service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorBundleActivator.cpp +++ b/service/resource-encapsulation/src/resourceContainer/examples/BMISensorBundle/src/BMISensorBundleActivator.cpp @@ -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 +} diff --git a/service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp b/service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp index 3be5edf..e7d34f9 100644 --- a/service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp +++ b/service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp @@ -83,7 +83,7 @@ int main() cout << "Press enter to add SO bundle " << endl; getchar(); std::map bundleParams; - container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", bundleParams); + container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", "test", bundleParams); std::list bundles = container->listBundles(); std::list::iterator bundleIt; diff --git a/service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DISensorBundleActivator.cpp b/service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DISensorBundleActivator.cpp index 921d6ea..79821d5 100644 --- a/service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DISensorBundleActivator.cpp +++ b/service/resource-encapsulation/src/resourceContainer/examples/DiscomfortIndexSensorBundle/src/DISensorBundleActivator.cpp @@ -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); } diff --git a/service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp b/service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp index ab7f40b..67b364f 100644 --- a/service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp +++ b/service/resource-encapsulation/src/resourceContainer/examples/HueSampleBundle/src/HueSampleBundleActivator.cpp @@ -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); } diff --git a/service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml b/service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml index 5d917b8..e9d7263 100644 --- a/service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml +++ b/service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml @@ -41,6 +41,7 @@ oic.bundle.BMISensor libBMISensorBundle.so + bmisensor 1.0.0 @@ -73,6 +74,7 @@ oic.bundle.hueSample libHueBundle.so + huesample 1.0.0 diff --git a/service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h b/service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h index 3844d29..3c01c5a 100644 --- a/service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h +++ b/service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h @@ -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(); diff --git a/service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp b/service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp index 2ffccf4..de0362e 100644 --- a/service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp +++ b/service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp @@ -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 +} diff --git a/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerInvalidConfig.xml b/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerInvalidConfig.xml index 07f42b8..d3420e2 100644 --- a/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerInvalidConfig.xml +++ b/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerInvalidConfig.xml @@ -3,6 +3,7 @@ oic.bundle.test libTestBundle.so + test 1.0.0 \ No newline at end of file diff --git a/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp b/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp index e760572..ba070ff 100644 --- a/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp +++ b/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp @@ -202,7 +202,7 @@ TEST_F(ResourceContainerTest, AddNewSoBundleToContainer) std::list 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 bundleParams; std::list 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 +} diff --git a/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTestConfig.xml b/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTestConfig.xml index d7e4671..f262d8d 100644 --- a/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTestConfig.xml +++ b/service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTestConfig.xml @@ -4,6 +4,7 @@ oic.bundle.test libTestBundle.so . + test 1.0.0 diff --git a/service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/src/TestBundleActivator.cpp b/service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/src/TestBundleActivator.cpp index 47b1afa..8d5c965 100644 --- a/service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/src/TestBundleActivator.cpp +++ b/service/resource-encapsulation/src/resourceContainer/unittests/TestBundle/src/TestBundleActivator.cpp @@ -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); } -- 2.7.4