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_
33 #include "RCSAddress.h"
34 #include "PresenceSubscriber.h"
35 #include "HostingObject.h"
36 #include "PrimitiveResource.h"
37 #include "RCSDiscoveryManager.h"
44 class RCSDiscoveryManager;
48 typedef std::shared_ptr<HostingObject> HostingObjectPtr;
49 typedef std::weak_ptr<HostingObject> HostingObjectWeakPtr;
51 typedef std::shared_ptr<RCSRemoteResourceObject> RemoteObjectPtr;
52 typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
54 typedef std::function<
55 void(std::shared_ptr<RCSRemoteResourceObject>)> DiscoveryCallback;
56 typedef std::function<void()> DestroyedCallback;
62 static ResourceHosting * getInstance();
66 ~ResourceHosting() = default;
68 ResourceHosting(const ResourceHosting&) = delete;
69 ResourceHosting(ResourceHosting&&) = delete;
70 ResourceHosting& operator=(const ResourceHosting&) const = delete;
71 ResourceHosting& operator=(ResourceHosting&&) const = delete;
73 static ResourceHosting * s_instance;
74 static std::mutex s_mutexForCreation;
75 std::mutex mutexForList;
77 std::list<HostingObjectPtr> hostingObjectList;
79 RCSDiscoveryManager * discoveryManager;
80 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> discoveryTask;
82 DiscoveryCallback pDiscoveryCB;
84 void initializeResourceHosting();
86 void requestMulticastDiscovery();
88 void discoverHandler(RemoteObjectPtr remoteResource);
90 HostingObjectPtr findRemoteResource(RemoteObjectPtr remoteResource);
91 bool isSameRemoteResource(RemoteObjectPtr remoteResource_1, RemoteObjectPtr remoteResource_2);
93 void destroyedHostingObject(HostingObjectWeakPtr destroyedWeakPtr);
97 } /* namespace Service */
100 #endif /* RH_RESOURCEHOSTING_H_ */