Modify RCSBundleInfo API, make constructor and destructor of the container protected.
authorMinji Park <minjii.park@samsung.com>
Fri, 18 Sep 2015 05:44:50 +0000 (14:44 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 18 Sep 2015 12:22:26 +0000 (12:22 +0000)
- remove RCSBundleInfo APIs to build bundleinfo and set bundle information, since bundleinfo only can be created and set only by the container internally
- make constructor and destructor of the container protected to make container exists as singleton

Change-Id: I677ec510f046a3f5b7d2be584c0d42a915d17082
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2671
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/include/RCSBundleInfo.h
service/resource-encapsulation/include/RCSResourceContainer.h
service/resource-encapsulation/src/resourceContainer/bundle-api/include/ResourceContainerBundleAPI.h
service/resource-encapsulation/src/resourceContainer/examples/ContainerSample.cpp
service/resource-encapsulation/src/resourceContainer/examples/ResourceContainerConfig.xml
service/resource-encapsulation/src/resourceContainer/include/ResourceContainerImpl.h
service/resource-encapsulation/src/resourceContainer/src/RCSBundleInfo.cpp
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp

index b18d0d9..5238df2 100644 (file)
@@ -24,8 +24,8 @@
  * This file contains RCSBundleInfo class, which provides APIs related to Bundle information.
  */
 
-#ifndef BUNDLEINFO_H_
-#define BUNDLEINFO_H_
+#ifndef RCSBUNDLEINFO_H_
+#define RCSBUNDLEINFO_H_
 
 #include <string>
 
@@ -42,17 +42,6 @@ namespace OIC
         class RCSBundleInfo
         {
             public:
-                RCSBundleInfo();
-                virtual ~RCSBundleInfo();
-
-                /**
-                * API for setting the Id of the bundle
-                *
-                * @param name Id of the bundle in string form
-                *
-                */
-                virtual void setID(const std::string &name) = 0;
-
                 /**
                 * API for getting the Id of the bundle
                 *
@@ -62,14 +51,6 @@ namespace OIC
                 virtual const std::string &getID() = 0;
 
                 /**
-                * API for setting the path of the bundle
-                *
-                * @param path path of the bundle in string form
-                *
-                */
-                virtual void setPath(const std::string &path) = 0;
-
-                /**
                 * API for getting the path of the bundle
                 *
                 * @return path of the bundle
@@ -80,42 +61,18 @@ namespace OIC
                 /**
                 * API for setting the Activator name for the bundle
                 *
-                * @param activator Activator name in string form
-                *
-                */
-                virtual void setActivatorName(const std::string &activator) = 0;
-
-                /**
-                * API for setting the Activator name for the bundle
-                *
                 * @return Name of the activator
                 *
                 */
                 virtual const std::string &getActivatorName() = 0;
 
                 /**
-                * API for setting the library path for the bundle
-                *
-                * @param libpath Library path in string form
-                *
-                */
-                virtual void setLibraryPath(const std::string &libpath) = 0;
-
-                /**
                 * API for getting the library path for the bundle
                 *
                 * @return Library path  in string form
                 *
                 */
-                virtual const std::string& getLibraryPath() = 0;
-
-                /**
-                * API for setting the version of the bundle
-                *
-                * @param version version of the bundle in string form
-                *
-                */
-                virtual void setVersion(const std::string &version) = 0;
+                virtual const std::string &getLibraryPath() = 0;
 
                 /**
                 * API for getting the version of the bundle
@@ -125,17 +82,14 @@ namespace OIC
                 */
                 virtual const std::string &getVersion() = 0;
 
-                /**
-                 * API for creating new bundle information
-                 *
-                 * @return RCSBundleInfo pointer.
-                 *
-                 */
-                static RCSBundleInfo *build();
+
             protected:
                 std::string m_ID, m_path, m_version;
+
+                RCSBundleInfo();
+                virtual ~RCSBundleInfo();
         };
     }
 }
 
-#endif /* BUNDLEINFO_H_ */
+#endif /* RCSBUNDLEINFO_H_ */
index e167e48..0afcd16 100644 (file)
@@ -27,7 +27,6 @@
 #ifndef RCSRESOURCECONTAINER_H_
 #define RCSRESOURCECONTAINER_H_
 
-#include <iostream>
 #include <string>
 #include <vector>
 #include <map>
