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(OCStackResult, const unsigned int, const std::string&)> SubscribeCallback;
56 typedef std::function<
57 void(std::shared_ptr<RCSRemoteResourceObject>)> DiscoveryCallback;
58 typedef std::function<void()> DestroyedCallback;
64 static ResourceHosting * getInstance();
68 ~ResourceHosting() = default;
70 ResourceHosting(const ResourceHosting&) = delete;
71 ResourceHosting(ResourceHosting&&) = delete;
72 ResourceHosting& operator=(const ResourceHosting&) const = delete;
73 ResourceHosting& operator=(ResourceHosting&&) const = delete;
75 static ResourceHosting * s_instance;
76 static std::mutex s_mutexForCreation;
77 std::mutex mutexForList;
79 std::list<HostingObjectPtr> hostingObjectList;
81 RCSDiscoveryManager * discoveryManager;
82 PresenceSubscriber presenceHandle;
83 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> discoveryTask;
85 SubscribeCallback pPresenceCB;
86 DiscoveryCallback pDiscoveryCB;
88 void initializeResourceHosting();
90 void requestMulticastPresence();
91 void requestMulticastDiscovery();
92 void requestDiscovery(std::string address = std::string());
94 void presenceHandler(OCStackResult ret, const unsigned int seq, const std::string & address);
95 void discoverHandler(RemoteObjectPtr remoteResource);
97 HostingObjectPtr findRemoteResource(RemoteObjectPtr remoteResource);
98 bool isSameRemoteResource(RemoteObjectPtr remoteResource_1, RemoteObjectPtr remoteResource_2);
100 void destroyedHostingObject(HostingObjectWeakPtr destroyedWeakPtr);
104 } /* namespace Service */
105 } /* namespace OIC */
107 #endif /* RH_RESOURCEHOSTING_H_ */