replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-container / src / RemoteResourceUnit.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 REMOTERESOURCEINFO_H_
22 #define REMOTERESOURCEINFO_H_
23
24 #include <mutex>
25
26 #include "RCSRemoteResourceObject.h"
27
28 namespace OIC
29 {
30     namespace Service
31     {
32         class RemoteResourceUnit
33         {
34         public:
35             enum class UPDATE_MSG
36             {
37                 DATA_UPDATED,
38                 RESOURCE_DELETED
39             };
40
41             typedef std::shared_ptr<RemoteResourceUnit> Ptr;
42             typedef std::function<void(UPDATE_MSG,
43                 RCSRemoteResourceObject::Ptr)> UpdatedCBFromServer;
44
45             RemoteResourceUnit();
46             ~RemoteResourceUnit();
47
48         private:
49             mutable std::mutex m_mutex;
50             RCSRemoteResourceObject::Ptr remoteObject;
51
52             UpdatedCBFromServer pUpdatedCB;
53             RCSRemoteResourceObject::StateChangedCallback pStateChangedCB;
54             RCSRemoteResourceObject::CacheUpdatedCallback pCacheUpdateCB;
55
56             void stateChangedCB(ResourceState changedState) const;
57             void cacheUpdateCB(const RCSResourceAttributes & updatedAtt, int) const;
58
59         public:
60             static RemoteResourceUnit::Ptr createRemoteResourceInfo(
61                 RCSRemoteResourceObject::Ptr ptr, UpdatedCBFromServer updatedCB);
62             static RemoteResourceUnit::Ptr createRemoteResourceInfoWithStateCB(
63                 RCSRemoteResourceObject::Ptr ptr, UpdatedCBFromServer updatedCB,
64                 RCSRemoteResourceObject::StateChangedCallback stateCB);
65             static RemoteResourceUnit::Ptr createRemoteResourceInfoWithCacheCB(
66                 RCSRemoteResourceObject::Ptr ptr, UpdatedCBFromServer updatedCB,
67                 RCSRemoteResourceObject::CacheUpdatedCallback cacheCB);
68
69             RCSRemoteResourceObject::Ptr getRemoteResourceObject() const;
70             std::string getRemoteResourceUri() const;
71
72             void startCaching() const;
73             void startMonitoring() const;
74         };
75     }
76 }
77
78 #endif // REMOTERESOURCEINFO_H_