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 RH_RESOURCEHOSTING_H_
22 #define RH_RESOURCEHOSTING_H_
30 #include "RCSDiscoveryManager.h"
31 #include "RCSRemoteResourceObject.h"
32 #include "HostingObject.h"
42 typedef RCSRemoteResourceObject::Ptr RemoteObjectPtr;
43 typedef std::lock_guard<std::mutex> RHLock;
44 typedef std::string HostingObjectKey;
46 typedef std::function<void(RemoteObjectPtr)> DiscoveryCallback;
47 typedef HostingObject::DestroyedCallback DestroyedCallback;
53 static ResourceHosting * getInstance();
57 ~ResourceHosting() = default;
59 ResourceHosting(ResourceHosting&&) = delete;
60 ResourceHosting(const ResourceHosting&) = delete;
61 ResourceHosting& operator=(ResourceHosting&&) = delete;
62 ResourceHosting& operator=(const ResourceHosting&) = delete;
64 std::mutex m_mutexForList;
65 std::atomic_bool m_isStartedHosting;
67 std::unordered_map<HostingObjectKey, HostingObject::Ptr> m_hostingObjects;
68 RCSDiscoveryManager::DiscoveryTask::Ptr m_discoveryTask;
70 void createDiscoveryListener();
71 void discoveryHandler(RemoteObjectPtr remoteResource);
73 inline HostingObjectKey generateHostingObjectKey(std::string address, std::string uri)
75 return HostingObjectKey(address + uri);
77 inline HostingObjectKey generateHostingObjectKey(RemoteObjectPtr rResource)
79 return HostingObjectKey(rResource->getAddress() + rResource->getUri());
82 HostingObject::Ptr findRemoteResource(RemoteObjectPtr remoteResource);
84 void destroyedHostingObject(const HostingObjectKey & key);
87 } /* namespace Service */
90 #endif /* RH_RESOURCEHOSTING_H_ */