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 RB_RESOURCEBROKER_H_
22 #define RB_RESOURCEBROKER_H_
29 #include <condition_variable>
31 #include "BrokerTypes.h"
32 #include "ResourcePresence.h"
41 class InvalidParameterException: public RCSException
44 InvalidParameterException(std::string&& what)
45 : RCSException{ std::move(what) } {}
47 class FailedSubscribePresenceException: public RCSPlatformException
50 FailedSubscribePresenceException(OCStackResult reason)
51 : RCSPlatformException{reason} {}
54 static ResourceBroker * getInstance();
56 BrokerID hostResource(PrimitiveResourcePtr pResource, BrokerCB cb);
57 void cancelHostResource(BrokerID brokerId);
59 BROKER_STATE getResourceState(BrokerID brokerId);
60 BROKER_STATE getResourceState(PrimitiveResourcePtr pResource);
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;
68 ResourceBroker() = default;
70 ResourceBroker(const ResourceBroker&) = delete;
71 ResourceBroker(ResourceBroker&&) = delete;
73 ResourceBroker& operator=(const ResourceBroker&) const = delete;
74 ResourceBroker& operator=(ResourceBroker&&) const = delete;
76 void initializeResourceBroker();
77 BrokerID generateBrokerID();
78 ResourcePresencePtr findResourcePresence(PrimitiveResourcePtr pResource);
80 } // namespace Service
83 #endif /* RB_RESOURCEBROKER_H_ */