Merge "Partial Implementation of US1574:"
[platform/upstream/iotivity.git] / csdk / controller / core / include / core / Link.hpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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 LINK_HPP_
22 #define LINK_HPP_
23
24 // ============================================================================
25 // Includes
26 // ============================================================================
27 #include <string>
28 #include <memory>
29 #include "Description.hpp"
30 #include "Service.hpp"
31 #include "Characteristic.hpp"
32
33 // ============================================================================
34 // Namespace
35 // ============================================================================
36 namespace Intel {
37 namespace CCFL {
38 namespace API {
39
40 class Link {
41         // ============================================================
42         // Type Definition(s)
43         // ============================================================
44 public:
45                 typedef std::shared_ptr<Link> SharedPtr;
46                 typedef std::weak_ptr<Link> WeakPtr;
47
48                 typedef std::function<void (const std::string& propertyName, const PropertyGetFunction& asyncReturnFunc)> RegisteredGetPropFunction;
49                 typedef std::function<void (const std::string& propertyName, const std::string& propertyValue, const PropertySetFunction& asyncReturnFunc)> RegisteredSetPropFunction;
50                 typedef std::function<void (const DescriptionGetFunction& asyncReturnFunc)> RegisteredGetDescriptionFunction;
51
52 public:
53         Link() {
54                 name_ = "unknown link name";
55                 registeredGetPropFunction_ = nullptr;
56                 registeredSetPropFunction_ = nullptr;
57                 registeredGetDescriptionFunction_ = nullptr;
58         };
59
60         virtual ~Link() {};
61
62         virtual const std::string& getName() {
63                 return name_;
64         }
65
66         virtual void setName(const std::string name) {
67                 name_ = name;
68         }
69
70         // Used at application interface
71         virtual void getProperty(const std::string& propertyName, PropertyGetFunction& asyncReturnFunc) {
72                 // Call registered function
73                 if (nullptr != registeredGetPropFunction_) {
74                         registeredGetPropFunction_(propertyName, asyncReturnFunc);
75                 }
76         }
77
78         virtual void setProperty(const std::string& propertyName, const std::string& propertyValue, PropertySetFunction& asyncReturnFunc) {
79                 if (nullptr != registeredSetPropFunction_) {
80                         registeredSetPropFunction_(propertyName, propertyValue, asyncReturnFunc);
81                 }
82         }
83
84         virtual void getDescription(DescriptionGetFunction& asyncReturnFunc) {
85                 if (nullptr != registeredGetDescriptionFunction_) {
86                         registeredGetDescriptionFunction_(asyncReturnFunc);
87                 }
88         }
89
90         // Used at protocol interface
91         virtual void registerGetPropertyFunction(RegisteredGetPropFunction& registeredGetPropFunction) {
92                 registeredGetPropFunction_ = registeredGetPropFunction;
93         }
94
95         virtual void registerSetPropertyFunction(RegisteredSetPropFunction& registeredSetPropFunction) {
96                 registeredSetPropFunction_ = registeredSetPropFunction;
97         }
98
99         virtual void registerGetDescriptionFunction(RegisteredGetDescriptionFunction& registeredGetDescriptionFunction) {
100                 registeredGetDescriptionFunction_ = registeredGetDescriptionFunction;
101         }
102
103 private:
104         std::string name_;
105         RegisteredGetPropFunction registeredGetPropFunction_;
106         RegisteredSetPropFunction registeredSetPropFunction_;
107         RegisteredGetDescriptionFunction registeredGetDescriptionFunction_;
108 };
109
110 }
111 }
112 }
113
114 #endif /* LINK_HPP_ */