Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
m2minterfacefactory.cpp
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 // Note: this macro is needed on armcc to get the the PRI*32 macros 00018 // from inttypes.h in a C++ code. 00019 #ifndef __STDC_FORMAT_MACROS 00020 #define __STDC_FORMAT_MACROS 00021 #endif 00022 00023 #include "mbed-client/m2minterfacefactory.h" 00024 #include "mbed-client/m2mserver.h" 00025 #include "mbed-client/m2mdevice.h" 00026 #include "mbed-client/m2mfirmware.h" 00027 #include "mbed-client/m2mobject.h" 00028 #include "mbed-client/m2mconstants.h" 00029 #include "mbed-client/m2mconfig.h" 00030 #include "include/m2minterfaceimpl.h" 00031 #include "mbed-trace/mbed_trace.h" 00032 00033 #include <inttypes.h> 00034 00035 #define TRACE_GROUP "mClt" 00036 00037 M2MInterface* M2MInterfaceFactory::create_interface(M2MInterfaceObserver &observer, 00038 const String &endpoint_name, 00039 const String &endpoint_type, 00040 const int32_t life_time, 00041 const uint16_t listen_port, 00042 const String &domain, 00043 M2MInterface::BindingMode mode, 00044 M2MInterface::NetworkStack stack, 00045 const String &context_address) 00046 { 00047 tr_debug("M2MInterfaceFactory::create_interface - IN"); 00048 tr_info("M2MInterfaceFactory::create_interface - parameters endpoint name : %s",endpoint_name.c_str()); 00049 tr_info("M2MInterfaceFactory::create_interface - parameters endpoint type : %s",endpoint_type.c_str()); 00050 tr_info("M2MInterfaceFactory::create_interface - parameters life time(in secs): %" PRId32,life_time); 00051 tr_info("M2MInterfaceFactory::create_interface - parameters Listen Port : %d",listen_port); 00052 tr_info("M2MInterfaceFactory::create_interface - parameters Binding Mode : %d",(int)mode); 00053 tr_info("M2MInterfaceFactory::create_interface - parameters NetworkStack : %d",(int)stack); 00054 M2MInterfaceImpl *interface = NULL; 00055 00056 00057 bool endpoint_type_valid = true; 00058 if(!endpoint_type.empty()) { 00059 if(endpoint_type.size() > MAX_ALLOWED_STRING_LENGTH){ 00060 endpoint_type_valid = false; 00061 } 00062 } 00063 00064 bool domain_valid = true; 00065 if(!domain.empty()) { 00066 if(domain.size() > MAX_ALLOWED_STRING_LENGTH){ 00067 domain_valid = false; 00068 } 00069 } 00070 00071 if(((life_time == -1) || (life_time >= MINIMUM_REGISTRATION_TIME)) && 00072 !endpoint_name.empty() && (endpoint_name.size() <= MAX_ALLOWED_STRING_LENGTH) && 00073 endpoint_type_valid && domain_valid) { 00074 tr_debug("M2MInterfaceFactory::create_interface - Creating M2MInterfaceImpl"); 00075 interface = new M2MInterfaceImpl(observer, endpoint_name, 00076 endpoint_type, life_time, 00077 listen_port, domain, mode, 00078 stack, context_address); 00079 00080 } 00081 tr_debug("M2MInterfaceFactory::create_interface - OUT"); 00082 return interface; 00083 } 00084 00085 M2MSecurity* M2MInterfaceFactory::create_security(M2MSecurity::ServerType server_type) 00086 { 00087 tr_debug("M2MInterfaceFactory::create_security"); 00088 M2MSecurity *security = M2MSecurity::get_instance(); 00089 return security; 00090 } 00091 00092 M2MServer* M2MInterfaceFactory::create_server() 00093 { 00094 tr_debug("M2MInterfaceFactory::create_server"); 00095 M2MServer *server = new M2MServer(); 00096 return server; 00097 } 00098 00099 M2MDevice* M2MInterfaceFactory::create_device() 00100 { 00101 tr_debug("M2MInterfaceFactory::create_device"); 00102 M2MDevice* device = M2MDevice::get_instance(); 00103 return device; 00104 } 00105 00106 M2MFirmware* M2MInterfaceFactory::create_firmware() 00107 { 00108 tr_debug("M2MInterfaceFactory::create_firmware"); 00109 M2MFirmware* firmware = M2MFirmware::get_instance(); 00110 return firmware; 00111 } 00112 00113 M2MObject* M2MInterfaceFactory::create_object(const String &name) 00114 { 00115 tr_debug("M2MInterfaceFactory::create_object : Name : %s", name.c_str()); 00116 if(name.size() > MAX_ALLOWED_STRING_LENGTH || name.empty()){ 00117 return NULL; 00118 } 00119 00120 M2MObject *object = NULL; 00121 char *name_copy = M2MBase::stringdup(name.c_str()); 00122 if (name_copy) { 00123 object = new M2MObject(name, name_copy); 00124 } 00125 return object; 00126 }
Generated on Tue Jul 12 2022 19:01:35 by 1.7.2