c5c9a3412bdde715c0656a5ec6995f11fdc504ab
[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 #include "RCSRemoteResourceObject.h"
26 #include "RCSResourceObject.h"
27 #include "RequestObject.h"
28
29 #define OIC_HOSTING_LOG(level, fmt, args...) OIC_LOG_V((level), PCF("Hosting"), fmt, ##args)
30
31 namespace OIC
32 {
33 namespace Service
34 {
35
36 class HostingObject : public std::enable_shared_from_this<HostingObject>
37 {
38 private:
39     typedef RCSResourceObject::Ptr ResourceObjectPtr;
40     typedef RequestObject::Ptr RequestObjectPtr;
41     typedef RCSRemoteResourceObject::Ptr RemoteObjectPtr;
42
43 public:
44     typedef std::shared_ptr<HostingObject> Ptr;
45     typedef std::weak_ptr<HostingObject> wPtr;
46
47     typedef std::function<void()> DestroyedCallback;
48     typedef RCSRemoteResourceObject::StateChangedCallback BrokerCallback;
49     typedef RCSRemoteResourceObject::CacheUpdatedCallback CacheCallback;
50     typedef RCSResourceObject::SetRequestHandler SetRequestHandler;
51
52 public:
53     HostingObject();
54     ~HostingObject();
55
56     HostingObject(const HostingObject&) = delete;
57     HostingObject(HostingObject&&) = delete;
58     HostingObject& operator=(HostingObject&&) = delete;
59     HostingObject& operator=(const HostingObject&) = delete;
60
61     static HostingObject::Ptr createHostingObject(const RemoteObjectPtr & rResource,
62             DestroyedCallback destroyCB);
63
64     RemoteObjectPtr getRemoteResource() const;
65
66 private:
67     RemoteObjectPtr remoteObject;
68     ResourceObjectPtr mirroredServer;
69
70     CacheCallback pDataUpdateCB;
71     DestroyedCallback pDestroyCB;
72
73     std::mutex mutexForCB;
74
75     ResourceObjectPtr createMirroredServer(RemoteObjectPtr rObject);
76
77     RCSSetResponse setRequestHandler(
78             const RCSRequest & request, RCSResourceAttributes & attributes);
79
80     void destroyHostingObject();
81
82 public:
83     void stateChangedCB(ResourceState state);
84     void dataChangedCB(const RCSResourceAttributes & attributes);
85 };
86
87 } /* namespace Service */
88 } /* namespace OIC */
89
90 #endif /* RH_HOSTINGOBJECT_H_ */