Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-client by
source/m2minterfacefactory.cpp@4:ae5178938864, 2016-04-02 (annotated)
- Committer:
- Yogesh Pande
- Date:
- Sat Apr 02 00:31:13 2016 +0300
- Revision:
- 4:ae5178938864
- Parent:
- 1:79b6cc67d8b4
Latest updated sources from Github and some trace group refactor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
1:79b6cc67d8b4 | 1 | /* |
Christopher Haster |
1:79b6cc67d8b4 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
Christopher Haster |
1:79b6cc67d8b4 | 3 | * SPDX-License-Identifier: Apache-2.0 |
Christopher Haster |
1:79b6cc67d8b4 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
Christopher Haster |
1:79b6cc67d8b4 | 5 | * not use this file except in compliance with the License. |
Christopher Haster |
1:79b6cc67d8b4 | 6 | * You may obtain a copy of the License at |
Christopher Haster |
1:79b6cc67d8b4 | 7 | * |
Christopher Haster |
1:79b6cc67d8b4 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
1:79b6cc67d8b4 | 9 | * |
Christopher Haster |
1:79b6cc67d8b4 | 10 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
1:79b6cc67d8b4 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
Christopher Haster |
1:79b6cc67d8b4 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
1:79b6cc67d8b4 | 13 | * See the License for the specific language governing permissions and |
Christopher Haster |
1:79b6cc67d8b4 | 14 | * limitations under the License. |
Christopher Haster |
1:79b6cc67d8b4 | 15 | */ |
Christopher Haster |
1:79b6cc67d8b4 | 16 | #include "mbed-client/m2minterfacefactory.h" |
Christopher Haster |
1:79b6cc67d8b4 | 17 | #include "mbed-client/m2mserver.h" |
Christopher Haster |
1:79b6cc67d8b4 | 18 | #include "mbed-client/m2mdevice.h" |
Christopher Haster |
1:79b6cc67d8b4 | 19 | #include "mbed-client/m2mfirmware.h" |
Christopher Haster |
1:79b6cc67d8b4 | 20 | #include "mbed-client/m2mobject.h" |
Christopher Haster |
1:79b6cc67d8b4 | 21 | #include "mbed-client/m2mconstants.h" |
Christopher Haster |
1:79b6cc67d8b4 | 22 | #include "mbed-client/m2mconfig.h" |
Christopher Haster |
1:79b6cc67d8b4 | 23 | #include "include/m2minterfaceimpl.h" |
Yogesh Pande |
4:ae5178938864 | 24 | #include "mbed-trace/mbed_trace.h" |
Yogesh Pande |
4:ae5178938864 | 25 | |
Yogesh Pande |
4:ae5178938864 | 26 | #define TRACE_GROUP "mClt" |
Christopher Haster |
1:79b6cc67d8b4 | 27 | |
Christopher Haster |
1:79b6cc67d8b4 | 28 | M2MInterface* M2MInterfaceFactory::create_interface(M2MInterfaceObserver &observer, |
Christopher Haster |
1:79b6cc67d8b4 | 29 | const String &endpoint_name, |
Christopher Haster |
1:79b6cc67d8b4 | 30 | const String &endpoint_type, |
Christopher Haster |
1:79b6cc67d8b4 | 31 | const int32_t life_time, |
Christopher Haster |
1:79b6cc67d8b4 | 32 | const uint16_t listen_port, |
Christopher Haster |
1:79b6cc67d8b4 | 33 | const String &domain, |
Christopher Haster |
1:79b6cc67d8b4 | 34 | M2MInterface::BindingMode mode, |
Christopher Haster |
1:79b6cc67d8b4 | 35 | M2MInterface::NetworkStack stack, |
Christopher Haster |
1:79b6cc67d8b4 | 36 | const String &context_address) |
Christopher Haster |
1:79b6cc67d8b4 | 37 | { |
Christopher Haster |
1:79b6cc67d8b4 | 38 | tr_debug("M2MInterfaceFactory::create_interface - IN"); |
Christopher Haster |
1:79b6cc67d8b4 | 39 | tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint name : %s",endpoint_name.c_str()); |
Christopher Haster |
1:79b6cc67d8b4 | 40 | tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint type : %s",endpoint_type.c_str()); |
Christopher Haster |
1:79b6cc67d8b4 | 41 | tr_debug("M2MInterfaceFactory::create_interface - parameters life time(in secs): %d",life_time); |
Christopher Haster |
1:79b6cc67d8b4 | 42 | tr_debug("M2MInterfaceFactory::create_interface - parameters Listen Port : %d",listen_port); |
Christopher Haster |
1:79b6cc67d8b4 | 43 | tr_debug("M2MInterfaceFactory::create_interface - parameters Binding Mode : %d",(int)mode); |
Christopher Haster |
1:79b6cc67d8b4 | 44 | tr_debug("M2MInterfaceFactory::create_interface - parameters NetworkStack : %d",(int)stack); |
Christopher Haster |
1:79b6cc67d8b4 | 45 | M2MInterfaceImpl *interface = NULL; |
Christopher Haster |
1:79b6cc67d8b4 | 46 | |
Christopher Haster |
1:79b6cc67d8b4 | 47 | |
Christopher Haster |
1:79b6cc67d8b4 | 48 | bool endpoint_type_valid = true; |
Christopher Haster |
1:79b6cc67d8b4 | 49 | if(!endpoint_type.empty()) { |
Christopher Haster |
1:79b6cc67d8b4 | 50 | if(endpoint_type.size() > MAX_ALLOWED_STRING_LENGTH){ |
Christopher Haster |
1:79b6cc67d8b4 | 51 | endpoint_type_valid = false; |
Christopher Haster |
1:79b6cc67d8b4 | 52 | } |
Christopher Haster |
1:79b6cc67d8b4 | 53 | } |
Christopher Haster |
1:79b6cc67d8b4 | 54 | |
Christopher Haster |
1:79b6cc67d8b4 | 55 | bool domain_valid = true; |
Christopher Haster |
1:79b6cc67d8b4 | 56 | if(!domain.empty()) { |
Christopher Haster |
1:79b6cc67d8b4 | 57 | if(domain.size() > MAX_ALLOWED_STRING_LENGTH){ |
Christopher Haster |
1:79b6cc67d8b4 | 58 | domain_valid = false; |
Christopher Haster |
1:79b6cc67d8b4 | 59 | } |
Christopher Haster |
1:79b6cc67d8b4 | 60 | } |
Christopher Haster |
1:79b6cc67d8b4 | 61 | |
Christopher Haster |
1:79b6cc67d8b4 | 62 | if(((life_time == -1) || (life_time >= MINIMUM_REGISTRATION_TIME)) && |
Christopher Haster |
1:79b6cc67d8b4 | 63 | !endpoint_name.empty() && (endpoint_name.size() <= MAX_ALLOWED_STRING_LENGTH) && |
Christopher Haster |
1:79b6cc67d8b4 | 64 | endpoint_type_valid && domain_valid) { |
Christopher Haster |
1:79b6cc67d8b4 | 65 | tr_debug("M2MInterfaceFactory::create_interface - Creating M2MInterfaceImpl"); |
Christopher Haster |
1:79b6cc67d8b4 | 66 | interface = new M2MInterfaceImpl(observer, endpoint_name, |
Christopher Haster |
1:79b6cc67d8b4 | 67 | endpoint_type, life_time, |
Christopher Haster |
1:79b6cc67d8b4 | 68 | listen_port, domain, mode, |
Christopher Haster |
1:79b6cc67d8b4 | 69 | stack, context_address); |
Christopher Haster |
1:79b6cc67d8b4 | 70 | |
Christopher Haster |
1:79b6cc67d8b4 | 71 | } |
Christopher Haster |
1:79b6cc67d8b4 | 72 | tr_debug("M2MInterfaceFactory::create_interface - OUT"); |
Christopher Haster |
1:79b6cc67d8b4 | 73 | return interface; |
Christopher Haster |
1:79b6cc67d8b4 | 74 | } |
Christopher Haster |
1:79b6cc67d8b4 | 75 | |
Christopher Haster |
1:79b6cc67d8b4 | 76 | M2MSecurity* M2MInterfaceFactory::create_security(M2MSecurity::ServerType server_type) |
Christopher Haster |
1:79b6cc67d8b4 | 77 | { |
Christopher Haster |
1:79b6cc67d8b4 | 78 | tr_debug("M2MInterfaceFactory::create_security"); |
Christopher Haster |
1:79b6cc67d8b4 | 79 | M2MSecurity *security = new M2MSecurity(server_type); |
Christopher Haster |
1:79b6cc67d8b4 | 80 | return security; |
Christopher Haster |
1:79b6cc67d8b4 | 81 | } |
Christopher Haster |
1:79b6cc67d8b4 | 82 | |
Christopher Haster |
1:79b6cc67d8b4 | 83 | M2MServer* M2MInterfaceFactory::create_server() |
Christopher Haster |
1:79b6cc67d8b4 | 84 | { |
Christopher Haster |
1:79b6cc67d8b4 | 85 | tr_debug("M2MInterfaceFactory::create_server"); |
Christopher Haster |
1:79b6cc67d8b4 | 86 | M2MServer *server = new M2MServer(); |
Christopher Haster |
1:79b6cc67d8b4 | 87 | return server; |
Christopher Haster |
1:79b6cc67d8b4 | 88 | } |
Christopher Haster |
1:79b6cc67d8b4 | 89 | |
Christopher Haster |
1:79b6cc67d8b4 | 90 | M2MDevice* M2MInterfaceFactory::create_device() |
Christopher Haster |
1:79b6cc67d8b4 | 91 | { |
Christopher Haster |
1:79b6cc67d8b4 | 92 | tr_debug("M2MInterfaceFactory::create_device"); |
Christopher Haster |
1:79b6cc67d8b4 | 93 | M2MDevice* device = M2MDevice::get_instance(); |
Christopher Haster |
1:79b6cc67d8b4 | 94 | return device; |
Christopher Haster |
1:79b6cc67d8b4 | 95 | } |
Christopher Haster |
1:79b6cc67d8b4 | 96 | |
Christopher Haster |
1:79b6cc67d8b4 | 97 | M2MFirmware* M2MInterfaceFactory::create_firmware() |
Christopher Haster |
1:79b6cc67d8b4 | 98 | { |
Christopher Haster |
1:79b6cc67d8b4 | 99 | tr_debug("M2MInterfaceFactory::create_firmware"); |
Christopher Haster |
1:79b6cc67d8b4 | 100 | M2MFirmware* firmware = M2MFirmware::get_instance(); |
Christopher Haster |
1:79b6cc67d8b4 | 101 | return firmware; |
Christopher Haster |
1:79b6cc67d8b4 | 102 | } |
Christopher Haster |
1:79b6cc67d8b4 | 103 | |
Christopher Haster |
1:79b6cc67d8b4 | 104 | M2MObject* M2MInterfaceFactory::create_object(const String &name) |
Christopher Haster |
1:79b6cc67d8b4 | 105 | { |
Christopher Haster |
1:79b6cc67d8b4 | 106 | tr_debug("M2MInterfaceFactory::create_object : Name : %s", name.c_str()); |
Christopher Haster |
1:79b6cc67d8b4 | 107 | if(name.size() > MAX_ALLOWED_STRING_LENGTH || name.empty()){ |
Christopher Haster |
1:79b6cc67d8b4 | 108 | return NULL; |
Christopher Haster |
1:79b6cc67d8b4 | 109 | } |
Christopher Haster |
1:79b6cc67d8b4 | 110 | |
Christopher Haster |
1:79b6cc67d8b4 | 111 | M2MObject *object = NULL; |
Christopher Haster |
1:79b6cc67d8b4 | 112 | object = new M2MObject(name); |
Christopher Haster |
1:79b6cc67d8b4 | 113 | return object; |
Christopher Haster |
1:79b6cc67d8b4 | 114 | } |