1e040673fd50735abb81352480b076f40f9e30c9
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceContainer / include / ResourceContainerImpl.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef RESOURCECONTAINERIMPL_H_
22 #define RESOURCECONTAINERIMPL_H_
23
24
25
26 #include "ResourceContainer.h"
27 #include "ResourceContainerBundleAPI.h"
28 #include "BundleInfoInternal.h"
29
30 #include "RCSRequest.h"
31 #include "RCSResponse.h"
32 #include "ResourceObject.h"
33
34 #if(JAVA_SUPPORT)
35     #include <jni.h>
36 #endif
37
38 #include <map>
39
40 using namespace OIC::Service;
41
42 namespace OIC
43 {
44     namespace Service
45     {
46
47         class ResourceContainerImpl: public ResourceContainer, public ResourceContainerBundleAPI
48         {
49             public:
50                 ResourceContainerImpl();
51                 virtual ~ResourceContainerImpl();
52
53                 // methods from ResourceContainer
54                 void startContainer(const std::string &configFile);
55                 void stopContainer();
56                 void activateBundle(BundleInfo *bundleInfo);
57                 void deactivateBundle(BundleInfo *bundleInfo);
58                 void activateBundle(const std::string &bundleId);
59                 void deactivateBundle(const std::string &bundleId);
60                 void registerBundle(BundleInfo *bundleinfo);
61                 void unregisterBundle(BundleInfo *bundleinfo);
62                 void unregisterBundleSo(const std::string &id);
63
64
65                 // methods from ResourceContainerBundleAPI
66                 void registerResource(BundleResource *resource);
67                 void unregisterResource(BundleResource *resource);
68
69                 void getBundleConfiguration(const std::string &bundleId, configInfo *configOutput);
70                 void getResourceConfiguration(const std::string &bundleId,
71                                               std::vector< resourceInfo > *configOutput);
72
73                 RCSGetResponse getRequestHandler(const RCSRequest &request,
74                                                  const ResourceAttributes &attributes);
75                 RCSSetResponse setRequestHandler(const RCSRequest &request,
76                                                  const ResourceAttributes &attributes);
77
78                 void onNotificationReceived(const std::string &strResourceUri);
79
80                 static ResourceContainerImpl *getImplInstance();
81                 static ResourceObject::Ptr buildResourceObject(const std::string &strUri, const std::string &strResourceType);
82
83                 void startBundle(const std::string &bundleId);
84                 void stopBundle(const std::string &bundleId);
85
86                 void addBundle(const std::string &bundleId, const std::string &bundleUri, const std::string &bundlePath,
87                                std::map<string, string> params);
88                 void removeBundle(const std::string &bundleId);
89
90                 std::list<BundleInfo *> listBundles();
91
92                 void addResourceConfig(const std::string &bundleId, const std::string &resourceUri, std::map<string, string> params);
93                 void removeResourceConfig(const std::string &bundleId, const std::string &resourceUri);
94
95                 std::list<string> listBundleResources(const std::string &bundleId);
96
97 #if(JAVA_SUPPORT)
98                 JavaVM *getJavaVM(string bundleId);
99                 void unregisterBundleJava(string id);
100 #endif
101
102
103             private:
104                 map< std::string, BundleInfoInternal * > m_bundles; // <bundleID, bundleInfo>
105                 map< std::string, ResourceObject::Ptr > m_mapServers; //<uri, serverPtr>
106                 map< std::string, BundleResource * > m_mapResources; //<uri, resourcePtr>
107                 map< std::string, list<string> > m_mapBundleResources; //<bundleID, vector<uri>>
108                 string m_configFile;
109                 Configuration *m_config;
110
111
112                 void activateSoBundle(const std::string &bundleId);
113                 void deactivateSoBundle(const std::string &bundleId);
114                 void addSoBundleResource(const std::string &bundleId, resourceInfo newResourceInfo);
115                 void removeSoBundleResource(const std::string &bundleId, const std::string &resourceUri);
116                 void registerSoBundle(BundleInfo *bundleInfo);
117
118 #if(JAVA_SUPPORT)
119                 map<string, JavaVM *> m_bundleVM;
120
121                 void registerJavaBundle(BundleInfo *bundleInfo);
122                 void activateJavaBundle(string bundleId);
123                 void deactivateJavaBundle(string bundleId);
124
125 #endif
126
127         };
128     }
129 }
130 #endif