use TCP to connect to mbed connector
Fork of mbedConnectorInterfaceWithDM by
source/NamedPointer.cpp@90:b738617379a6, 2016-11-28 (annotated)
- Committer:
- Maggie17
- Date:
- Mon Nov 28 15:52:56 2016 +0000
- Revision:
- 90:b738617379a6
- Parent:
- 45:db754b994deb
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 27:b8aaf7dc7023 | 1 | /** |
ansond | 27:b8aaf7dc7023 | 2 | * @file NamedPointer.cpp |
ansond | 27:b8aaf7dc7023 | 3 | * @brief mbed CoAP Endpoint Device Management Named Pointer |
ansond | 27:b8aaf7dc7023 | 4 | * @author Doug Anson |
ansond | 27:b8aaf7dc7023 | 5 | * @version 1.0 |
ansond | 27:b8aaf7dc7023 | 6 | * @see |
ansond | 27:b8aaf7dc7023 | 7 | * |
ansond | 27:b8aaf7dc7023 | 8 | * Copyright (c) 2016 |
ansond | 27:b8aaf7dc7023 | 9 | * |
ansond | 27:b8aaf7dc7023 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 27:b8aaf7dc7023 | 11 | * you may not use this file except in compliance with the License. |
ansond | 27:b8aaf7dc7023 | 12 | * You may obtain a copy of the License at |
ansond | 27:b8aaf7dc7023 | 13 | * |
ansond | 27:b8aaf7dc7023 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 27:b8aaf7dc7023 | 15 | * |
ansond | 27:b8aaf7dc7023 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 27:b8aaf7dc7023 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 27:b8aaf7dc7023 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 27:b8aaf7dc7023 | 19 | * See the License for the specific language governing permissions and |
ansond | 27:b8aaf7dc7023 | 20 | * limitations under the License. |
ansond | 27:b8aaf7dc7023 | 21 | */ |
ansond | 27:b8aaf7dc7023 | 22 | |
ansond | 27:b8aaf7dc7023 | 23 | // Base Class |
ansond | 27:b8aaf7dc7023 | 24 | #include "mbed-connector-interface/ObjectInstanceManager.h" |
ansond | 27:b8aaf7dc7023 | 25 | |
ansond | 27:b8aaf7dc7023 | 26 | // constructor |
ansond | 45:db754b994deb | 27 | NamedPointer::NamedPointer(string name,void *ptr,int index) { |
ansond | 27:b8aaf7dc7023 | 28 | this->m_name = name; |
ansond | 27:b8aaf7dc7023 | 29 | this->m_ptr = ptr; |
ansond | 45:db754b994deb | 30 | this->m_index = index; |
ansond | 27:b8aaf7dc7023 | 31 | this->m_list = (void *)new NamedPointerList(); |
ansond | 27:b8aaf7dc7023 | 32 | } |
ansond | 27:b8aaf7dc7023 | 33 | |
ansond | 27:b8aaf7dc7023 | 34 | // copy constructor |
ansond | 27:b8aaf7dc7023 | 35 | NamedPointer::NamedPointer(const NamedPointer &np) { |
ansond | 27:b8aaf7dc7023 | 36 | this->m_name = np.m_name; |
ansond | 27:b8aaf7dc7023 | 37 | this->m_ptr = np.m_ptr; |
ansond | 45:db754b994deb | 38 | this->m_index = np.m_index; |
ansond | 27:b8aaf7dc7023 | 39 | this->m_list = this->copyList(np.m_list); |
ansond | 27:b8aaf7dc7023 | 40 | } |
ansond | 27:b8aaf7dc7023 | 41 | |
ansond | 27:b8aaf7dc7023 | 42 | // Destructor |
ansond | 27:b8aaf7dc7023 | 43 | NamedPointer::~NamedPointer() { |
ansond | 27:b8aaf7dc7023 | 44 | NamedPointerList *list = (NamedPointerList *)this->m_list; |
ansond | 27:b8aaf7dc7023 | 45 | if (list != NULL) { |
ansond | 27:b8aaf7dc7023 | 46 | delete list; |
ansond | 27:b8aaf7dc7023 | 47 | } |
ansond | 27:b8aaf7dc7023 | 48 | } |
ansond | 27:b8aaf7dc7023 | 49 | |
ansond | 27:b8aaf7dc7023 | 50 | // Get the Name |
ansond | 27:b8aaf7dc7023 | 51 | string NamedPointer::name() { |
ansond | 27:b8aaf7dc7023 | 52 | return this->m_name; |
ansond | 27:b8aaf7dc7023 | 53 | } |
ansond | 27:b8aaf7dc7023 | 54 | |
ansond | 27:b8aaf7dc7023 | 55 | // Get the Pointer |
ansond | 27:b8aaf7dc7023 | 56 | void *NamedPointer::ptr() { |
ansond | 27:b8aaf7dc7023 | 57 | return this->m_ptr; |
ansond | 27:b8aaf7dc7023 | 58 | } |
ansond | 27:b8aaf7dc7023 | 59 | |
ansond | 45:db754b994deb | 60 | // Get the Index |
ansond | 45:db754b994deb | 61 | int NamedPointer::index() { |
ansond | 45:db754b994deb | 62 | return this->m_index; |
ansond | 45:db754b994deb | 63 | } |
ansond | 45:db754b994deb | 64 | |
ansond | 27:b8aaf7dc7023 | 65 | // Get any associated list |
ansond | 27:b8aaf7dc7023 | 66 | void *NamedPointer::list() { |
ansond | 27:b8aaf7dc7023 | 67 | return this->m_list; |
ansond | 27:b8aaf7dc7023 | 68 | } |
ansond | 27:b8aaf7dc7023 | 69 | |
ansond | 27:b8aaf7dc7023 | 70 | // Copy the list |
ansond | 27:b8aaf7dc7023 | 71 | void *NamedPointer::copyList(void *list) { |
ansond | 27:b8aaf7dc7023 | 72 | NamedPointerList *npl = new NamedPointerList(); |
ansond | 27:b8aaf7dc7023 | 73 | NamedPointerList *tmp_list = (NamedPointerList *)list; |
ansond | 38:bb6d2be4d54c | 74 | for(int i=0;tmp_list != NULL && i<(int)tmp_list->size();++i) { |
ansond | 27:b8aaf7dc7023 | 75 | npl->push_back(tmp_list->at(i)); |
ansond | 27:b8aaf7dc7023 | 76 | } |
ansond | 27:b8aaf7dc7023 | 77 | return (void *)npl; |
ansond | 27:b8aaf7dc7023 | 78 | } |
ansond | 27:b8aaf7dc7023 | 79 |