mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew 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 #ifndef M2M_SERVER_H
mbedAustin 11:cada08fc8a70 17 #define M2M_SERVER_H
mbedAustin 11:cada08fc8a70 18
mbedAustin 11:cada08fc8a70 19 #include "mbed-client/m2mobject.h"
mbedAustin 11:cada08fc8a70 20
mbedAustin 11:cada08fc8a70 21 // FORWARD DECLARATION
mbedAustin 11:cada08fc8a70 22 class M2MResource;
mbedAustin 11:cada08fc8a70 23
mbedAustin 11:cada08fc8a70 24 /**
mbedAustin 11:cada08fc8a70 25 * @brief M2MServer.
mbedAustin 11:cada08fc8a70 26 * This class represents an interface for the Server Object model of the LWM2M framework.
mbedAustin 11:cada08fc8a70 27 * It handles the server object and all its corresponding
mbedAustin 11:cada08fc8a70 28 * resources.
mbedAustin 11:cada08fc8a70 29 */
mbedAustin 11:cada08fc8a70 30
mbedAustin 11:cada08fc8a70 31 class M2MServer : public M2MObject
mbedAustin 11:cada08fc8a70 32 {
mbedAustin 11:cada08fc8a70 33
mbedAustin 11:cada08fc8a70 34 friend class M2MInterfaceFactory;
mbedAustin 11:cada08fc8a70 35 friend class M2MNsdlInterface;
mbedAustin 11:cada08fc8a70 36
mbedAustin 11:cada08fc8a70 37 public:
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39 /**
mbedAustin 11:cada08fc8a70 40 * @brief Enum defining all resources associated with
mbedAustin 11:cada08fc8a70 41 * a Server Object in the LWM2M framework.
mbedAustin 11:cada08fc8a70 42 */
mbedAustin 11:cada08fc8a70 43 typedef enum {
mbedAustin 11:cada08fc8a70 44 ShortServerID,
mbedAustin 11:cada08fc8a70 45 Lifetime,
mbedAustin 11:cada08fc8a70 46 DefaultMinPeriod,
mbedAustin 11:cada08fc8a70 47 DefaultMaxPeriod,
mbedAustin 11:cada08fc8a70 48 Disable,
mbedAustin 11:cada08fc8a70 49 DisableTimeout,
mbedAustin 11:cada08fc8a70 50 NotificationStorage,
mbedAustin 11:cada08fc8a70 51 Binding,
mbedAustin 11:cada08fc8a70 52 RegistrationUpdate
mbedAustin 11:cada08fc8a70 53 }ServerResource;
mbedAustin 11:cada08fc8a70 54
mbedAustin 11:cada08fc8a70 55 private:
mbedAustin 11:cada08fc8a70 56
mbedAustin 11:cada08fc8a70 57 /**
mbedAustin 11:cada08fc8a70 58 * @brief Constructor
mbedAustin 11:cada08fc8a70 59 */
mbedAustin 11:cada08fc8a70 60 M2MServer();
mbedAustin 11:cada08fc8a70 61
mbedAustin 11:cada08fc8a70 62
mbedAustin 11:cada08fc8a70 63 // Prevents the use of assignment operator.
mbedAustin 11:cada08fc8a70 64 M2MServer& operator=( const M2MServer& /*other*/ );
mbedAustin 11:cada08fc8a70 65
mbedAustin 11:cada08fc8a70 66 // Prevents the use of copy constructor
mbedAustin 11:cada08fc8a70 67 M2MServer( const M2MServer& /*other*/ );
mbedAustin 11:cada08fc8a70 68
mbedAustin 11:cada08fc8a70 69 public:
mbedAustin 11:cada08fc8a70 70
mbedAustin 11:cada08fc8a70 71 /**
mbedAustin 11:cada08fc8a70 72 * @brief Destructor
mbedAustin 11:cada08fc8a70 73 */
mbedAustin 11:cada08fc8a70 74 virtual ~M2MServer();
mbedAustin 11:cada08fc8a70 75
mbedAustin 11:cada08fc8a70 76 /**
mbedAustin 11:cada08fc8a70 77 * @brief Creates a new resource for a given resource enum.
mbedAustin 11:cada08fc8a70 78 * @param resource, With this function, a value can be set to the following resources:
mbedAustin 11:cada08fc8a70 79 * 'ShortServerID','Lifetime','DefaultMinPeriod','DefaultMaxPeriod','DisableTimeout',
mbedAustin 11:cada08fc8a70 80 * 'NotificationStorage'.
mbedAustin 11:cada08fc8a70 81 * @param value, Value to be set on the resource, in Integer format.
mbedAustin 11:cada08fc8a70 82 * @return M2MResource if created successfully, else NULL.
mbedAustin 11:cada08fc8a70 83 */
mbedAustin 11:cada08fc8a70 84 M2MResource* create_resource(ServerResource resource, uint32_t value);
mbedAustin 11:cada08fc8a70 85
mbedAustin 11:cada08fc8a70 86 /**
mbedAustin 11:cada08fc8a70 87 * @brief Creates a new resource for a given resource enum.
mbedAustin 11:cada08fc8a70 88 * @param resource, With this function, the following resources can be created:
mbedAustin 11:cada08fc8a70 89 * 'Disable', 'RegistrationUpdate'
mbedAustin 11:cada08fc8a70 90 * @return M2MResource if created successfully, else NULL.
mbedAustin 11:cada08fc8a70 91 */
mbedAustin 11:cada08fc8a70 92 M2MResource* create_resource(ServerResource resource);
mbedAustin 11:cada08fc8a70 93
mbedAustin 11:cada08fc8a70 94 /**
mbedAustin 11:cada08fc8a70 95 * @brief Deletes the resource with the given resource enum.
mbedAustin 11:cada08fc8a70 96 * Mandatory resources cannot be deleted.
mbedAustin 11:cada08fc8a70 97 * @param resource, Name of the resource to be deleted.
mbedAustin 11:cada08fc8a70 98 * @return True if deleted, else false.
mbedAustin 11:cada08fc8a70 99 */
mbedAustin 11:cada08fc8a70 100 bool delete_resource(ServerResource rescource);
mbedAustin 11:cada08fc8a70 101
mbedAustin 11:cada08fc8a70 102 /**
mbedAustin 11:cada08fc8a70 103 * @brief Sets the value of the given resource enum.
mbedAustin 11:cada08fc8a70 104 * @param resource, With this function, a value can be set on the following resources:
mbedAustin 11:cada08fc8a70 105 * 'Binding'.
mbedAustin 11:cada08fc8a70 106 * @param value, Value to be set on the resource, in String format.
mbedAustin 11:cada08fc8a70 107 * @return True if successfully set, else false.
mbedAustin 11:cada08fc8a70 108 */
mbedAustin 11:cada08fc8a70 109 bool set_resource_value(ServerResource resource,
mbedAustin 11:cada08fc8a70 110 const String &value);
mbedAustin 11:cada08fc8a70 111
mbedAustin 11:cada08fc8a70 112 /**
mbedAustin 11:cada08fc8a70 113 * @brief Sets the value of the given resource enum.
mbedAustin 11:cada08fc8a70 114 * @param resource, With this function, a value can be set to the following resources:
mbedAustin 11:cada08fc8a70 115 * 'ShortServerID','Lifetime','DefaultMinPeriod','DefaultMaxPeriod','DisableTimeout',
mbedAustin 11:cada08fc8a70 116 * 'NotificationStorage'.
mbedAustin 11:cada08fc8a70 117 * @param value, Value to be set on the resource, in Integer format.
mbedAustin 11:cada08fc8a70 118 * @return True if successfully set else false.
mbedAustin 11:cada08fc8a70 119 */
mbedAustin 11:cada08fc8a70 120 bool set_resource_value(ServerResource resource,
mbedAustin 11:cada08fc8a70 121 uint32_t value);
mbedAustin 11:cada08fc8a70 122 /**
mbedAustin 11:cada08fc8a70 123 * @brief Returns the value of the given resource enum, in String.
mbedAustin 11:cada08fc8a70 124 * @param resource, With this function, the following resources can return a value:
mbedAustin 11:cada08fc8a70 125 * 'Binding'.
mbedAustin 11:cada08fc8a70 126 * @return Value associated with the resource. If the resource is not valid an empty string is returned.
mbedAustin 11:cada08fc8a70 127 */
mbedAustin 11:cada08fc8a70 128 String resource_value_string(ServerResource resource) const;
mbedAustin 11:cada08fc8a70 129
mbedAustin 11:cada08fc8a70 130 /**
mbedAustin 11:cada08fc8a70 131 * @brief Returns the value of the given resource name, in Integer.
mbedAustin 11:cada08fc8a70 132 * @param resource, With this function, the following resources can return a value:
mbedAustin 11:cada08fc8a70 133 * 'ShortServerID','Lifetime','DefaultMinPeriod','DefaultMaxPeriod','DisableTimeout',
mbedAustin 11:cada08fc8a70 134 * 'NotificationStorage'
mbedAustin 11:cada08fc8a70 135 * @return Value associated with the resource. If the resource is not valid -1 is returned.
mbedAustin 11:cada08fc8a70 136 */
mbedAustin 11:cada08fc8a70 137 uint32_t resource_value_int(ServerResource resource) const;
mbedAustin 11:cada08fc8a70 138
mbedAustin 11:cada08fc8a70 139 /**
mbedAustin 11:cada08fc8a70 140 * @brief Returns whether the resource instance with the given resource enum exists or not.
mbedAustin 11:cada08fc8a70 141 * @param resource, Resource enum.
mbedAustin 11:cada08fc8a70 142 * @return True if at least one instance exists, else false.
mbedAustin 11:cada08fc8a70 143 */
mbedAustin 11:cada08fc8a70 144 bool is_resource_present(ServerResource resource)const;
mbedAustin 11:cada08fc8a70 145
mbedAustin 11:cada08fc8a70 146 /**
mbedAustin 11:cada08fc8a70 147 * @brief Returns the total number of resources for the server object.
mbedAustin 11:cada08fc8a70 148 * @return Total number of resources.
mbedAustin 11:cada08fc8a70 149 */
mbedAustin 11:cada08fc8a70 150 uint16_t total_resource_count()const;
mbedAustin 11:cada08fc8a70 151
mbedAustin 11:cada08fc8a70 152 private:
mbedAustin 11:cada08fc8a70 153
mbedAustin 11:cada08fc8a70 154 M2MResource* get_resource(ServerResource res) const;
mbedAustin 11:cada08fc8a70 155
mbedAustin 11:cada08fc8a70 156
mbedAustin 11:cada08fc8a70 157 private:
mbedAustin 11:cada08fc8a70 158
mbedAustin 11:cada08fc8a70 159 M2MObjectInstance* _server_instance;
mbedAustin 11:cada08fc8a70 160
mbedAustin 11:cada08fc8a70 161 friend class Test_M2MServer;
mbedAustin 11:cada08fc8a70 162 friend class Test_M2MNsdlInterface;
mbedAustin 11:cada08fc8a70 163 };
mbedAustin 11:cada08fc8a70 164
mbedAustin 11:cada08fc8a70 165 #endif // M2M_SERVER_H