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