Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / controller / core / include / core / Link.hpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 #ifndef LINK_HPP_
7 #define LINK_HPP_
8
9 // ============================================================================
10 // Includes
11 // ============================================================================
12 #include <string>
13 #include <memory>
14 #include "Description.hpp"
15 #include "Service.hpp"
16 #include "Characteristic.hpp"
17
18 // ============================================================================
19 // Namespace
20 // ============================================================================
21 namespace Intel {
22 namespace CCFL {
23 namespace API {
24
25 class Link {
26         // ============================================================
27         // Type Definition(s)
28         // ============================================================
29 public:
30                 typedef std::shared_ptr<Link> SharedPtr;
31                 typedef std::weak_ptr<Link> WeakPtr;
32
33                 typedef std::function<void (const std::string& propertyName, const PropertyGetFunction& asyncReturnFunc)> RegisteredGetPropFunction;
34                 typedef std::function<void (const std::string& propertyName, const std::string& propertyValue, const PropertySetFunction& asyncReturnFunc)> RegisteredSetPropFunction;
35                 typedef std::function<void (const DescriptionGetFunction& asyncReturnFunc)> RegisteredGetDescriptionFunction;
36
37 public:
38         Link() {
39                 name_ = "unknown link name";
40                 registeredGetPropFunction_ = nullptr;
41                 registeredSetPropFunction_ = nullptr;
42                 registeredGetDescriptionFunction_ = nullptr;
43         };
44
45         virtual ~Link() {};
46
47         virtual const std::string& getName() {
48                 return name_;
49         }
50
51         virtual void setName(const std::string name) {
52                 name_ = name;
53         }
54
55         // Used at application interface
56         virtual void getProperty(const std::string& propertyName, PropertyGetFunction& asyncReturnFunc) {
57                 // Call registered function
58                 if (nullptr != registeredGetPropFunction_) {
59                         registeredGetPropFunction_(propertyName, asyncReturnFunc);
60                 }
61         }
62
63         virtual void setProperty(const std::string& propertyName, const std::string& propertyValue, PropertySetFunction& asyncReturnFunc) {
64                 if (nullptr != registeredSetPropFunction_) {
65                         registeredSetPropFunction_(propertyName, propertyValue, asyncReturnFunc);
66                 }
67         }
68
69         virtual void getDescription(DescriptionGetFunction& asyncReturnFunc) {
70                 if (nullptr != registeredGetDescriptionFunction_) {
71                         registeredGetDescriptionFunction_(asyncReturnFunc);
72                 }
73         }
74
75         // Used at protocol interface
76         virtual void registerGetPropertyFunction(RegisteredGetPropFunction& registeredGetPropFunction) {
77                 registeredGetPropFunction_ = registeredGetPropFunction;
78         }
79
80         virtual void registerSetPropertyFunction(RegisteredSetPropFunction& registeredSetPropFunction) {
81                 registeredSetPropFunction_ = registeredSetPropFunction;
82         }
83
84         virtual void registerGetDescriptionFunction(RegisteredGetDescriptionFunction& registeredGetDescriptionFunction) {
85                 registeredGetDescriptionFunction_ = registeredGetDescriptionFunction;
86         }
87
88 private:
89         std::string name_;
90         RegisteredGetPropFunction registeredGetPropFunction_;
91         RegisteredSetPropFunction registeredSetPropFunction_;
92         RegisteredGetDescriptionFunction registeredGetDescriptionFunction_;
93 };
94
95 }
96 }
97 }
98
99 #endif /* LINK_HPP_ */