![](/media/cache/profiles/debfdc81854eac26ec993b55a659c6e1.jpg.50x50_q85.jpg)
mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client/source/m2minterfacefactory.cpp@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #include "mbed-client/m2minterfacefactory.h" |
mbedAustin | 11:cada08fc8a70 | 17 | #include "mbed-client/m2mserver.h" |
mbedAustin | 11:cada08fc8a70 | 18 | #include "mbed-client/m2mdevice.h" |
mbedAustin | 11:cada08fc8a70 | 19 | #include "mbed-client/m2mfirmware.h" |
mbedAustin | 11:cada08fc8a70 | 20 | #include "mbed-client/m2mobject.h" |
mbedAustin | 11:cada08fc8a70 | 21 | #include "mbed-client/m2mconstants.h" |
mbedAustin | 11:cada08fc8a70 | 22 | #include "mbed-client/m2mconfig.h" |
mbedAustin | 11:cada08fc8a70 | 23 | #include "include/m2minterfaceimpl.h" |
mbedAustin | 11:cada08fc8a70 | 24 | #include "ns_trace.h" |
mbedAustin | 11:cada08fc8a70 | 25 | |
mbedAustin | 11:cada08fc8a70 | 26 | M2MInterface* M2MInterfaceFactory::create_interface(M2MInterfaceObserver &observer, |
mbedAustin | 11:cada08fc8a70 | 27 | const String &endpoint_name, |
mbedAustin | 11:cada08fc8a70 | 28 | const String &endpoint_type, |
mbedAustin | 11:cada08fc8a70 | 29 | const int32_t life_time, |
mbedAustin | 11:cada08fc8a70 | 30 | const uint16_t listen_port, |
mbedAustin | 11:cada08fc8a70 | 31 | const String &domain, |
mbedAustin | 11:cada08fc8a70 | 32 | M2MInterface::BindingMode mode, |
mbedAustin | 11:cada08fc8a70 | 33 | M2MInterface::NetworkStack stack, |
mbedAustin | 11:cada08fc8a70 | 34 | const String &context_address) |
mbedAustin | 11:cada08fc8a70 | 35 | { |
mbedAustin | 11:cada08fc8a70 | 36 | tr_debug("M2MInterfaceFactory::create_interface - IN"); |
mbedAustin | 11:cada08fc8a70 | 37 | tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint name : %s",endpoint_name.c_str()); |
mbedAustin | 11:cada08fc8a70 | 38 | tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint type : %s",endpoint_type.c_str()); |
mbedAustin | 11:cada08fc8a70 | 39 | tr_debug("M2MInterfaceFactory::create_interface - parameters life time(in secs): %d",life_time); |
mbedAustin | 11:cada08fc8a70 | 40 | tr_debug("M2MInterfaceFactory::create_interface - parameters Listen Port : %d",listen_port); |
mbedAustin | 11:cada08fc8a70 | 41 | tr_debug("M2MInterfaceFactory::create_interface - parameters Binding Mode : %d",(int)mode); |
mbedAustin | 11:cada08fc8a70 | 42 | tr_debug("M2MInterfaceFactory::create_interface - parameters NetworkStack : %d",(int)stack); |
mbedAustin | 11:cada08fc8a70 | 43 | M2MInterfaceImpl *interface = NULL; |
mbedAustin | 11:cada08fc8a70 | 44 | |
mbedAustin | 11:cada08fc8a70 | 45 | |
mbedAustin | 11:cada08fc8a70 | 46 | bool endpoint_type_valid = true; |
mbedAustin | 11:cada08fc8a70 | 47 | if(!endpoint_type.empty()) { |
mbedAustin | 11:cada08fc8a70 | 48 | if(endpoint_type.size() > MAX_ALLOWED_STRING_LENGTH){ |
mbedAustin | 11:cada08fc8a70 | 49 | endpoint_type_valid = false; |
mbedAustin | 11:cada08fc8a70 | 50 | } |
mbedAustin | 11:cada08fc8a70 | 51 | } |
mbedAustin | 11:cada08fc8a70 | 52 | |
mbedAustin | 11:cada08fc8a70 | 53 | bool domain_valid = true; |
mbedAustin | 11:cada08fc8a70 | 54 | if(!domain.empty()) { |
mbedAustin | 11:cada08fc8a70 | 55 | if(domain.size() > MAX_ALLOWED_STRING_LENGTH){ |
mbedAustin | 11:cada08fc8a70 | 56 | domain_valid = false; |
mbedAustin | 11:cada08fc8a70 | 57 | } |
mbedAustin | 11:cada08fc8a70 | 58 | } |
mbedAustin | 11:cada08fc8a70 | 59 | |
mbedAustin | 11:cada08fc8a70 | 60 | if(((life_time == -1) || (life_time >= MINIMUM_REGISTRATION_TIME)) && |
mbedAustin | 11:cada08fc8a70 | 61 | !endpoint_name.empty() && (endpoint_name.size() <= MAX_ALLOWED_STRING_LENGTH) && |
mbedAustin | 11:cada08fc8a70 | 62 | endpoint_type_valid && domain_valid) { |
mbedAustin | 11:cada08fc8a70 | 63 | tr_debug("M2MInterfaceFactory::create_interface - Creating M2MInterfaceImpl"); |
mbedAustin | 11:cada08fc8a70 | 64 | interface = new M2MInterfaceImpl(observer, endpoint_name, |
mbedAustin | 11:cada08fc8a70 | 65 | endpoint_type, life_time, |
mbedAustin | 11:cada08fc8a70 | 66 | listen_port, domain, mode, |
mbedAustin | 11:cada08fc8a70 | 67 | stack, context_address); |
mbedAustin | 11:cada08fc8a70 | 68 | |
mbedAustin | 11:cada08fc8a70 | 69 | } |
mbedAustin | 11:cada08fc8a70 | 70 | tr_debug("M2MInterfaceFactory::create_interface - OUT"); |
mbedAustin | 11:cada08fc8a70 | 71 | return interface; |
mbedAustin | 11:cada08fc8a70 | 72 | } |
mbedAustin | 11:cada08fc8a70 | 73 | |
mbedAustin | 11:cada08fc8a70 | 74 | M2MSecurity* M2MInterfaceFactory::create_security(M2MSecurity::ServerType server_type) |
mbedAustin | 11:cada08fc8a70 | 75 | { |
mbedAustin | 11:cada08fc8a70 | 76 | tr_debug("M2MInterfaceFactory::create_security"); |
mbedAustin | 11:cada08fc8a70 | 77 | M2MSecurity *security = new M2MSecurity(server_type); |
mbedAustin | 11:cada08fc8a70 | 78 | return security; |
mbedAustin | 11:cada08fc8a70 | 79 | } |
mbedAustin | 11:cada08fc8a70 | 80 | |
mbedAustin | 11:cada08fc8a70 | 81 | M2MServer* M2MInterfaceFactory::create_server() |
mbedAustin | 11:cada08fc8a70 | 82 | { |
mbedAustin | 11:cada08fc8a70 | 83 | tr_debug("M2MInterfaceFactory::create_server"); |
mbedAustin | 11:cada08fc8a70 | 84 | M2MServer *server = new M2MServer(); |
mbedAustin | 11:cada08fc8a70 | 85 | return server; |
mbedAustin | 11:cada08fc8a70 | 86 | } |
mbedAustin | 11:cada08fc8a70 | 87 | |
mbedAustin | 11:cada08fc8a70 | 88 | M2MDevice* M2MInterfaceFactory::create_device() |
mbedAustin | 11:cada08fc8a70 | 89 | { |
mbedAustin | 11:cada08fc8a70 | 90 | tr_debug("M2MInterfaceFactory::create_device"); |
mbedAustin | 11:cada08fc8a70 | 91 | M2MDevice* device = M2MDevice::get_instance(); |
mbedAustin | 11:cada08fc8a70 | 92 | return device; |
mbedAustin | 11:cada08fc8a70 | 93 | } |
mbedAustin | 11:cada08fc8a70 | 94 | |
mbedAustin | 11:cada08fc8a70 | 95 | M2MFirmware* M2MInterfaceFactory::create_firmware() |
mbedAustin | 11:cada08fc8a70 | 96 | { |
mbedAustin | 11:cada08fc8a70 | 97 | tr_debug("M2MInterfaceFactory::create_firmware"); |
mbedAustin | 11:cada08fc8a70 | 98 | M2MFirmware* firmware = M2MFirmware::get_instance(); |
mbedAustin | 11:cada08fc8a70 | 99 | return firmware; |
mbedAustin | 11:cada08fc8a70 | 100 | } |
mbedAustin | 11:cada08fc8a70 | 101 | |
mbedAustin | 11:cada08fc8a70 | 102 | M2MObject* M2MInterfaceFactory::create_object(const String &name) |
mbedAustin | 11:cada08fc8a70 | 103 | { |
mbedAustin | 11:cada08fc8a70 | 104 | tr_debug("M2MInterfaceFactory::create_object : Name : %s", name.c_str()); |
mbedAustin | 11:cada08fc8a70 | 105 | if(name.size() > MAX_ALLOWED_STRING_LENGTH || name.empty()){ |
mbedAustin | 11:cada08fc8a70 | 106 | return NULL; |
mbedAustin | 11:cada08fc8a70 | 107 | } |
mbedAustin | 11:cada08fc8a70 | 108 | |
mbedAustin | 11:cada08fc8a70 | 109 | M2MObject *object = NULL; |
mbedAustin | 11:cada08fc8a70 | 110 | object = new M2MObject(name); |
mbedAustin | 11:cada08fc8a70 | 111 | return object; |
mbedAustin | 11:cada08fc8a70 | 112 | } |