Modify empty parameter handling in RCSDiscoveryManager
[platform/upstream/iotivity.git] / service / resource-encapsulation / include / RCSDiscoveryManagerImpl.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 /**
22  * @file
23  *
24  * This file contains the RCSActiveDiscoveryManager class which provide APIs to discover the Resource in the network
25  *
26  */
27
28 #ifndef RCSDISCOVERYMANAGER_IMPL_H
29 #define RCSDISCOVERYMANAGER_IMPL_H
30
31 #include <memory>
32 #include <functional>
33 #include <list>
34 #include <mutex>
35 #include <unordered_map>
36 #include <algorithm>
37
38 #include "octypes.h"
39
40 #include "RCSDiscoveryManager.h"
41 #include "RCSAddress.h"
42 #include "ExpiryTimer.h"
43 #include "PrimitiveResource.h"
44 #include "RCSRemoteResourceObject.h"
45
46 namespace OIC
47 {
48     namespace Service
49     {
50         class RCSDiscoveryManager;
51         class PrimitiveResource;
52         class RCSAddress;
53         class DiscoverRequestInfo
54         {
55             public:
56
57                 std::string m_address;
58                 std::string m_relativeUri;
59                 std::string m_resourceType;
60                 std::list<std::string> m_receivedIds;
61                 bool m_isReceivedFindCallback;
62                 DiscoverCallback m_findCB;
63                 RCSDiscoveryManager::ResourceDiscoveredCallback m_discoverCB;
64         };
65
66         class RCSDiscoveryManagerImpl
67         {
68             static unsigned int s_uniqueId;
69
70             public:
71
72                 typedef std::function<void(OCStackResult, const unsigned int,
73                         const std::string&)> PresenceCallback;
74                 typedef unsigned int ID;
75                 typedef std::function<void(std::shared_ptr< PrimitiveResource >, ID)> FindCallback;
76
77             public:
78
79                 static RCSDiscoveryManagerImpl* getInstance();
80
81                 DiscoverRequestInfo m_discoveryItem;
82                 std::unordered_map<ID,DiscoverRequestInfo> m_discoveryMap;
83                 PresenceCallback m_presenceCB;
84                 ExpiryTimer::Callback m_pollingCB;
85                 ExpiryTimer m_timer;
86                 ID m_timerHandle;
87
88             private:
89                 static RCSDiscoveryManagerImpl * s_instance;
90                 static std::mutex s_mutexForCreation;
91                 std::mutex m_mutex;
92
93             public:
94
95                 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> startDiscovery(const RCSAddress& address,
96                         const std::string& relativeURI,const std::string& resourceType,
97                         RCSDiscoveryManager::ResourceDiscoveredCallback cb);
98
99             private:
100
101                 void requestMulticastPresence();
102                 void initializedDiscoveryEnvironment();
103                 void findCallback(std::shared_ptr< PrimitiveResource > resource, ID discoverID);
104                 void pollingCallback(unsigned int /*msg*/);
105                 void presenceCallback(OCStackResult, const unsigned int,const std::string&);
106                 bool isDuplicatedCallback(std::shared_ptr<PrimitiveResource> resource,ID discoverID);
107                 ID createId();
108
109             private:
110
111                 RCSDiscoveryManagerImpl() = default;;
112                 ~RCSDiscoveryManagerImpl() = default;
113         };
114     }
115 }
116 #endif // RCSDISCOVERYMANAGER_IMPL_H