- 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>
* 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>
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
*
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
/**
* 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
*/
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_ */
#ifndef RCSRESOURCECONTAINER_H_
#define RCSRESOURCECONTAINER_H_
-#include <iostream>
#include <string>
#include <vector>
#include <map>
{
public:
/**
- * Constructor
- */
- RCSResourceContainer();
-
- /**
- *virtual Destructor
- */
- virtual ~RCSResourceContainer();
-
- /**
* API for starting the Container
*
* @details This API start the container with the provided Configuration file.
* @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
*
*
*/
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;
};
}
}
#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"
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
* @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;
};
}
}
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;
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();
<bundle>
<id>oic.bundle.discomfortIndexSensor</id>
<path>libDISensorBundle.so</path>
+ <activator>disensor</activator>
<version>1.0.0</version>
<resources>
<resourceInfo>
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
{
}
-
- RCSBundleInfo *RCSBundleInfo::build()
- {
- BundleInfoInternal *newBundleInfo = new BundleInfoInternal();
- return newBundleInfo;
- }
}
}
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]);
}
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;
else
{
- RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
+ BundleInfoInternal *bundleInfo = new BundleInfoInternal();
bundleInfo->setID(bundleId);
bundleInfo->setPath(bundlePath);
bundleInfo->setActivatorName(activator);
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;
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)
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());
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;
}
};