1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef RESOURCECONTAINERIMPL_H_
22 #define RESOURCECONTAINERIMPL_H_
24 #include "RCSResourceContainer.h"
25 #include "ResourceContainerBundleAPI.h"
26 #include "BundleInfoInternal.h"
28 #include "RCSRequest.h"
29 #include "RCSResponse.h"
30 #include "RCSResourceObject.h"
32 #include "DiscoverResourceUnit.h"
34 #include <boost/thread.hpp>
35 #include <boost/date_time.hpp>
43 #define BUNDLE_ACTIVATION_WAIT_SEC 10
44 #define BUNDLE_SET_GET_WAIT_SEC 10
46 using namespace OIC::Service;
53 class ResourceContainerImpl: public RCSResourceContainer, public ResourceContainerBundleAPI
56 ResourceContainerImpl();
57 virtual ~ResourceContainerImpl();
59 // methods from ResourceContainer
60 void startContainer(const std::string &configFile);
62 void activateBundle(RCSBundleInfo *bundleInfo);
63 void deactivateBundle(RCSBundleInfo *bundleInfo);
64 void activateBundle(const std::string &bundleId);
65 void deactivateBundle(const std::string &bundleId);
66 void registerBundle(RCSBundleInfo *bundleinfo);
67 void unregisterBundle(RCSBundleInfo *bundleinfo);
68 void unregisterBundleSo(const std::string &id);
70 // methods from ResourceContainerBundleAPI
71 void registerResource(BundleResource *resource);
72 void unregisterResource(BundleResource *resource);
74 void getBundleConfiguration(const std::string &bundleId, configInfo *configOutput);
75 void getResourceConfiguration(const std::string &bundleId,
76 std::vector< resourceInfo > *configOutput);
78 RCSGetResponse getRequestHandler(const RCSRequest &request,
79 const RCSResourceAttributes &attributes);
80 RCSSetResponse setRequestHandler(const RCSRequest &request,
81 const RCSResourceAttributes &attributes);
83 void onNotificationReceived(const std::string &strResourceUri);
85 static ResourceContainerImpl *getImplInstance();
86 static RCSResourceObject::Ptr buildResourceObject(const std::string &strUri,
87 const std::string &strResourceType);
89 void startBundle(const std::string &bundleId);
90 void stopBundle(const std::string &bundleId);
92 void addBundle(const std::string &bundleId, const std::string &bundleUri,
93 const std::string &bundlePath, const std::string &activator,
94 std::map< string, string > params);
95 void removeBundle(const std::string &bundleId);
97 std::list< RCSBundleInfo * > listBundles();
99 void addResourceConfig(const std::string &bundleId, const std::string &resourceUri,
100 std::map< string, string > params);
101 void removeResourceConfig(const std::string &bundleId, const std::string &resourceUri);
103 std::list< string > listBundleResources(const std::string &bundleId);
106 JavaVM *getJavaVM(string bundleId);
107 void unregisterBundleJava(string id);
111 map< std::string, BundleInfoInternal * > m_bundles; // <bundleID, bundleInfo>
112 map< std::string, RCSResourceObject::Ptr > m_mapServers; //<uri, serverPtr>
113 map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
114 map< std::string, list< string > > m_mapBundleResources; //<bundleID, vector<uri>>
115 map< std::string, list< DiscoverResourceUnit::Ptr > > m_mapDiscoverResourceUnits;
116 //<uri, DiscoverUnit>
118 Configuration *m_config;
119 // holds for a bundle the threads for bundle activation
120 map< std::string, boost::thread > m_activators;
121 // used for synchronize the resource registration of multiple bundles
122 std::mutex registrationLock;
123 // used to synchronize the startup of the container with other operation
124 // such as individual bundle activation
125 std::recursive_mutex activationLock;
127 void activateSoBundle(const std::string &bundleId);
128 void deactivateSoBundle(const std::string &bundleId);
129 void addSoBundleResource(const std::string &bundleId, resourceInfo newResourceInfo);
130 void removeSoBundleResource(const std::string &bundleId,
131 const std::string &resourceUri);
132 void registerSoBundle(RCSBundleInfo *bundleInfo);
133 void discoverInputResource(const std::string & outputResourceUri);
134 void undiscoverInputResource(const std::string & outputResourceUri);
135 void activateBundleThread(const std::string &bundleId);
138 map<string, JavaVM *> m_bundleVM;
140 void registerJavaBundle(RCSBundleInfo *bundleInfo);
141 void activateJavaBundle(string bundleId);
142 void deactivateJavaBundle(string bundleId);