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"
43 class RCSDiscoveryManager;
47 typedef std::shared_ptr<HostingObject> HostingObjectPtr;
48 typedef std::shared_ptr<RCSRemoteResourceObject> RemoteObjectPtr;
49 typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
51 typedef std::function<
52 void(OCStackResult, const unsigned int, const std::string&)> SubscribeCallback;
53 typedef std::function<
54 void(std::shared_ptr<RCSRemoteResourceObject>)> DiscoveryCallback;
55 typedef std::function<void()> DestroyedCallback;
61 static ResourceHosting * getInstance();
65 ~ResourceHosting() = default;
67 ResourceHosting(const ResourceHosting&) = delete;
68 ResourceHosting(ResourceHosting&&) = delete;
69 ResourceHosting& operator=(const ResourceHosting&) const = delete;
70 ResourceHosting& operator=(ResourceHosting&&) const = delete;
72 static ResourceHosting * s_instance;
73 static std::mutex s_mutexForCreation;
75 std::list<HostingObjectPtr> hostingObjectList;
77 RCSDiscoveryManager * discoveryManager;
78 PresenceSubscriber presenceHandle;
80 SubscribeCallback pPresenceCB;
81 DiscoveryCallback pDiscoveryCB;
83 void initializeResourceHosting();
85 void requestMulticastPresence();
86 void requestMulticastDiscovery();
87 void requestDiscovery(std::string address = std::string());
89 void presenceHandler(OCStackResult ret, const unsigned int seq, const std::string & address);
90 void discoverHandler(RemoteObjectPtr remoteResource);
92 HostingObjectPtr findRemoteResource(RemoteObjectPtr remoteResource);
93 bool isSameRemoteResource(RemoteObjectPtr remoteResource_1, RemoteObjectPtr remoteResource_2);
95 void destroyedHostingObject(HostingObjectPtr destroyedPtr);
99 } /* namespace Service */
100 } /* namespace OIC */
102 #endif /* RH_RESOURCEHOSTING_H_ */