Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceBroker / include / ResourceBroker.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 RB_RESOURCEBROKER_H_
22 #define RB_RESOURCEBROKER_H_
23
24 #include <functional>
25 #include <list>
26 #include <string>
27 #include <algorithm>
28 #include <mutex>
29 #include <condition_variable>
30
31 #include "BrokerTypes.h"
32 #include "ResourcePresence.h"
33
34 namespace OIC
35 {
36     namespace Service
37     {
38         class ResourceBroker
39         {
40         public:
41             class InvalidParameterException: public RCSException
42             {
43             public:
44                 InvalidParameterException(std::string&& what)
45                 : RCSException{ std::move(what) } {}
46             };
47             class FailedSubscribePresenceException: public PlatformException
48             {
49             public:
50                 FailedSubscribePresenceException(OCStackResult reason)
51                 : PlatformException{reason} {}
52             };
53
54             static ResourceBroker * getInstance();
55
56             BrokerID hostResource(PrimitiveResourcePtr pResource, BrokerCB cb);
57             void cancelHostResource(BrokerID brokerId);
58
59             BROKER_STATE getResourceState(BrokerID brokerId);
60             BROKER_STATE getResourceState(PrimitiveResourcePtr pResource);
61
62         private:
63             static ResourceBroker * s_instance;
64             static std::mutex s_mutexForCreation;
65             static std::unique_ptr<PresenceList>  s_presenceList;
66             static std::unique_ptr<BrokerIDMap> s_brokerIDMap;
67
68             ResourceBroker() = default;
69             ~ResourceBroker();
70             ResourceBroker(const ResourceBroker&) = delete;
71             ResourceBroker(ResourceBroker&&) = delete;
72
73             ResourceBroker& operator=(const ResourceBroker&) const = delete;
74             ResourceBroker& operator=(ResourceBroker&&) const = delete;
75
76             void initializeResourceBroker();
77             BrokerID generateBrokerID();
78             ResourcePresencePtr findResourcePresence(PrimitiveResourcePtr pResource);
79         };
80     } // namespace Service
81 } // namespace OIC
82
83 #endif /* RB_RESOURCEBROKER_H_ */