Merge branch 'easysetup'
[platform/upstream/iotivity.git] / service / resource-container / src / DiscoverResourceUnit.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 DISCOVERRESOURCEUNIT_H_
22 #define DISCOVERRESOURCEUNIT_H_
23
24 #include <atomic>
25 #include <cstdbool>
26 #include <functional>
27 #include <memory>
28 #include <string>
29 #include <vector>
30
31 #include "RCSDiscoveryManager.h"
32 #include "RCSRemoteResourceObject.h"
33 #include "RCSResourceAttributes.h"
34 #include "RemoteResourceUnit.h"
35 #include "InternalTypes.h"
36
37 namespace OIC
38 {
39     namespace Service
40     {
41         class DiscoverResourceUnit
42         {
43             public:
44                 struct DiscoverResourceInfo
45                 {
46                     DiscoverResourceInfo()
47                         : resourceUri(), resourceType(), attributeName() {}
48                     DiscoverResourceInfo(std::string uri, std::string type, std::string name)
49                         : resourceUri(uri), resourceType(type), attributeName(name) {}
50                     std::string resourceUri;
51                     std::string resourceType;
52                     std::string attributeName;
53                 };
54
55                 typedef std::shared_ptr<DiscoverResourceUnit> Ptr;
56                 typedef std::function<void(RemoteResourceUnit::UPDATE_MSG,
57                                            RCSRemoteResourceObject::Ptr)> UpdatedCBFromServer;
58                 typedef std::function<void(const std::string attributeName,
59                                            std::vector<RCSResourceAttributes::Value> values)>
60                 UpdatedCB;
61                 typedef RemoteResourceUnit::UPDATE_MSG REMOTE_MSG;
62
63                 DiscoverResourceUnit(const std::string &bundleId);
64                 DiscoverResourceUnit(const DiscoverResourceUnit &other)=delete;
65                 DiscoverResourceUnit& operator=( const DiscoverResourceUnit& rhs )=delete;
66                 ~DiscoverResourceUnit();
67
68                 void startDiscover(DiscoverResourceInfo info, UpdatedCB updatedCB);
69
70             private:
71                 std::string m_bundleId;
72                 std::string m_Uri;
73                 std::string m_ResourceType;
74                 std::string m_AttrubuteName;
75                 std::atomic_bool isStartedDiscovery;
76                 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> discoveryTask;
77
78                 std::vector<RemoteResourceUnit::Ptr> m_vecRemoteResource;
79                 RCSDiscoveryManager::ResourceDiscoveredCallback pDiscoveredCB;
80                 UpdatedCBFromServer pUpdatedCBFromServer;
81                 UpdatedCB pUpdatedCB;
82
83                 bool isAlreadyDiscoveredResource(RCSRemoteResourceObject::Ptr discoveredResource);
84                 void discoverdCB(RCSRemoteResourceObject::Ptr remoteObject, std::string uri);
85                 void onUpdate(REMOTE_MSG msg, RCSRemoteResourceObject::Ptr updatedResource);
86
87                 std::vector<RCSResourceAttributes::Value>
88                 buildInputResourceData(RCSRemoteResourceObject::Ptr updatedResource);
89         };
90     }
91 }
92
93 #endif // DISCOVERRESOURCEUNIT_H_