@@ -49,16 +48,6 @@ namespace OIC
         {
             public:
                 /**
-                * Constructor
-                */
-                RCSResourceContainer();
-
-                /**
-                *virtual Destructor
-                */
-                virtual ~RCSResourceContainer();
-
-                /**
                  * API for starting the Container
                  *
                  * @details This API start the container with the provided Configuration file.
@@ -106,8 +95,9 @@ namespace OIC
                  * @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,
-                                       const std::string &activator, std::map<std::string, std::string> params) = 0;
+                virtual void addBundle(const std::string &bundleId, const std::string &bundleUri,
+                                       const std::string &bundlePath, const std::string &activator,
+                                       std::map<std::string, std::string> params) = 0;
                 /**
                  * API for removing the bundle from the container
                  *
@@ -150,6 +140,15 @@ namespace OIC
                  *
                  */
                 static RCSResourceContainer *getInstance();
+
+            protected:
+                RCSResourceContainer();
+                virtual ~RCSResourceContainer();
+
+                RCSResourceContainer(const RCSResourceContainer &) = delete;
+                RCSResourceContainer(RCSResourceContainer &&) = delete;
+                RCSResourceContainer &operator=(const RCSResourceContainer &) const = delete;
+                RCSResourceContainer &operator=(RCSResourceContainer &&) const = delete;
         };
     }
 }
index 7712429..373a8e0 100644 (file)
 #ifndef RESOURCECONTAINERBUNDLEAPI_H_
 #define RESOURCECONTAINERBUNDLEAPI_H_
 
-#include <unistd.h>
-#include <string.h>
-#include <fstream>
-
-#include "RCSBundleInfo.h"
 #include "Configuration.h"
 #include "NotificationReceiver.h"
 #include "BundleResource.h"
@@ -39,17 +34,6 @@ namespace OIC
         class ResourceContainerBundleAPI: public NotificationReceiver
         {
             public:
-
-                /**
-                * Constructor for ResourceContainerBundleAPI
-                */
-                ResourceContainerBundleAPI();
-
-                /**
-                * Virtual destructor for ResourceContainerBundleAPI
-                */
-                virtual ~ResourceContainerBundleAPI();
-
                 /**
                 * Register bundle resource in the container
                 *   and register resource server for bundle resource
@@ -99,6 +83,15 @@ namespace OIC
                 * @return ResourceContainerBundleAPI * - return the object pointer of ResourceContainerBundleAPI
                 */
                 static ResourceContainerBundleAPI *getInstance();
+
+            protected:
+                ResourceContainerBundleAPI();
+                virtual ~ResourceContainerBundleAPI();
+
+                ResourceContainerBundleAPI(const ResourceContainerBundleAPI &) = delete;
+                ResourceContainerBundleAPI(ResourceContainerBundleAPI &&) = delete;
+                ResourceContainerBundleAPI &operator=(const ResourceContainerBundleAPI &) const = delete;
+                ResourceContainerBundleAPI &operator=(ResourceContainerBundleAPI &&) const = delete;
         };
     }
 }
index e7d34f9..b60d5a6 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", "test", bundleParams);
+    container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", "huesample", bundleParams);
 
     std::list<RCSBundleInfo *> bundles = container->listBundles();
     std::list<RCSBundleInfo *>::iterator bundleIt;
@@ -148,9 +148,11 @@ int main()
     cout << "Press enter to add java bundle " << endl;
     getchar();
     bundleParams["libraryPath"] = ".";
-    bundleParams["activator"] = "org.iotivity.bundle.hue.HueBundleActivator";
+    std::string activator = "org.iotivity.bundle.hue.HueBundleActivator";
     container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
-                         "../../../../../../../../service/resource-encapsulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
+                         "../../../../../../../../service/resource-encapsulation/src/resourceContainer/" \
+                         "examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
+                         activator,
                          bundleParams);
 
     bundles = container->listBundles();
index e9d7263..96d9044 100644 (file)
@@ -3,6 +3,7 @@
     <bundle>
         <id>oic.bundle.discomfortIndexSensor</id>
         <path>libDISensorBundle.so</path>
+        <activator>disensor</activator>
         <version>1.0.0</version>
         <resources>
             <resourceInfo>
