/src/wpantund/src/ncp-spinel/SpinelNCPVendorCustom.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * |
3 | | * Copyright (c) 2018 Nest Labs, Inc. |
4 | | * All rights reserved. |
5 | | * |
6 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | | * you may not use this file except in compliance with the License. |
8 | | * You may obtain a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, software |
13 | | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | | * See the License for the specific language governing permissions and |
16 | | * limitations under the License. |
17 | | * |
18 | | */ |
19 | | |
20 | | #if HAVE_CONFIG_H |
21 | | #include <config.h> |
22 | | #endif |
23 | | |
24 | | #include "SpinelNCPVendorCustom.h" |
25 | | |
26 | | #include <syslog.h> |
27 | | #include <errno.h> |
28 | | |
29 | | #include "assert-macros.h" |
30 | | #include "time-utils.h" |
31 | | #include "any-to.h" |
32 | | #include "spinel-extra.h" |
33 | | #include "IPv6Helpers.h" |
34 | | #include "SpinelNCPInstance.h" |
35 | | #include "SpinelNCPTask.h" |
36 | | #include "SpinelNCPTaskSendCommand.h" |
37 | | |
38 | | using namespace nl; |
39 | | using namespace wpantund; |
40 | | |
41 | | SpinelNCPVendorCustom::SpinelNCPVendorCustom(SpinelNCPInstance* instance): |
42 | 11.5k | mInstance(instance) |
43 | 11.5k | { |
44 | | // Warning: `instance` hasn't yet been fully constructed at this point. |
45 | 11.5k | } |
46 | | |
47 | | SpinelNCPVendorCustom::~SpinelNCPVendorCustom() |
48 | 11.5k | { |
49 | | // Warning: `instance` has been partially destructed at this point. |
50 | 11.5k | } |
51 | | |
52 | | bool |
53 | | SpinelNCPVendorCustom::setup_property_supported_by_class(const std::string& prop_name) |
54 | 0 | { |
55 | 0 | return false; |
56 | 0 | } |
57 | | |
58 | | const std::set<std::string>& |
59 | | SpinelNCPVendorCustom::get_supported_property_keys()const |
60 | 2.44M | { |
61 | 2.44M | if (mSupportedProperties.empty()) { |
62 | | // Populate mSupportedProperties here. |
63 | 2.44M | } |
64 | | |
65 | 2.44M | return mSupportedProperties; |
66 | 2.44M | } |
67 | | |
68 | | bool |
69 | | SpinelNCPVendorCustom::is_property_key_supported(const std::string& key)const |
70 | 2.44M | { |
71 | 2.44M | return get_supported_property_keys().count(key) != 0; |
72 | 2.44M | } |
73 | | |
74 | | void |
75 | | SpinelNCPVendorCustom::property_get_value(const std::string& key, CallbackWithStatusArg1 cb) |
76 | 0 | { |
77 | 0 | #define SIMPLE_SPINEL_GET(prop__, type__) \ |
78 | 0 | mInstance->start_new_task(SpinelNCPTaskSendCommand::Factory(this) \ |
79 | 0 | .set_callback(cb) \ |
80 | 0 | .add_command( \ |
81 | 0 | SpinelPackData(SPINEL_FRAME_PACK_CMD_PROP_VALUE_GET, prop__) \ |
82 | 0 | ) \ |
83 | 0 | .set_reply_format(type__) \ |
84 | 0 | .finish() \ |
85 | 0 | ) |
86 | |
|
87 | 0 | if (strcaseequal(key.c_str(), "__CustomKeyHere__")) { |
88 | 0 | cb(0, boost::any(std::string("spinel"))); |
89 | |
|
90 | 0 | } else { |
91 | 0 | cb(kWPANTUNDStatus_FeatureNotSupported, |
92 | 0 | boost::any(std::string("Cannot get property value for ") + key)); |
93 | 0 | } |
94 | 0 | } |
95 | | |
96 | | void |
97 | | SpinelNCPVendorCustom::property_set_value(const std::string& key, const boost::any& value, CallbackWithStatus cb) |
98 | 0 | { |
99 | 0 | if (strcaseequal(key.c_str(), "__CustomKeyHere__")) { |
100 | 0 | cb(kWPANTUNDStatus_Ok); |
101 | |
|
102 | 0 | } else { |
103 | 0 | cb(kWPANTUNDStatus_FeatureNotSupported); |
104 | 0 | } |
105 | 0 | } |
106 | | |
107 | | void |
108 | | SpinelNCPVendorCustom::property_insert_value(const std::string& key, const boost::any& value, CallbackWithStatus cb) |
109 | 0 | { |
110 | 0 | if (strcaseequal(key.c_str(), "__CustomKeyHere__")) { |
111 | 0 | cb(kWPANTUNDStatus_Ok); |
112 | |
|
113 | 0 | } else { |
114 | 0 | cb(kWPANTUNDStatus_FeatureNotSupported); |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | | void |
119 | | SpinelNCPVendorCustom::property_remove_value(const std::string& key, const boost::any& value, CallbackWithStatus cb) |
120 | 0 | { |
121 | 0 | if (strcaseequal(key.c_str(), "__CustomKeyHere__")) { |
122 | 0 | cb(kWPANTUNDStatus_Ok); |
123 | |
|
124 | 0 | } else { |
125 | 0 | cb(kWPANTUNDStatus_FeatureNotSupported); |
126 | 0 | } |
127 | 0 | } |
128 | | |
129 | | cms_t |
130 | | SpinelNCPVendorCustom::get_ms_to_next_event(void) |
131 | 2.76M | { |
132 | 2.76M | return CMS_DISTANT_FUTURE; |
133 | 2.76M | } |
134 | | |
135 | | void |
136 | | SpinelNCPVendorCustom::process(void) |
137 | 2.74M | { |
138 | | // Do nothing for now. |
139 | 2.74M | } |