use TCP to connect to mbed connector
Fork of mbedConnectorInterfaceWithDM by
mbed-connector-interface/ConnectorEndpoint.h@77:cee832ba6dd0, 2016-11-04 (annotated)
- Committer:
- ansond
- Date:
- Fri Nov 04 22:32:30 2016 +0000
- Revision:
- 77:cee832ba6dd0
- Parent:
- 76:7f55e1c0635d
- Child:
- 81:a2441163a06e
updates
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 | 1:16f0fb5b8d97 | 52 | class Endpoint : public M2MInterfaceObserver { |
ansond | 1:16f0fb5b8d97 | 53 | |
ansond | 1:16f0fb5b8d97 | 54 | public: |
ansond | 1:16f0fb5b8d97 | 55 | /** |
ansond | 1:16f0fb5b8d97 | 56 | Default Constructor |
ansond | 1:16f0fb5b8d97 | 57 | */ |
ansond | 1:16f0fb5b8d97 | 58 | Endpoint(const Logger *logger,const Options *ob); |
ansond | 1:16f0fb5b8d97 | 59 | |
ansond | 1:16f0fb5b8d97 | 60 | /** |
ansond | 1:16f0fb5b8d97 | 61 | Copy Constructor |
ansond | 1:16f0fb5b8d97 | 62 | @param ob input endpoint instance to deep copy |
ansond | 1:16f0fb5b8d97 | 63 | */ |
ansond | 1:16f0fb5b8d97 | 64 | Endpoint(const Endpoint &ep); |
ansond | 1:16f0fb5b8d97 | 65 | |
ansond | 1:16f0fb5b8d97 | 66 | /** |
ansond | 1:16f0fb5b8d97 | 67 | Destructor |
ansond | 1:16f0fb5b8d97 | 68 | */ |
ansond | 1:16f0fb5b8d97 | 69 | virtual ~Endpoint(); |
ansond | 1:16f0fb5b8d97 | 70 | |
ansond | 1:16f0fb5b8d97 | 71 | /** |
ansond | 8:f950fb1b78c0 | 72 | Build out the endpoint. |
ansond | 1:16f0fb5b8d97 | 73 | */ |
ansond | 46:62da4ce20276 | 74 | void buildEndpoint(); |
ansond | 1:16f0fb5b8d97 | 75 | |
ansond | 1:16f0fb5b8d97 | 76 | /** |
ansond | 1:16f0fb5b8d97 | 77 | Plumb the lower RF network stack |
ansond | 13:9edad7677211 | 78 | @param device_manager input optional device manager (DeviceManager type) |
ansond | 1:16f0fb5b8d97 | 79 | @param canActAsRouterNode input boolean indicating whether this node can act as a router node or not. |
ansond | 1:16f0fb5b8d97 | 80 | */ |
ansond | 13:9edad7677211 | 81 | static void plumbNetwork(void *device_manager = NULL,bool canActAsRouterNode = false); |
ansond | 0:1f1f55e73248 | 82 | |
ansond | 1:16f0fb5b8d97 | 83 | /** |
ansond | 1:16f0fb5b8d97 | 84 | Initialize the endpoint's configuration and begin the endpoint's main even loop |
ansond | 1:16f0fb5b8d97 | 85 | */ |
ansond | 1:16f0fb5b8d97 | 86 | static void start(); |
ansond | 1:16f0fb5b8d97 | 87 | |
ansond | 43:3fb57c4fba34 | 88 | /** |
ansond | 43:3fb57c4fba34 | 89 | Set the ConnectionStatusInterface instance |
ansond | 43:3fb57c4fba34 | 90 | @param csi input instance pointer to the ConnectionStatusInterface implementation to be used |
ansond | 43:3fb57c4fba34 | 91 | */ |
ansond | 43:3fb57c4fba34 | 92 | static void setConnectionStatusInterface(ConnectionStatusInterface *csi); |
ansond | 8:f950fb1b78c0 | 93 | |
ansond | 8:f950fb1b78c0 | 94 | // re-register endpoint |
ansond | 8:f950fb1b78c0 | 95 | void re_register_endpoint(); |
ansond | 8:f950fb1b78c0 | 96 | |
ansond | 8:f950fb1b78c0 | 97 | // de-register endpoint and stop scheduling |
ansond | 8:f950fb1b78c0 | 98 | void de_register_endpoint(void); |
ansond | 76:7f55e1c0635d | 99 | |
ansond | 76:7f55e1c0635d | 100 | // mbed-client : register the endpoint |
ansond | 76:7f55e1c0635d | 101 | void register_endpoint(M2MSecurity *server_instance, M2MObjectList resources); |
ansond | 8:f950fb1b78c0 | 102 | |
ansond | 8:f950fb1b78c0 | 103 | // mbed-client : object registered |
ansond | 8:f950fb1b78c0 | 104 | virtual void object_registered(M2MSecurity *server_instance, const M2MServer &server); |
ansond | 1:16f0fb5b8d97 | 105 | |
ansond | 8:f950fb1b78c0 | 106 | // mbed-client : registration updated |
ansond | 8:f950fb1b78c0 | 107 | virtual void registration_updated(M2MSecurity *server_instance, const M2MServer &server) ; |
ansond | 1:16f0fb5b8d97 | 108 | |
ansond | 1:16f0fb5b8d97 | 109 | // mbed-client : object unregistered |
ansond | 8:f950fb1b78c0 | 110 | virtual void object_unregistered(M2MSecurity *server_instance); |
ansond | 1:16f0fb5b8d97 | 111 | |
ansond | 8:f950fb1b78c0 | 112 | // mbed-client : bootstrap done |
ansond | 8:f950fb1b78c0 | 113 | virtual void bootstrap_done(M2MSecurity *server_instance); |
ansond | 1:16f0fb5b8d97 | 114 | |
ansond | 1:16f0fb5b8d97 | 115 | // mbed-client : resource value updated |
ansond | 8:f950fb1b78c0 | 116 | virtual void value_updated(M2MBase *resource, M2MBase::BaseType type) ; |
ansond | 1:16f0fb5b8d97 | 117 | |
ansond | 1:16f0fb5b8d97 | 118 | // mbed-client : error handler |
ansond | 1:16f0fb5b8d97 | 119 | virtual void error(M2MInterface::Error error); |
ansond | 1:16f0fb5b8d97 | 120 | |
ansond | 1:16f0fb5b8d97 | 121 | // get our Options |
ansond | 1:16f0fb5b8d97 | 122 | void setOptions(Options *options); |
ansond | 1:16f0fb5b8d97 | 123 | |
ansond | 1:16f0fb5b8d97 | 124 | // get our Options |
ansond | 1:16f0fb5b8d97 | 125 | Options *getOptions(); |
ansond | 8:f950fb1b78c0 | 126 | |
ansond | 73:f12a767bc300 | 127 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 73:f12a767bc300 | 128 | // get our Endpoint Interface |
ansond | 73:f12a767bc300 | 129 | MbedCloudClient *getEndpointInterface(); |
ansond | 73:f12a767bc300 | 130 | #else |
ansond | 46:62da4ce20276 | 131 | // get our Endpoint Interface |
ansond | 46:62da4ce20276 | 132 | M2MInterface *getEndpointInterface(); |
ansond | 1:16f0fb5b8d97 | 133 | |
ansond | 46:62da4ce20276 | 134 | // get our Endpoint Security |
ansond | 46:62da4ce20276 | 135 | M2MSecurity *getEndpointSecurity(); |
ansond | 73:f12a767bc300 | 136 | #endif |
ansond | 46:62da4ce20276 | 137 | |
ansond | 46:62da4ce20276 | 138 | // get our Endpoint Object List |
ansond | 46:62da4ce20276 | 139 | M2MObjectList getEndpointObjectList(); |
ansond | 1:16f0fb5b8d97 | 140 | |
ansond | 1:16f0fb5b8d97 | 141 | // configure to act as router node |
ansond | 1:16f0fb5b8d97 | 142 | void asRouterNode(bool canActAsRouterNode); |
ansond | 13:9edad7677211 | 143 | |
ansond | 13:9edad7677211 | 144 | // access the logger |
ansond | 13:9edad7677211 | 145 | Logger *logger(); |
ansond | 13:9edad7677211 | 146 | |
ansond | 13:9edad7677211 | 147 | // set the device manager |
ansond | 13:9edad7677211 | 148 | void setDeviceManager(void *device_manager); |
ansond | 13:9edad7677211 | 149 | |
ansond | 13:9edad7677211 | 150 | // get the device manager |
ansond | 13:9edad7677211 | 151 | void *getDeviceManager(void); |
ansond | 13:9edad7677211 | 152 | |
ansond | 13:9edad7677211 | 153 | // underlying network is connected (SET) |
ansond | 13:9edad7677211 | 154 | void isConnected(bool connected); |
ansond | 13:9edad7677211 | 155 | |
ansond | 13:9edad7677211 | 156 | // underlying network is connected (GET) |
ansond | 13:9edad7677211 | 157 | bool isConnected(); |
ansond | 15:c11dbe4d354c | 158 | |
ansond | 15:c11dbe4d354c | 159 | // Registered with mDC/mDS |
ansond | 15:c11dbe4d354c | 160 | bool isRegistered(); |
ansond | 27:b8aaf7dc7023 | 161 | |
ansond | 27:b8aaf7dc7023 | 162 | /** |
ansond | 27:b8aaf7dc7023 | 163 | Set the ConnectionStatusInterface instance |
ansond | 27:b8aaf7dc7023 | 164 | @param csi input instance pointer to the ConnectionStatusInterface implementation to be used |
ansond | 27:b8aaf7dc7023 | 165 | */ |
ansond | 43:3fb57c4fba34 | 166 | void setConnectionStatusInterfaceImpl(ConnectionStatusInterface *csi); |
ansond | 1:16f0fb5b8d97 | 167 | |
ansond | 27:b8aaf7dc7023 | 168 | // Set ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 169 | void setObjectInstanceManager(ObjectInstanceManager *oim); |
ansond | 27:b8aaf7dc7023 | 170 | |
ansond | 27:b8aaf7dc7023 | 171 | // Get ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 172 | ObjectInstanceManager *getObjectInstanceManager(); |
ansond | 27:b8aaf7dc7023 | 173 | |
ansond | 1:16f0fb5b8d97 | 174 | private: |
ansond | 44:7c73baf9f4c1 | 175 | Logger *m_logger; |
ansond | 44:7c73baf9f4c1 | 176 | Options *m_options; |
ansond | 44:7c73baf9f4c1 | 177 | bool m_canActAsRouterNode; |
ansond | 44:7c73baf9f4c1 | 178 | bool m_connected; |
ansond | 44:7c73baf9f4c1 | 179 | bool m_registered; |
ansond | 1:16f0fb5b8d97 | 180 | |
ansond | 1:16f0fb5b8d97 | 181 | // mbed-client support |
ansond | 71:5069a202e892 | 182 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 71:5069a202e892 | 183 | MbedCloudClient *m_endpoint_interface; |
ansond | 71:5069a202e892 | 184 | #else |
ansond | 46:62da4ce20276 | 185 | M2MInterface *m_endpoint_interface; |
ansond | 46:62da4ce20276 | 186 | M2MSecurity *m_endpoint_security; |
ansond | 71:5069a202e892 | 187 | #endif |
ansond | 46:62da4ce20276 | 188 | M2MObjectList m_endpoint_object_list; |
ansond | 13:9edad7677211 | 189 | |
ansond | 13:9edad7677211 | 190 | // Device Manager |
ansond | 44:7c73baf9f4c1 | 191 | void *m_device_manager; |
ansond | 27:b8aaf7dc7023 | 192 | |
ansond | 27:b8aaf7dc7023 | 193 | // ConnectionStatusInterface implementation |
ansond | 27:b8aaf7dc7023 | 194 | ConnectionStatusInterface *m_csi; |
ansond | 27:b8aaf7dc7023 | 195 | |
ansond | 27:b8aaf7dc7023 | 196 | // ObjectInstanceManager |
ansond | 27:b8aaf7dc7023 | 197 | ObjectInstanceManager *m_oim; |
ansond | 71:5069a202e892 | 198 | |
ansond | 71:5069a202e892 | 199 | // create our endpoint interface |
ansond | 71:5069a202e892 | 200 | void createEndpointInterface(); |
ansond | 44:7c73baf9f4c1 | 201 | |
ansond | 71:5069a202e892 | 202 | #ifdef ENABLE_MBED_CLOUD_SUPPORT |
ansond | 44:7c73baf9f4c1 | 203 | // mbed-client methods |
ansond | 71:5069a202e892 | 204 | void createCloudEndpointInterface(); |
ansond | 71:5069a202e892 | 205 | #else |
ansond | 71:5069a202e892 | 206 | // mbed-client methods |
ansond | 71:5069a202e892 | 207 | void createConnectorEndpointInterface(); |
ansond | 46:62da4ce20276 | 208 | M2MSecurity *createEndpointInstance(); |
ansond | 71:5069a202e892 | 209 | #endif |
ansond | 44:7c73baf9f4c1 | 210 | |
ansond | 44:7c73baf9f4c1 | 211 | // DynamicResource Lookup |
ansond | 44:7c73baf9f4c1 | 212 | DynamicResource *lookupDynamicResource(M2MBase *base); |
ansond | 54:dfee8691c83a | 213 | |
ansond | 54:dfee8691c83a | 214 | // stop underlying observers |
ansond | 54:dfee8691c83a | 215 | void stopObservations(); |
ansond | 1:16f0fb5b8d97 | 216 | }; |
ansond | 1:16f0fb5b8d97 | 217 | |
ansond | 1:16f0fb5b8d97 | 218 | } // namespace Connector |
ansond | 1:16f0fb5b8d97 | 219 | |
ansond | 1:16f0fb5b8d97 | 220 | #endif // __CONNECTOR_ENDPOINT_H__ |