index 4061d20..93cdf4d 100644 (file)
@@ -52,94 +52,99 @@ namespace OIC
 
         class ResourceContainerImpl: public RCSResourceContainer, public ResourceContainerBundleAPI
         {
-        public:
-            ResourceContainerImpl();
-            virtual ~ResourceContainerImpl();
+            public:
+                // methods from ResourceContainer
+                void startContainer(const std::string &configFile);
+                void stopContainer();
+                void activateBundle(RCSBundleInfo *bundleInfo);
+                void deactivateBundle(RCSBundleInfo *bundleInfo);
+                void activateBundle(const std::string &bundleId);
+                void deactivateBundle(const std::string &bundleId);
+                void registerBundle(RCSBundleInfo *bundleinfo);
+                void unregisterBundle(RCSBundleInfo *bundleinfo);
+                void unregisterBundleSo(const std::string &id);
 
-            // methods from ResourceContainer
-            void startContainer(const std::string &configFile);
-            void stopContainer();
-            void activateBundle(RCSBundleInfo *bundleInfo);
-            void deactivateBundle(RCSBundleInfo *bundleInfo);
-            void activateBundle(const std::string &bundleId);
-            void deactivateBundle(const std::string &bundleId);
-            void registerBundle(RCSBundleInfo *bundleinfo);
-            void unregisterBundle(RCSBundleInfo *bundleinfo);
-            void unregisterBundleSo(const std::string &id);
+                // methods from ResourceContainerBundleAPI
+                void registerResource(BundleResource *resource);
+                void unregisterResource(BundleResource *resource);
 
-            // methods from ResourceContainerBundleAPI
-            void registerResource(BundleResource *resource);
-            void unregisterResource(BundleResource *resource);
+                void getBundleConfiguration(const std::string &bundleId, configInfo *configOutput);
+                void getResourceConfiguration(const std::string &bundleId,
+                                              std::vector< resourceInfo > *configOutput);
 
-            void getBundleConfiguration(const std::string &bundleId, configInfo *configOutput);
-            void getResourceConfiguration(const std::string &bundleId,
-                    std::vector< resourceInfo > *configOutput);
+                RCSGetResponse getRequestHandler(const RCSRequest &request,
+                                                 const RCSResourceAttributes &attributes);
+                RCSSetResponse setRequestHandler(const RCSRequest &request,
+                                                 const RCSResourceAttributes &attributes);
 
-            RCSGetResponse getRequestHandler(const RCSRequest &request,
-                    const RCSResourceAttributes &attributes);
-            RCSSetResponse setRequestHandler(const RCSRequest &request,
-                    const RCSResourceAttributes &attributes);
+                void onNotificationReceived(const std::string &strResourceUri);
 
-            void onNotificationReceived(const std::string &strResourceUri);
+                static ResourceContainerImpl *getImplInstance();
+                static RCSResourceObject::Ptr buildResourceObject(const std::string &strUri,
+                        const std::string &strResourceType);
 
-            static ResourceContainerImpl *getImplInstance();
-            static RCSResourceObject::Ptr buildResourceObject(const std::string &strUri,
-                    const std::string &strResourceType);
+                void startBundle(const std::string &bundleId);
+                void stopBundle(const std::string &bundleId);
 
-            void startBundle(const std::string &bundleId);
-            void stopBundle(const std::string &bundleId);
+                void addBundle(const std::string &bundleId, const std::string &bundleUri,
+                               const std::string &bundlePath, const std::string &activator,
+                               std::map< string, string > params);
+                void removeBundle(const std::string &bundleId);
 
-            void addBundle(const std::string &bundleId, const std::string &bundleUri,
-                    const std::string &bundlePath, const std::string &activator,
-                    std::map< string, string > params);
-            void removeBundle(const std::string &bundleId);
+                std::list< RCSBundleInfo * > listBundles();
 
-            std::list< RCSBundleInfo * > listBundles();
+                void addResourceConfig(const std::string &bundleId, const std::string &resourceUri,
+                                       std::map< string, string > params);
+                void removeResourceConfig(const std::string &bundleId, const std::string &resourceUri);
 
-            void addResourceConfig(const std::string &bundleId, const std::string &resourceUri,
-                    std::map< string, string > params);
-            void removeResourceConfig(const std::string &bundleId, const std::string &resourceUri);
-
-            std::list< string > listBundleResources(const std::string &bundleId);
+                std::list< string > listBundleResources(const std::string &bundleId);
 
 #if(JAVA_SUPPORT)
-            JavaVM *getJavaVM(string bundleId);
-            void unregisterBundleJava(string id);
+                JavaVM *getJavaVM(string bundleId);
+                void unregisterBundleJava(string id);
 #endif
 
-        private:
-            map< std::string, BundleInfoInternal * > m_bundles; // <bundleID, bundleInfo>
-            map< std::string, RCSResourceObject::Ptr > m_mapServers; //<uri, serverPtr>
-            map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
-            map< std::string, list< string > > m_mapBundleResources; //<bundleID, vector<uri>>
-            map< std::string, list< DiscoverResourceUnit::Ptr > > m_mapDiscoverResourceUnits;
-            //<uri, DiscoverUnit>
-            string m_configFile;
-            Configuration *m_config;
-            // holds for a bundle the threads for bundle activation
-            map< std::string, boost::thread > m_activators;
-            // used for synchronize the resource registration of multiple bundles
-            std::mutex registrationLock;
-            // used to synchronize the startup of the container with other operation
-            // such as individual bundle activation
-            std::recursive_mutex activationLock;
-
-            void activateSoBundle(const std::string &bundleId);
-            void deactivateSoBundle(const std::string &bundleId);
-            void addSoBundleResource(const std::string &bundleId, resourceInfo newResourceInfo);
-            void removeSoBundleResource(const std::string &bundleId,
-                    const std::string &resourceUri);
-            void registerSoBundle(RCSBundleInfo *bundleInfo);
-            void discoverInputResource(const std::string & outputResourceUri);
-            void undiscoverInputResource(const std::string & outputResourceUri);
-            void activateBundleThread(const std::string &bundleId);
+            private:
+                map< std::string, BundleInfoInternal * > m_bundles; // <bundleID, bundleInfo>
+                map< std::string, RCSResourceObject::Ptr > m_mapServers; //<uri, serverPtr>
+                map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
+                map< std::string, list< string > > m_mapBundleResources; //<bundleID, vector<uri>>
+                map< std::string, list< DiscoverResourceUnit::Ptr > > m_mapDiscoverResourceUnits;
+                //<uri, DiscoverUnit>
+                string m_configFile;
+                Configuration *m_config;
+                // holds for a bundle the threads for bundle activation
+                map< std::string, boost::thread > m_activators;
+                // used for synchronize the resource registration of multiple bundles
+                std::mutex registrationLock;
+                // used to synchronize the startup of the container with other operation
+                // such as individual bundle activation
+                std::recursive_mutex activationLock;
+
+                ResourceContainerImpl();
+                virtual ~ResourceContainerImpl();
+
+                ResourceContainerImpl(const ResourceContainerImpl &) = delete;
+                ResourceContainerImpl(ResourceContainerImpl &&) = delete;
+                ResourceContainerImpl &operator=(const ResourceContainerImpl &) const = delete;
+                ResourceContainerImpl &operator=(ResourceContainerImpl &&) const = delete;
+
+                void activateSoBundle(const std::string &bundleId);
+                void deactivateSoBundle(const std::string &bundleId);
+                void addSoBundleResource(const std::string &bundleId, resourceInfo newResourceInfo);
+                void removeSoBundleResource(const std::string &bundleId,
+                                            const std::string &resourceUri);
+                void registerSoBundle(RCSBundleInfo *bundleInfo);
+                void discoverInputResource(const std::string &outputResourceUri);
+                void undiscoverInputResource(const std::string &outputResourceUri);
+                void activateBundleThread(const std::string &bundleId);
 
 #if(JAVA_SUPPORT)
-            map<string, JavaVM *> m_bundleVM;
+                map<string, JavaVM *> m_bundleVM;
 
-            void registerJavaBundle(RCSBundleInfo *bundleInfo);
-            void activateJavaBundle(string bundleId);
-            void deactivateJavaBundle(string bundleId);
+                void registerJavaBundle(RCSBundleInfo *bundleInfo);
+                void activateJavaBundle(string bundleId);
+                void deactivateJavaBundle(string bundleId);
 
 #endif
 
index fdcd111..d89ab7c 100644 (file)
@@ -34,11 +34,5 @@ namespace OIC
         {
 
         }
-
-        RCSBundleInfo *RCSBundleInfo::build()
-        {
-            BundleInfoInternal *newBundleInfo = new BundleInfoInternal();
-            return newBundleInfo;
-        }
     }
 }
