use TCP to connect to mbed connector
Fork of mbedConnectorInterfaceWithDM by
mbed-connector-interface/ConnectorEndpoint.h@90:b738617379a6, 2016-11-28 (annotated)
- Committer:
- Maggie17
- Date:
- Mon Nov 28 15:52:56 2016 +0000
- Revision:
- 90:b738617379a6
- Parent:
- 87:00b3837986c7
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 1:16f0fb5b8d97 | 1 | /** |
ansond | 1:16f0fb5b8d97 | 2 | * @file Endpoint.h |
ansond | 1:16f0fb5b8d97 | 3 | * @brief mbed CoAP Endpoint base class |
ansond | 1:16f0fb5b8d97 | 4 | * @author Doug Anson/Chris Paola |
ansond | 1:16f0fb5b8d97 | 5 | * @version 1.0 |
ansond | 1:16f0fb5b8d97 | 6 | * @see |
ansond | 1:16f0fb5b8d97 | 7 | * |
ansond | 1:16f0fb5b8d97 | 8 | * Copyright (c) 2014 |
ansond | 1:16f0fb5b8d97 | 9 | * |
ansond | 1:16f0fb5b8d97 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 1:16f0fb5b8d97 | 11 | * you may not use this file except in compliance with the License. |
ansond | 1:16f0fb5b8d97 | 12 | * You may obtain a copy of the License at |
ansond | 1:16f0fb5b8d97 | 13 | * |
ansond | 1:16f0fb5b8d97 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 1:16f0fb5b8d97 | 15 | * |
ansond | 1:16f0fb5b8d97 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 1:16f0fb5b8d97 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 1:16f0fb5b8d97 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 1:16f0fb5b8d97 | 19 | * See the License for the specific language governing permissions and |
ansond | 1:16f0fb5b8d97 | 20 | * limitations under the License. |
ansond | 1:16f0fb5b8d97 | 21 | */ |
ansond | 1:16f0fb5b8d97 | 22 | |
ansond | 1:16f0fb5b8d97 | 23 | #ifndef __CONNECTOR_ENDPOINT_H__ |
ansond | 1:16f0fb5b8d97 | 24 | #define __CONNECTOR_ENDPOINT_H__ |
ansond | 1:16f0fb5b8d97 | 25 | |
ansond | 71:5069a202e892 | 26 | // Support for Logging/Debug output |
ansond | 71:5069a202e892 | 27 | #include "mbed-connector-interface/Logger.h" |
ansond | 71:5069a202e892 | 28 | |
ansond | 1:16f0fb5b8d97 | 29 | // mbed-client support |
ansond | 1:16f0fb5b8d97 | 30 | #include "mbed-client/m2minterfacefactory.h" |
ansond | 1:16f0fb5b8d97 | 31 | #include "mbed-client/m2minterfaceobserver.h" |
ansond | 1:16f0fb5b8d97 | 32 | #include "mbed-client/m2minterface.h" |
ansond | 1:16f0fb5b8d97 | 33 | #include "mbed-client/m2mobjectinstance.h" |
ansond | 1:16f0fb5b8d97 | 34 | #include "mbed-client/m2mresource.h" |
ansond | 33:1d0b855df5a5 | 35 | #include "mbed-client/m2mdevice.h" |
ansond | 33:1d0b855df5a5 | 36 | #include "mbed-client/m2mfirmware.h" |
ansond | 1:16f0fb5b8d97 | 37 | |
ansond | 1:16f0fb5b8d97 | 38 | // Options support |
ansond | 1:16f0fb5b8d97 | 39 | #include "mbed-connector-interface/Options.h" |
ansond | 1:16f0fb5b8d97 | 40 | |
ansond | 27:b8aaf7dc7023 | 41 | // ConnectionStatusInterface support |
ansond | 27:b8aaf7dc7023 | 42 | #include "mbed-connector-interface/ConnectionStatusInterface.h" |
ansond | 27:b8aaf7dc7023 | 43 | |
ansond | 27:b8aaf7dc7023 | 44 | // ObjectInstanceManager support |
ansond | 27:b8aaf7dc7023 | 45 | #include "mbed-connector-interface/ObjectInstanceManager.h" |
ansond | 27:b8aaf7dc7023 | 46 | |
ansond | 1:16f0fb5b8d97 | 47 | // Connector namespace |
ansond | 1:16f0fb5b8d97 | 48 | namespace Connector { |
ansond | 1:16f0fb5b8d97 | 49 | |
ansond | 1:16f0fb5b8d97 | 50 | /** Endpoint class |
ansond | 1:16f0fb5b8d97 | 51 | */ |
ansond | 81:a2441163a06e | 52 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 81:a2441163a06e | 53 | class Endpoint : public MbedCloudClientCallback, public M2MInterfaceObserver { |
ansond | 81:a2441163a06e | 54 | #else |
ansond | 1:16f0fb5b8d97 | 55 | class Endpoint : public M2MInterfaceObserver { |
ansond | 81:a2441163a06e | 56 | #endif |
ansond | 1:16f0fb5b8d97 | 57 | |
ansond | 1:16f0fb5b8d97 | 58 | public: |
ansond | 1:16f0fb5b8d97 | 59 | /** |
ansond | 1:16f0fb5b8d97 | 60 | Default Constructor |
ansond | 1:16f0fb5b8d97 | 61 | */ |
ansond | 1:16f0fb5b8d97 | 62 | Endpoint(const Logger *logger,const Options *ob); |
ansond | 1:16f0fb5b8d97 | 63 | |
ansond | 1:16f0fb5b8d97 | 64 | /** |
ansond | 1:16f0fb5b8d97 | 65 | Copy Constructor |
ansond | 1:16f0fb5b8d97 | 66 | @param ob input endpoint instance to deep copy |
ansond | 1:16f0fb5b8d97 | 67 | */ |
ansond | 1:16f0fb5b8d97 | 68 | Endpoint(const Endpoint &ep); |
ansond | 1:16f0fb5b8d97 | 69 | |
ansond | 1:16f0fb5b8d97 | 70 | /** |
ansond | 1:16f0fb5b8d97 | 71 | Destructor |
ansond | 1:16f0fb5b8d97 | 72 | */ |
ansond | 1:16f0fb5b8d97 | 73 | virtual ~Endpoint(); |
ansond | 1:16f0fb5b8d97 | 74 | |
ansond | 1:16f0fb5b8d97 | 75 | /** |
ansond | 8:f950fb1b78c0 | 76 | Build out the endpoint. |
ansond | 1:16f0fb5b8d97 | 77 | */ |
ansond | 46:62da4ce20276 | 78 | void buildEndpoint(); |
ansond | 1:16f0fb5b8d97 | 79 | |
ansond | 1:16f0fb5b8d97 | 80 | /** |
ansond | 1:16f0fb5b8d97 | 81 | Plumb the lower RF network stack |
ansond | 13:9edad7677211 | 82 | @param device_manager input optional device manager (DeviceManager type) |
ansond | 1:16f0fb5b8d97 | 83 | @param canActAsRouterNode input boolean indicating whether this node can act as a router node or not. |
ansond | 1:16f0fb5b8d97 | 84 | */ |
ansond | 13:9edad7677211 | 85 | static void plumbNetwork(void *device_manager = NULL,bool canActAsRouterNode = false); |
ansond | 0:1f1f55e73248 | 86 | |
ansond | 1:16f0fb5b8d97 | 87 | /** |
ansond | 1:16f0fb5b8d97 | 88 | Initialize the endpoint's configuration and begin the endpoint's main even loop |
ansond | 1:16f0fb5b8d97 | 89 | */ |
ansond | 1:16f0fb5b8d97 | 90 | static void start(); |
ansond | 1:16f0fb5b8d97 | 91 | |
ansond | 43:3fb57c4fba34 | 92 | /** |
ansond | 43:3fb57c4fba34 | 93 | Set the ConnectionStatusInterface instance |
ansond | 43:3fb57c4fba34 | 94 | @param csi input instance pointer to the ConnectionStatusInterface implementation to be used |
ansond | 43:3fb57c4fba34 | 95 | */ |
ansond | 43:3fb57c4fba34 | 96 | static void setConnectionStatusInterface(ConnectionStatusInterface *csi); |
ansond | 8:f950fb1b78c0 | 97 | |
ansond | 8:f950fb1b78c0 | 98 | // re-register endpoint |
ansond | 8:f950fb1b78c0 | 99 | void re_register_endpoint(); |
ansond | 8:f950fb1b78c0 | 100 | |
ansond | 8:f950fb1b78c0 | 101 | // de-register endpoint and stop scheduling |
ansond | 8:f950fb1b78c0 | 102 | void de_register_endpoint(void); |
ansond | 76:7f55e1c0635d | 103 | |
ansond | 76:7f55e1c0635d | 104 | // mbed-client : register the endpoint |
ansond | 76:7f55e1c0635d | 105 | void register_endpoint(M2MSecurity *server_instance, M2MObjectList resources); |
ansond | 8:f950fb1b78c0 | 106 | |
ansond | 81:a2441163a06e | 107 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 81:a2441163a06e | 108 | // mbed-cloud-client : object registered |
ansond | 81:a2441163a06e | 109 | static void on_registered(); |
ansond | 81:a2441163a06e | 110 | |
ansond | 81:a2441163a06e | 111 | // mbed-cloud-client : registration updated |
ansond | 81:a2441163a06e | 112 | static void on_registration_updated() ; |
ansond | 81:a2441163a06e | 113 | |
ansond | 81:a2441163a06e | 114 | // mbed-cloud-client : object unregistered |
ansond | 81:a2441163a06e | 115 | static void on_unregistered(); |
ansond | 81:a2441163a06e | 116 | |
ansond | 81:a2441163a06e | 117 | // mbed-cloud-client: error |
ansond | 81:a2441163a06e | 118 | static void on_error(int error_code); |
ansond | 81:a2441163a06e | 119 | #endif |
ansond | 81:a2441163a06e | 120 | |
ansond | 8:f950fb1b78c0 | 121 | // mbed-client : object registered |
ansond | 87:00b3837986c7 | 122 | virtual void object_registered(M2MSecurity *security, const M2MServer &server); |
ansond | 87:00b3837986c7 | 123 | void object_registered(void *security = NULL,void *server = NULL); |
ansond | 1:16f0fb5b8d97 | 124 | |
ansond | 8:f950fb1b78c0 | 125 | // mbed-client : registration updated |
ansond | 87:00b3837986c7 | 126 | virtual void registration_updated(M2MSecurity *security, const M2MServer &server); |
ansond | 87:00b3837986c7 | 127 | void registration_updated(void *security = NULL,void *server = NULL); |
ansond | 1:16f0fb5b8d97 | 128 | |
ansond | 1:16f0fb5b8d97 | 129 | // mbed-client : object unregistered |
ansond | 87:00b3837986c7 | 130 | virtual void object_unregistered(M2MSecurity *security = NULL); |
ansond | 1:16f0fb5b8d97 | 131 | |
ansond | 8:f950fb1b78c0 | 132 | // mbed-client : bootstrap done |
ansond | 87:00b3837986c7 | 133 | virtual void bootstrap_done(M2MSecurity *security = NULL); |
ansond | 1:16f0fb5b8d97 | 134 | |
ansond | 1:16f0fb5b8d97 | 135 | // mbed-client : resource value updated |
ansond | 8:f950fb1b78c0 | 136 | virtual void value_updated(M2MBase *resource, M2MBase::BaseType type) ; |
ansond | 1:16f0fb5b8d97 | 137 | |
ansond | 1:16f0fb5b8d97 | 138 | // mbed-client : error handler |
ansond | 1:16f0fb5b8d97 | 139 | virtual void error(M2MInterface::Error error); |
ansond | 1:16f0fb5b8d97 | 140 | |
ansond | 1:16f0fb5b8d97 | 141 | // get our Options |
ansond | 1:16f0fb5b8d97 | 142 | void setOptions(Options *options); |
ansond | 1:16f0fb5b8d97 | 143 | |
ansond | 1:16f0fb5b8d97 | 144 | // get our Options |
ansond | 1:16f0fb5b8d97 | 145 | Options *getOptions(); |
ansond | 8:f950fb1b78c0 | 146 | |
ansond | 73:f12a767bc300 | 147 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 73:f12a767bc300 | 148 | // get our Endpoint Interface |
ansond | 73:f12a767bc300 | 149 | MbedCloudClient *getEndpointInterface(); |
ansond | 73:f12a767bc300 | 150 | #else |
ansond | 46:62da4ce20276 | 151 | // get our Endpoint Interface |
ansond | 46:62da4ce20276 | 152 | M2MInterface *getEndpointInterface(); |
ansond | 81:a2441163a06e | 153 | #endif |
ansond | 81:a2441163a06e | 154 | |
ansond | 46:62da4ce20276 | 155 | // get our Endpoint Security |
ansond | 81:a2441163a06e | 156 | M2MSecurity *getSecurityInstance(); |
ansond | 46:62da4ce20276 | 157 | |
ansond | 46:62da4ce20276 | 158 | // get our Endpoint Object List |
ansond | 46:62da4ce20276 | 159 | M2MObjectList getEndpointObjectList(); |
ansond | 1:16f0fb5b8d97 | 160 | |
ansond | 1:16f0fb5b8d97 | 161 | // configure to act as router node |
ansond | 1:16f0fb5b8d97 | 162 | void asRouterNode(bool canActAsRouterNode); |
ansond | 13:9edad7677211 | 163 | |
ansond | 13:9edad7677211 | 164 | // access the logger |
ansond | 13:9edad7677211 | 165 | Logger *logger(); |
ansond | 13:9edad7677211 | 166 | |
ansond | 13:9edad7677211 | 167 | // set the device manager |
ansond | 13:9edad7677211 | 168 | void setDeviceManager(void *device_manager); |
ansond | 13:9edad7677211 | 169 | |
ansond | 13:9edad7677211 | 170 | // get the device manager |
ansond | 13:9edad7677211 | 171 | void *getDeviceManager(void); |
ansond | 13:9edad7677211 | 172 | |
ansond | 13:9edad7677211 | 173 | // underlying network is connected (SET) |
ansond | 13:9edad7677211 | 174 | void isConnected(bool connected); |
ansond | 13:9edad7677211 | 175 | |
ansond | 13:9edad7677211 | 176 | // underlying network is connected (GET) |
ansond | 13:9edad7677211 | 177 | bool isConnected(); |
ansond | 15:c11dbe4d354c | 178 | |
ansond | 15:c11dbe4d354c | 179 | // Registered with mDC/mDS |
ansond | 15:c11dbe4d354c | 180 | bool isRegistered(); |
ansond | 27:b8aaf7dc7023 | 181 | |
ansond | 27:b8aaf7dc7023 | 182 | /** |
ansond | 27:b8aaf7dc7023 | 183 | Set the ConnectionStatusInterface instance |
ansond | 27:b8aaf7dc7023 | 184 | @param csi input instance pointer to the ConnectionStatusInterface implementation to be used |
ansond | 27:b8aaf7dc7023 | 185 | */ |
ansond | 43:3fb57c4fba34 | 186 | void setConnectionStatusInterfaceImpl(ConnectionStatusInterface *csi); |
ansond | 1:16f0fb5b8d97 | 187 | |
ansond | 27:b8aaf7dc7023 | 188 | // Set ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 189 | void setObjectInstanceManager(ObjectInstanceManager *oim); |
ansond | 27:b8aaf7dc7023 | 190 | |
ansond | 27:b8aaf7dc7023 | 191 | // Get ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 192 | ObjectInstanceManager *getObjectInstanceManager(); |
ansond | 27:b8aaf7dc7023 | 193 | |
ansond | 1:16f0fb5b8d97 | 194 | private: |
ansond | 44:7c73baf9f4c1 | 195 | Logger *m_logger; |
ansond | 44:7c73baf9f4c1 | 196 | Options *m_options; |
ansond | 44:7c73baf9f4c1 | 197 | bool m_canActAsRouterNode; |
ansond | 44:7c73baf9f4c1 | 198 | bool m_connected; |
ansond | 44:7c73baf9f4c1 | 199 | bool m_registered; |
ansond | 1:16f0fb5b8d97 | 200 | |
ansond | 1:16f0fb5b8d97 | 201 | // mbed-client support |
ansond | 81:a2441163a06e | 202 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 71:5069a202e892 | 203 | MbedCloudClient *m_endpoint_interface; |
ansond | 71:5069a202e892 | 204 | #else |
ansond | 81:a2441163a06e | 205 | M2MInterface *m_endpoint_interface; |
ansond | 71:5069a202e892 | 206 | #endif |
ansond | 81:a2441163a06e | 207 | M2MSecurity *m_endpoint_security; |
ansond | 46:62da4ce20276 | 208 | M2MObjectList m_endpoint_object_list; |
ansond | 13:9edad7677211 | 209 | |
ansond | 13:9edad7677211 | 210 | // Device Manager |
ansond | 44:7c73baf9f4c1 | 211 | void *m_device_manager; |
ansond | 27:b8aaf7dc7023 | 212 | |
ansond | 27:b8aaf7dc7023 | 213 | // ConnectionStatusInterface implementation |
ansond | 27:b8aaf7dc7023 | 214 | ConnectionStatusInterface *m_csi; |
ansond | 27:b8aaf7dc7023 | 215 | |
ansond | 27:b8aaf7dc7023 | 216 | // ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 217 | ObjectInstanceManager *m_oim; |
ansond | 71:5069a202e892 | 218 | |
ansond | 71:5069a202e892 | 219 | // create our endpoint interface |
ansond | 71:5069a202e892 | 220 | void createEndpointInterface(); |
ansond | 44:7c73baf9f4c1 | 221 | |
ansond | 71:5069a202e892 | 222 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 44:7c73baf9f4c1 | 223 | // mbed-client methods |
ansond | 71:5069a202e892 | 224 | void createCloudEndpointInterface(); |
ansond | 71:5069a202e892 | 225 | #else |
ansond | 71:5069a202e892 | 226 | // mbed-client methods |
ansond | 71:5069a202e892 | 227 | void createConnectorEndpointInterface(); |
ansond | 83:8d856fa24fda | 228 | #endif |
ansond | 83:8d856fa24fda | 229 | |
ansond | 83:8d856fa24fda | 230 | // create our endpoint security instance |
ansond | 81:a2441163a06e | 231 | M2MSecurity *createEndpointSecurityInstance(); |
ansond | 44:7c73baf9f4c1 | 232 | |
ansond | 44:7c73baf9f4c1 | 233 | // DynamicResource Lookup |
ansond | 44:7c73baf9f4c1 | 234 | DynamicResource *lookupDynamicResource(M2MBase *base); |
ansond | 54:dfee8691c83a | 235 | |
ansond | 54:dfee8691c83a | 236 | // stop underlying observers |
ansond | 54:dfee8691c83a | 237 | void stopObservations(); |
ansond | 81:a2441163a06e | 238 | |
ansond | 81:a2441163a06e | 239 | // set our endpoint security instance |
ansond | 81:a2441163a06e | 240 | void setSecurityInstance(M2MSecurity *security); |
ansond | 1:16f0fb5b8d97 | 241 | }; |
ansond | 1:16f0fb5b8d97 | 242 | |
ansond | 1:16f0fb5b8d97 | 243 | } // namespace Connector |
ansond | 1:16f0fb5b8d97 | 244 | |
ansond | 1:16f0fb5b8d97 | 245 | #endif // __CONNECTOR_ENDPOINT_H__ |