use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Committer:
ansond
Date:
Tue Jun 14 04:01:34 2016 +0000
Revision:
27:b8aaf7dc7023
Parent:
15:c11dbe4d354c
Child:
33:1d0b855df5a5
Initial merge and update of device and firmware objects

Who changed what in which revision?

UserRevisionLine numberNew 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 1:16f0fb5b8d97 26 // mbed-client support
ansond 1:16f0fb5b8d97 27 #include "mbed-client/m2minterfacefactory.h"
ansond 1:16f0fb5b8d97 28 #include "mbed-client/m2mdevice.h"
ansond 1:16f0fb5b8d97 29 #include "mbed-client/m2minterfaceobserver.h"
ansond 1:16f0fb5b8d97 30 #include "mbed-client/m2minterface.h"
ansond 1:16f0fb5b8d97 31 #include "mbed-client/m2mobjectinstance.h"
ansond 1:16f0fb5b8d97 32 #include "mbed-client/m2mresource.h"
ansond 1:16f0fb5b8d97 33
ansond 1:16f0fb5b8d97 34 // Support for Logging/Debug output
ansond 1:16f0fb5b8d97 35 #include "mbed-connector-interface/Logger.h"
ansond 1:16f0fb5b8d97 36
ansond 1:16f0fb5b8d97 37 // Options support
ansond 1:16f0fb5b8d97 38 #include "mbed-connector-interface/Options.h"
ansond 1:16f0fb5b8d97 39
ansond 27:b8aaf7dc7023 40 // ConnectionStatusInterface support
ansond 27:b8aaf7dc7023 41 #include "mbed-connector-interface/ConnectionStatusInterface.h"
ansond 27:b8aaf7dc7023 42
ansond 27:b8aaf7dc7023 43 // ObjectInstanceManager support
ansond 27:b8aaf7dc7023 44 #include "mbed-connector-interface/ObjectInstanceManager.h"
ansond 27:b8aaf7dc7023 45
ansond 1:16f0fb5b8d97 46 // Connector namespace
ansond 1:16f0fb5b8d97 47 namespace Connector {
ansond 1:16f0fb5b8d97 48
ansond 1:16f0fb5b8d97 49 /** Endpoint class
ansond 1:16f0fb5b8d97 50 */
ansond 1:16f0fb5b8d97 51 class Endpoint : public M2MInterfaceObserver {
ansond 1:16f0fb5b8d97 52
ansond 1:16f0fb5b8d97 53 public:
ansond 1:16f0fb5b8d97 54 /**
ansond 1:16f0fb5b8d97 55 Default Constructor
ansond 1:16f0fb5b8d97 56 */
ansond 1:16f0fb5b8d97 57 Endpoint(const Logger *logger,const Options *ob);
ansond 1:16f0fb5b8d97 58
ansond 1:16f0fb5b8d97 59 /**
ansond 1:16f0fb5b8d97 60 Copy Constructor
ansond 1:16f0fb5b8d97 61 @param ob input endpoint instance to deep copy
ansond 1:16f0fb5b8d97 62 */
ansond 1:16f0fb5b8d97 63 Endpoint(const Endpoint &ep);
ansond 1:16f0fb5b8d97 64
ansond 1:16f0fb5b8d97 65 /**
ansond 1:16f0fb5b8d97 66 Destructor
ansond 1:16f0fb5b8d97 67 */
ansond 1:16f0fb5b8d97 68 virtual ~Endpoint();
ansond 1:16f0fb5b8d97 69
ansond 1:16f0fb5b8d97 70 /**
ansond 8:f950fb1b78c0 71 Build out the endpoint.
ansond 1:16f0fb5b8d97 72 */
ansond 8:f950fb1b78c0 73 void build_endpoint();
ansond 1:16f0fb5b8d97 74
ansond 1:16f0fb5b8d97 75 /**
ansond 1:16f0fb5b8d97 76 Plumb the lower RF network stack
ansond 13:9edad7677211 77 @param device_manager input optional device manager (DeviceManager type)
ansond 1:16f0fb5b8d97 78 @param canActAsRouterNode input boolean indicating whether this node can act as a router node or not.
ansond 1:16f0fb5b8d97 79 */
ansond 13:9edad7677211 80 static void plumbNetwork(void *device_manager = NULL,bool canActAsRouterNode = false);
ansond 0:1f1f55e73248 81
ansond 1:16f0fb5b8d97 82 /**
ansond 1:16f0fb5b8d97 83 Initialize the endpoint's configuration and begin the endpoint's main even loop
ansond 1:16f0fb5b8d97 84 */
ansond 1:16f0fb5b8d97 85 static void start();
ansond 1:16f0fb5b8d97 86
ansond 8:f950fb1b78c0 87 // register the endpoint
ansond 8:f950fb1b78c0 88 void register_endpoint(M2MSecurity *server_instance, M2MObjectList resources);
ansond 8:f950fb1b78c0 89
ansond 8:f950fb1b78c0 90 // re-register endpoint
ansond 8:f950fb1b78c0 91 void re_register_endpoint();
ansond 8:f950fb1b78c0 92
ansond 8:f950fb1b78c0 93 // de-register endpoint and stop scheduling
ansond 8:f950fb1b78c0 94 void de_register_endpoint(void);
ansond 8:f950fb1b78c0 95
ansond 8:f950fb1b78c0 96 // mbed-client : object registered
ansond 8:f950fb1b78c0 97 virtual void object_registered(M2MSecurity *server_instance, const M2MServer &server);
ansond 1:16f0fb5b8d97 98
ansond 8:f950fb1b78c0 99 // mbed-client : registration updated
ansond 8:f950fb1b78c0 100 virtual void registration_updated(M2MSecurity *server_instance, const M2MServer &server) ;
ansond 1:16f0fb5b8d97 101
ansond 1:16f0fb5b8d97 102 // mbed-client : object unregistered
ansond 8:f950fb1b78c0 103 virtual void object_unregistered(M2MSecurity *server_instance);
ansond 1:16f0fb5b8d97 104
ansond 8:f950fb1b78c0 105 // mbed-client : bootstrap done
ansond 8:f950fb1b78c0 106 virtual void bootstrap_done(M2MSecurity *server_instance);
ansond 1:16f0fb5b8d97 107
ansond 1:16f0fb5b8d97 108 // mbed-client : resource value updated
ansond 8:f950fb1b78c0 109 virtual void value_updated(M2MBase *resource, M2MBase::BaseType type) ;
ansond 1:16f0fb5b8d97 110
ansond 1:16f0fb5b8d97 111 // mbed-client : error handler
ansond 1:16f0fb5b8d97 112 virtual void error(M2MInterface::Error error);
ansond 1:16f0fb5b8d97 113
ansond 1:16f0fb5b8d97 114 // get our Options
ansond 1:16f0fb5b8d97 115 void setOptions(Options *options);
ansond 1:16f0fb5b8d97 116
ansond 1:16f0fb5b8d97 117 // get our Options
ansond 1:16f0fb5b8d97 118 Options *getOptions();
ansond 8:f950fb1b78c0 119
ansond 1:16f0fb5b8d97 120 // get our Server
ansond 1:16f0fb5b8d97 121 M2MSecurity *getServer();
ansond 1:16f0fb5b8d97 122
ansond 1:16f0fb5b8d97 123 // get our Object List
ansond 1:16f0fb5b8d97 124 M2MObjectList getObjectList();
ansond 1:16f0fb5b8d97 125
ansond 1:16f0fb5b8d97 126 // configure to act as router node
ansond 1:16f0fb5b8d97 127 void asRouterNode(bool canActAsRouterNode);
ansond 13:9edad7677211 128
ansond 13:9edad7677211 129 // access the logger
ansond 13:9edad7677211 130 Logger *logger();
ansond 13:9edad7677211 131
ansond 13:9edad7677211 132 // set the device manager
ansond 13:9edad7677211 133 void setDeviceManager(void *device_manager);
ansond 13:9edad7677211 134
ansond 13:9edad7677211 135 // get the device manager
ansond 13:9edad7677211 136 void *getDeviceManager(void);
ansond 13:9edad7677211 137
ansond 13:9edad7677211 138 // underlying network is connected (SET)
ansond 13:9edad7677211 139 void isConnected(bool connected);
ansond 13:9edad7677211 140
ansond 13:9edad7677211 141 // underlying network is connected (GET)
ansond 13:9edad7677211 142 bool isConnected();
ansond 15:c11dbe4d354c 143
ansond 15:c11dbe4d354c 144 // Registered with mDC/mDS
ansond 15:c11dbe4d354c 145 bool isRegistered();
ansond 27:b8aaf7dc7023 146
ansond 27:b8aaf7dc7023 147 /**
ansond 27:b8aaf7dc7023 148 Set the ConnectionStatusInterface instance
ansond 27:b8aaf7dc7023 149 @param csi input instance pointer to the ConnectionStatusInterface implementation to be used
ansond 27:b8aaf7dc7023 150 */
ansond 27:b8aaf7dc7023 151 static void setConnectionStatusInterfaceImpl(ConnectionStatusInterface *csi);
ansond 1:16f0fb5b8d97 152
ansond 27:b8aaf7dc7023 153 // Set ObjectInstanceManager
ansond 27:b8aaf7dc7023 154 void setObjectInstanceManager(ObjectInstanceManager *oim);
ansond 27:b8aaf7dc7023 155
ansond 27:b8aaf7dc7023 156 // Get ObjectInstanceManager
ansond 27:b8aaf7dc7023 157 ObjectInstanceManager *getObjectInstanceManager();
ansond 27:b8aaf7dc7023 158
ansond 1:16f0fb5b8d97 159 private:
ansond 1:16f0fb5b8d97 160 Logger *m_logger;
ansond 1:16f0fb5b8d97 161 Options *m_options;
ansond 1:16f0fb5b8d97 162 bool m_canActAsRouterNode;
ansond 13:9edad7677211 163 bool m_connected;
ansond 15:c11dbe4d354c 164 bool m_registered;
ansond 1:16f0fb5b8d97 165
ansond 1:16f0fb5b8d97 166 // mbed-client support
ansond 15:c11dbe4d354c 167 M2MInterface *m_interface;
ansond 15:c11dbe4d354c 168 M2MSecurity *m_server_instance;
ansond 15:c11dbe4d354c 169 M2MObjectList m_object_list;
ansond 15:c11dbe4d354c 170 M2MDevice *m_device_object;
ansond 1:16f0fb5b8d97 171
ansond 1:16f0fb5b8d97 172 // mbed-client methods
ansond 1:16f0fb5b8d97 173 void create_interface();
ansond 1:16f0fb5b8d97 174 M2MSecurity *create_server_instance();
ansond 13:9edad7677211 175
ansond 13:9edad7677211 176 // Device Manager
ansond 27:b8aaf7dc7023 177 void *m_device_manager;
ansond 1:16f0fb5b8d97 178
ansond 1:16f0fb5b8d97 179 // DynamicResource Lookup
ansond 1:16f0fb5b8d97 180 DynamicResource *lookupDynamicResource(M2MBase *base);
ansond 27:b8aaf7dc7023 181
ansond 27:b8aaf7dc7023 182 // ConnectionStatusInterface implementation
ansond 27:b8aaf7dc7023 183 ConnectionStatusInterface *m_csi;
ansond 27:b8aaf7dc7023 184
ansond 27:b8aaf7dc7023 185 // ObjectInstanceManager
ansond 27:b8aaf7dc7023 186 ObjectInstanceManager *m_oim;
ansond 1:16f0fb5b8d97 187 };
ansond 1:16f0fb5b8d97 188
ansond 1:16f0fb5b8d97 189 } // namespace Connector
ansond 1:16f0fb5b8d97 190
ansond 1:16f0fb5b8d97 191 #endif // __CONNECTOR_ENDPOINT_H__