index 99e8f4d..042db57 100644 (file)
@@ -79,7 +79,7 @@ namespace OIC
 
                     for (unsigned int i = 0; i < bundles.size(); i++)
                     {
-                        RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
+                        BundleInfoInternal *bundleInfo = new BundleInfoInternal();
                         bundleInfo->setPath(bundles[i][BUNDLE_PATH]);
                         bundleInfo->setVersion(bundles[i][BUNDLE_VERSION]);
                         bundleInfo->setID(bundles[i][BUNDLE_ID]);
@@ -480,8 +480,8 @@ namespace OIC
         }
 
         void ResourceContainerImpl::addBundle(const std::string &bundleId,
-                const std::string &bundleUri, const std::string &bundlePath,
-                const std::string &activator, std::map< string, string > params)
+                                              const std::string &bundleUri, const std::string &bundlePath,
+                                              const std::string &activator, std::map< string, string > params)
         {
             (void) bundleUri;
 
@@ -490,7 +490,7 @@ namespace OIC
 
             else
             {
-                RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
+                BundleInfoInternal *bundleInfo = new BundleInfoInternal();
                 bundleInfo->setID(bundleId);
                 bundleInfo->setPath(bundlePath);
                 bundleInfo->setActivatorName(activator);
@@ -536,10 +536,9 @@ namespace OIC
                  it != m_bundles.end(); ++it)
             {
                 {
-                    RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
-                    ((BundleInfoInternal *) bundleInfo)->setBundleInfo(
-                        (RCSBundleInfo *) it->second);
-                    ret.push_back(bundleInfo);
+                    BundleInfoInternal *bundleInfo = new BundleInfoInternal();
+                    (bundleInfo)->setBundleInfo(it->second);
+                    ret.push_back((RCSBundleInfo *) bundleInfo);
                 }
             }
             return ret;
@@ -612,28 +611,28 @@ namespace OIC
             deactivator_t *bundleDeactivator = NULL;
             resourceCreator_t *resourceCreator = NULL;
             resourceDestroyer_t *resourceDestroyer = NULL;
-            BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal*) bundleInfo;
+            BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
             void *bundleHandle = NULL;
             bundleHandle = dlopen(bundleInfo->getPath().c_str(), RTLD_LAZY);
 
             if (bundleHandle != NULL)
             {
                 bundleActivator =
-                        (activator_t *) dlsym(bundleHandle,
-                                ("" + bundleInfoInternal->getActivatorName()
-                                        + "_externalActivateBundle").c_str());
+                    (activator_t *) dlsym(bundleHandle,
+                                          ("" + bundleInfoInternal->getActivatorName()
+                                           + "_externalActivateBundle").c_str());
                 bundleDeactivator =
-                        (deactivator_t *) dlsym(bundleHandle,
-                                ("" + bundleInfoInternal->getActivatorName()
-                                        + "_externalDeactivateBundle").c_str());
+                    (deactivator_t *) dlsym(bundleHandle,
+                                            ("" + bundleInfoInternal->getActivatorName()
+                                             + "_externalDeactivateBundle").c_str());
                 resourceCreator =
-                        (resourceCreator_t *) dlsym(bundleHandle,
-                                ("" + bundleInfoInternal->getActivatorName()
-                                        + "_externalCreateResource").c_str());
+                    (resourceCreator_t *) dlsym(bundleHandle,
+                                                ("" + bundleInfoInternal->getActivatorName()
+                                                 + "_externalCreateResource").c_str());
                 resourceDestroyer =
-                        (resourceDestroyer_t *) dlsym(bundleHandle,
-                                ("" + bundleInfoInternal->getActivatorName()
-                                        + "_externalDestroyResource").c_str());
+                    (resourceDestroyer_t *) dlsym(bundleHandle,
+                                                  ("" + bundleInfoInternal->getActivatorName()
+                                                   + "_externalDestroyResource").c_str());
 
 
                 if ((error = dlerror()) != NULL)
index ecf1926..bd413e2 100644 (file)
@@ -204,7 +204,7 @@ TEST_F(ResourceContainerTest, AddNewSoBundleToContainer)
     std::list<RCSBundleInfo *> bundles;
 
     bundles = m_pResourceContainer->listBundles();
-    m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so","test", 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());
@@ -391,14 +391,19 @@ class ResourceContainerImplTest: public TestWithMock
 
     public:
         ResourceContainerImpl *m_pResourceContainer;
-        RCSBundleInfo *m_pBundleInfo;
+        BundleInfoInternal *m_pBundleInfo;
 
     protected:
         void SetUp()
         {
             TestWithMock::SetUp();
             m_pResourceContainer = ResourceContainerImpl::getImplInstance();
-            m_pBundleInfo = RCSBundleInfo::build();
+            m_pBundleInfo = new BundleInfoInternal();
+        }
+
+        void TearDown()
+        {
+            delete m_pBundleInfo;
         }
 };