Imported Upstream version 0.9.2
[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 "RCSRemoteResourceObject.h"
25 #include "RCSResourceObject.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 void OIC_HOSTING_LOG(LogLevel level, const char * format, ...);
37
38 class HostingObject
39 {
40 private:
41     typedef std::shared_ptr<RCSResourceObject> ResourceObjectPtr;
42     typedef std::shared_ptr<RCSRemoteResourceObject> RemoteObjectPtr;
43     typedef std::shared_ptr<RequestObject> RequestObjectPtr;
44     typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
45
46     typedef std::function<void(ResourceState)> BrokerCallback;
47     typedef std::function<void(const RCSResourceAttributes &)> CacheCallback;
48     typedef std::function<void()> DestroyedCallback;
49
50     typedef std::function<
51             RCSSetResponse(const RCSRequest&, RCSResourceAttributes&)> SetRequestHandler;
52
53 public:
54     HostingObject();
55     ~HostingObject() = default;
56
57     void initializeHostingObject(RemoteObjectPtr rResource, DestroyedCallback destroyCB);
58
59     RemoteObjectPtr getRemoteResource() const;
60
61 private:
62     RemoteObjectPtr remoteObject;
63     ResourceObjectPtr mirroredServer;
64
65     ResourceState remoteState;
66
67     BrokerCallback pStateChangedCB;
68     CacheCallback pDataUpdateCB;
69     DestroyedCallback pDestroyCB;
70
71     SetRequestHandler pSetRequestHandler;
72
73     ResourceObjectPtr createMirroredServer(RemoteObjectPtr rObject);
74
75     void stateChangedCB(ResourceState state, RemoteObjectPtr rObject);
76     void dataChangedCB(const RCSResourceAttributes & attributes, RemoteObjectPtr rObject);
77
78     RCSSetResponse setRequestHandler(
79             const RCSRequest & request, RCSResourceAttributes & attributes);
80
81     void destroyHostingObject();
82
83 };
84
85 } /* namespace Service */
86 } /* namespace OIC */
87
88 #endif /* RH_HOSTINGOBJECT_H_ */