a93a30a4c6b69cd13bfef792d2e93b335cc7d02b
[platform/upstream/iotivity.git] / service / notification-manager / NotificationManager / src / HostingObject.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef RH_HOSTINGOBJECT_H_
22 #define RH_HOSTINGOBJECT_H_
23
24 #include "ResourceClient.h"
25 #include "ResourceObject.h"
26 #include "RequestObject.h"
27 #include "ResourceBroker.h"
28 #include "ResourceCacheManager.h"
29 #include "PrimitiveResource.h"
30
31 namespace OIC
32 {
33 namespace Service
34 {
35
36 class HostingObject
37 {
38 private:
39     typedef std::shared_ptr<ResourceObject> ResourceObjectPtr;
40     typedef std::shared_ptr<RemoteResourceObject> RemoteObjectPtr;
41     typedef std::shared_ptr<RequestObject> RequestObjectPtr;
42     typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
43
44     typedef std::function<void(ResourceState)> BrokerCallback;
45     typedef std::function<void(const ResourceAttributes &)> CacheCallback;
46     typedef std::function<void()> DestroyedCallback;
47
48     typedef std::function<
49             RCSSetResponse(const RCSRequest&, ResourceAttributes&)> SetRequestHandler;
50
51 public:
52     HostingObject();
53     ~HostingObject() = default;
54
55     void initializeHostingObject(RemoteObjectPtr rResource, DestroyedCallback destroyCB);
56
57     RemoteObjectPtr getRemoteResource() const;
58
59 private:
60     RemoteObjectPtr remoteObject;
61     ResourceObjectPtr mirroredServer;
62
63     ResourceState remoteState;
64
65     BrokerCallback pStateChangedCB;
66     CacheCallback pDataUpdateCB;
67     DestroyedCallback pDestroyCB;
68
69     SetRequestHandler pSetRequestHandler;
70
71     ResourceObjectPtr createMirroredServer(RemoteObjectPtr rObject);
72
73     void stateChangedCB(ResourceState state, RemoteObjectPtr rObject);
74     void dataChangedCB(const ResourceAttributes & attributes, RemoteObjectPtr rObject);
75
76     RCSSetResponse setRequestHandler(
77             const RCSRequest & request, ResourceAttributes & attributes);
78
79     void destroyHostingObject();
80
81 };
82
83 } /* namespace Service */
84 } /* namespace OIC */
85
86 #endif /* RH_HOSTINGOBJECT_H_ */