Update Resource Broker Initial Version
[platform/upstream/iotivity.git] / service / basis / resourceBroker / include / ResourceBroker.h
1 /*
2  * ResourceBroker.h
3  *
4  *  Created on: May 20, 2015
5  *      Author: root
6  */
7
8 #ifndef RESOURCEBROKER_H_
9 #define RESOURCEBROKER_H_
10
11 #include <iostream>
12 #include <functional>
13 #include <pthread.h>
14 #include <cstdint>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 #include <list>
19 #include <mutex>
20 #include <thread>
21 #include <condition_variable>
22 #include <algorithm>
23
24 // Iotivity Base CAPI
25 #include "ocstack.h"
26 #include "logger.h"
27
28 // internal class
29 #include "PresenceInfo.h"
30
31 #define CACHE_TAG PCF("BROKER")
32
33
34 typedef std::function<OCStackResult(PrimitiveResource * resource)> DiscoverCB;
35 enum class BROKER_STATE
36 {
37     ALIVE = 0,
38     REQUESTED,
39     LOST_SIGNAL,
40     DESTROYED
41 };
42 class ResourceBroker {
43 public:
44     ResourceBroker * getInstance();
45
46     OCStackResult discoverResource(PrimitiveResource & pResource, DiscoverCB cb);
47     OCStackResult discoverResource(const std::string uri, const std::string address, DiscoverCB cb);
48
49     OCStackResult hostResource(PrimitiveResource & pResource, BrokerCB cb);
50     OCStackResult hostResource(
51             const std::string Uri, const std::string address, BrokerCB cb);
52
53     OCStackResult cancelHostResource(PrimitiveResource & pResource);
54     OCStackResult cancelHostResource(
55             const std::string uri, const std::string address);
56
57     OCStackResult getResourceState(PrimitiveResource & pResource);
58     OCStackResult getResourceState(
59             const std::string address, const std::string uri);
60
61 private:
62     ResourceBroker();
63     ~ResourceBroker();
64     bool isPrimitiveResource(PrimitiveResource& pResource, BrokerCB cb);
65     static ResourceBroker * s_instance;
66     static std::mutex s_mutexForCreation;
67     static std::list< PresenceInfo * > s_presenceInfo;
68 };
69
70 #endif /* RESOURCEBROKER_H_ */