Maggie Mei / mbedConnectorInterfaceWithDM

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ConnectorEndpoint.h Source File

ConnectorEndpoint.h

00001 /**
00002  * @file    Endpoint.h
00003  * @brief   mbed CoAP Endpoint base class
00004  * @author  Doug Anson/Chris Paola
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022 
00023 #ifndef __CONNECTOR_ENDPOINT_H__
00024 #define __CONNECTOR_ENDPOINT_H__
00025 
00026 // Support for Logging/Debug output
00027 #include "mbed-connector-interface/Logger.h"
00028 
00029 // mbed-client support
00030 #include "mbed-client/m2minterfacefactory.h"
00031 #include "mbed-client/m2minterfaceobserver.h"
00032 #include "mbed-client/m2minterface.h"
00033 #include "mbed-client/m2mobjectinstance.h"
00034 #include "mbed-client/m2mresource.h"
00035 #include "mbed-client/m2mdevice.h"
00036 #include "mbed-client/m2mfirmware.h"
00037 
00038 // Options support
00039 #include "mbed-connector-interface/Options.h"
00040 
00041 // ConnectionStatusInterface support
00042 #include "mbed-connector-interface/ConnectionStatusInterface.h"
00043 
00044 // ObjectInstanceManager support
00045 #include "mbed-connector-interface/ObjectInstanceManager.h"
00046 
00047 // Connector namespace
00048 namespace Connector  {
00049 
00050 /** Endpoint class
00051  */
00052 #ifdef ENABLE_MBED_CLOUD_SUPPORT
00053 class Endpoint : public MbedCloudClientCallback, public M2MInterfaceObserver  {
00054 #else
00055 class Endpoint : public M2MInterfaceObserver  {
00056 #endif
00057 
00058 public:
00059     /**
00060     Default Constructor
00061     */
00062     Endpoint(const Logger *logger,const Options *ob);
00063 
00064     /**
00065     Copy Constructor
00066     @param ob input endpoint instance to deep copy
00067     */
00068     Endpoint(const Endpoint &ep);
00069 
00070     /**
00071     Destructor
00072     */
00073     virtual ~Endpoint();
00074 
00075     /**
00076     Build out the endpoint.
00077     */
00078     void buildEndpoint();
00079 
00080     /**
00081     Plumb the lower RF network stack
00082     @param device_manager input optional device manager (DeviceManager type)
00083     @param canActAsRouterNode input boolean indicating whether this node can act as a router node or not.
00084     */
00085     static void plumbNetwork(void *device_manager = NULL,bool canActAsRouterNode = false);
00086 
00087     /**
00088     Initialize the endpoint's configuration and begin the endpoint's main even loop
00089     */
00090     static void start();
00091     
00092     /**
00093     Set the ConnectionStatusInterface instance
00094     @param csi input instance pointer to the ConnectionStatusInterface implementation to be used
00095     */
00096     static void setConnectionStatusInterface(ConnectionStatusInterface *csi);
00097     
00098     // re-register endpoint
00099     void re_register_endpoint();
00100     
00101     // de-register endpoint and stop scheduling
00102     void de_register_endpoint(void);
00103     
00104     // mbed-client : register the endpoint
00105     void register_endpoint(M2MSecurity *server_instance, M2MObjectList resources);
00106     
00107 #ifdef ENABLE_MBED_CLOUD_SUPPORT
00108     //  mbed-cloud-client : object registered
00109     static void on_registered();
00110 
00111     //  mbed-cloud-client : registration updated
00112     static void on_registration_updated() ;
00113 
00114     //  mbed-cloud-client : object unregistered
00115     static void on_unregistered();
00116     
00117     // mbed-cloud-client: error
00118     static void on_error(int error_code);
00119 #endif
00120 
00121     //  mbed-client : object registered
00122     virtual void object_registered(M2MSecurity *security, const M2MServer &server);
00123     void object_registered(void *security = NULL,void *server = NULL);
00124 
00125     //  mbed-client : registration updated
00126     virtual void registration_updated(M2MSecurity *security, const M2MServer &server);
00127     void registration_updated(void *security = NULL,void *server = NULL);
00128 
00129     //  mbed-client : object unregistered
00130     virtual void object_unregistered(M2MSecurity *security = NULL);
00131 
00132     //  mbed-client : bootstrap done
00133     virtual void bootstrap_done(M2MSecurity *security = NULL);
00134 
00135     //  mbed-client : resource value updated
00136     virtual void value_updated(M2MBase *resource, M2MBase::BaseType type) ;
00137     
00138     //  mbed-client : error handler
00139     virtual void error(M2MInterface::Error error);
00140     
00141     // get our Options
00142     void setOptions(Options *options);
00143     
00144     // get our Options
00145     Options *getOptions();
00146     
00147 #ifdef ENABLE_MBED_CLOUD_SUPPORT 
00148     // get our Endpoint Interface
00149     MbedCloudClient *getEndpointInterface();
00150 #else   
00151     // get our Endpoint Interface
00152     M2MInterface *getEndpointInterface();
00153 #endif
00154 
00155     // get our Endpoint Security
00156     M2MSecurity *getSecurityInstance();
00157     
00158     // get our Endpoint Object List
00159     M2MObjectList  getEndpointObjectList();
00160     
00161     // configure to act as router node
00162     void asRouterNode(bool canActAsRouterNode);
00163     
00164     // access the logger
00165     Logger *logger();
00166     
00167     // set the device manager
00168     void setDeviceManager(void *device_manager);
00169     
00170     // get the device manager
00171     void *getDeviceManager(void);
00172     
00173     // underlying network is connected (SET)
00174     void isConnected(bool connected); 
00175     
00176     // underlying network is connected (GET)
00177     bool isConnected();
00178     
00179     // Registered with mDC/mDS
00180     bool isRegistered();
00181     
00182     /**
00183     Set the ConnectionStatusInterface instance
00184     @param csi input instance pointer to the ConnectionStatusInterface implementation to be used
00185     */
00186     void setConnectionStatusInterfaceImpl(ConnectionStatusInterface *csi); 
00187 
00188     // Set ObjectInstanceManager
00189     void setObjectInstanceManager(ObjectInstanceManager *oim);
00190     
00191     // Get ObjectInstanceManager
00192     ObjectInstanceManager *getObjectInstanceManager();
00193     
00194 private:
00195     Logger                      *m_logger;
00196     Options                     *m_options;
00197     bool                         m_canActAsRouterNode;
00198     bool                         m_connected;
00199     bool                         m_registered;
00200     
00201     // mbed-client support
00202 #ifdef ENABLE_MBED_CLOUD_SUPPORT 
00203     MbedCloudClient             *m_endpoint_interface;
00204 #else
00205     M2MInterface                *m_endpoint_interface;
00206 #endif
00207     M2MSecurity                 *m_endpoint_security;
00208     M2MObjectList                m_endpoint_object_list;
00209     
00210     // Device Manager
00211     void                        *m_device_manager;
00212     
00213     // ConnectionStatusInterface implementation
00214     ConnectionStatusInterface   *m_csi;
00215     
00216     // ObjectInstanceManager
00217     ObjectInstanceManager       *m_oim;
00218 
00219     // create our endpoint interface
00220     void             createEndpointInterface();
00221     
00222 #ifdef ENABLE_MBED_CLOUD_SUPPORT
00223     // mbed-client methods
00224     void             createCloudEndpointInterface();
00225 #else
00226     // mbed-client methods
00227     void             createConnectorEndpointInterface();
00228 #endif
00229     
00230     // create our endpoint security instance
00231     M2MSecurity     *createEndpointSecurityInstance();
00232     
00233     // DynamicResource Lookup
00234     DynamicResource *lookupDynamicResource(M2MBase *base);
00235     
00236     // stop underlying observers
00237     void stopObservations();
00238     
00239     // set our endpoint security instance
00240     void setSecurityInstance(M2MSecurity *security);
00241 };
00242 
00243 } // namespace Connector
00244 
00245 #endif // __CONNECTOR_ENDPOINT_H__