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