FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16
ram54288 0:dbad57390bd1 17 // Note: this macro is needed on armcc to get the the PRI*32 macros
ram54288 0:dbad57390bd1 18 // from inttypes.h in a C++ code.
ram54288 0:dbad57390bd1 19 #ifndef __STDC_FORMAT_MACROS
ram54288 0:dbad57390bd1 20 #define __STDC_FORMAT_MACROS
ram54288 0:dbad57390bd1 21 #endif
ram54288 0:dbad57390bd1 22
ram54288 0:dbad57390bd1 23 #include "mbed-client/m2minterfacefactory.h"
ram54288 0:dbad57390bd1 24 #include "mbed-client/m2mserver.h"
ram54288 0:dbad57390bd1 25 #include "mbed-client/m2mdevice.h"
ram54288 0:dbad57390bd1 26 #include "mbed-client/m2mfirmware.h"
ram54288 0:dbad57390bd1 27 #include "mbed-client/m2mobject.h"
ram54288 0:dbad57390bd1 28 #include "mbed-client/m2mconstants.h"
ram54288 0:dbad57390bd1 29 #include "mbed-client/m2mconfig.h"
ram54288 0:dbad57390bd1 30 #include "include/m2minterfaceimpl.h"
ram54288 0:dbad57390bd1 31 #include "mbed-trace/mbed_trace.h"
ram54288 0:dbad57390bd1 32
ram54288 0:dbad57390bd1 33 #include <inttypes.h>
ram54288 0:dbad57390bd1 34
ram54288 0:dbad57390bd1 35 #define TRACE_GROUP "mClt"
ram54288 0:dbad57390bd1 36
ram54288 0:dbad57390bd1 37 M2MInterface* M2MInterfaceFactory::create_interface(M2MInterfaceObserver &observer,
ram54288 0:dbad57390bd1 38 const String &endpoint_name,
ram54288 0:dbad57390bd1 39 const String &endpoint_type,
ram54288 0:dbad57390bd1 40 const int32_t life_time,
ram54288 0:dbad57390bd1 41 const uint16_t listen_port,
ram54288 0:dbad57390bd1 42 const String &domain,
ram54288 0:dbad57390bd1 43 M2MInterface::BindingMode mode,
ram54288 0:dbad57390bd1 44 M2MInterface::NetworkStack stack,
ram54288 0:dbad57390bd1 45 const String &context_address)
ram54288 0:dbad57390bd1 46 {
ram54288 0:dbad57390bd1 47 tr_debug("M2MInterfaceFactory::create_interface - IN");
ram54288 0:dbad57390bd1 48 tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint name : %s",endpoint_name.c_str());
ram54288 0:dbad57390bd1 49 tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint type : %s",endpoint_type.c_str());
ram54288 0:dbad57390bd1 50 tr_debug("M2MInterfaceFactory::create_interface - parameters life time(in secs): %" PRId32,life_time);
ram54288 0:dbad57390bd1 51 tr_debug("M2MInterfaceFactory::create_interface - parameters Listen Port : %d",listen_port);
ram54288 0:dbad57390bd1 52 tr_debug("M2MInterfaceFactory::create_interface - parameters Binding Mode : %d",(int)mode);
ram54288 0:dbad57390bd1 53 tr_debug("M2MInterfaceFactory::create_interface - parameters NetworkStack : %d",(int)stack);
ram54288 0:dbad57390bd1 54 M2MInterfaceImpl *interface = NULL;
ram54288 0:dbad57390bd1 55
ram54288 0:dbad57390bd1 56
ram54288 0:dbad57390bd1 57 bool endpoint_type_valid = true;
ram54288 0:dbad57390bd1 58 if(!endpoint_type.empty()) {
ram54288 0:dbad57390bd1 59 if(endpoint_type.size() > MAX_ALLOWED_STRING_LENGTH){
ram54288 0:dbad57390bd1 60 endpoint_type_valid = false;
ram54288 0:dbad57390bd1 61 }
ram54288 0:dbad57390bd1 62 }
ram54288 0:dbad57390bd1 63
ram54288 0:dbad57390bd1 64 bool domain_valid = true;
ram54288 0:dbad57390bd1 65 if(!domain.empty()) {
ram54288 0:dbad57390bd1 66 if(domain.size() > MAX_ALLOWED_STRING_LENGTH){
ram54288 0:dbad57390bd1 67 domain_valid = false;
ram54288 0:dbad57390bd1 68 }
ram54288 0:dbad57390bd1 69 }
ram54288 0:dbad57390bd1 70
ram54288 0:dbad57390bd1 71 if(((life_time == -1) || (life_time >= MINIMUM_REGISTRATION_TIME)) &&
ram54288 0:dbad57390bd1 72 !endpoint_name.empty() && (endpoint_name.size() <= MAX_ALLOWED_STRING_LENGTH) &&
ram54288 0:dbad57390bd1 73 endpoint_type_valid && domain_valid) {
ram54288 0:dbad57390bd1 74 tr_debug("M2MInterfaceFactory::create_interface - Creating M2MInterfaceImpl");
ram54288 0:dbad57390bd1 75 interface = new M2MInterfaceImpl(observer, endpoint_name,
ram54288 0:dbad57390bd1 76 endpoint_type, life_time,
ram54288 0:dbad57390bd1 77 listen_port, domain, mode,
ram54288 0:dbad57390bd1 78 stack, context_address);
ram54288 0:dbad57390bd1 79
ram54288 0:dbad57390bd1 80 }
ram54288 0:dbad57390bd1 81 tr_debug("M2MInterfaceFactory::create_interface - OUT");
ram54288 0:dbad57390bd1 82 return interface;
ram54288 0:dbad57390bd1 83 }
ram54288 0:dbad57390bd1 84
ram54288 0:dbad57390bd1 85 M2MSecurity* M2MInterfaceFactory::create_security(M2MSecurity::ServerType server_type)
ram54288 0:dbad57390bd1 86 {
ram54288 0:dbad57390bd1 87 tr_debug("M2MInterfaceFactory::create_security");
ram54288 0:dbad57390bd1 88 M2MSecurity *security = new M2MSecurity(server_type);
ram54288 0:dbad57390bd1 89 return security;
ram54288 0:dbad57390bd1 90 }
ram54288 0:dbad57390bd1 91
ram54288 0:dbad57390bd1 92 M2MServer* M2MInterfaceFactory::create_server()
ram54288 0:dbad57390bd1 93 {
ram54288 0:dbad57390bd1 94 tr_debug("M2MInterfaceFactory::create_server");
ram54288 0:dbad57390bd1 95 M2MServer *server = new M2MServer();
ram54288 0:dbad57390bd1 96 return server;
ram54288 0:dbad57390bd1 97 }
ram54288 0:dbad57390bd1 98
ram54288 0:dbad57390bd1 99 M2MDevice* M2MInterfaceFactory::create_device()
ram54288 0:dbad57390bd1 100 {
ram54288 0:dbad57390bd1 101 tr_debug("M2MInterfaceFactory::create_device");
ram54288 0:dbad57390bd1 102 M2MDevice* device = M2MDevice::get_instance();
ram54288 0:dbad57390bd1 103 return device;
ram54288 0:dbad57390bd1 104 }
ram54288 0:dbad57390bd1 105
ram54288 0:dbad57390bd1 106 M2MFirmware* M2MInterfaceFactory::create_firmware()
ram54288 0:dbad57390bd1 107 {
ram54288 0:dbad57390bd1 108 tr_debug("M2MInterfaceFactory::create_firmware");
ram54288 0:dbad57390bd1 109 M2MFirmware* firmware = M2MFirmware::get_instance();
ram54288 0:dbad57390bd1 110 return firmware;
ram54288 0:dbad57390bd1 111 }
ram54288 0:dbad57390bd1 112
ram54288 0:dbad57390bd1 113 M2MObject* M2MInterfaceFactory::create_object(const String &name)
ram54288 0:dbad57390bd1 114 {
ram54288 0:dbad57390bd1 115 tr_debug("M2MInterfaceFactory::create_object : Name : %s", name.c_str());
ram54288 0:dbad57390bd1 116 if(name.size() > MAX_ALLOWED_STRING_LENGTH || name.empty()){
ram54288 0:dbad57390bd1 117 return NULL;
ram54288 0:dbad57390bd1 118 }
ram54288 0:dbad57390bd1 119
ram54288 0:dbad57390bd1 120 M2MObject *object = NULL;
ram54288 0:dbad57390bd1 121 object = new M2MObject(name, M2MBase::stringdup(name.c_str()));
ram54288 0:dbad57390bd1 122 return object;
ram54288 0:dbad57390bd1 123 }