Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
mbed_cloud_client_resource.h
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2018 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #ifndef MBED_CLOUD_CLIENT_RESOURCE_H 00020 #define MBED_CLOUD_CLIENT_RESOURCE_H 00021 00022 #include "mbed.h" 00023 #include "simple-mbed-cloud-client.h" 00024 #include "mbed-client/m2mstring.h" 00025 00026 namespace M2MMethod { 00027 00028 enum M2MMethod { 00029 GET = 0x01, 00030 PUT = 0x02, 00031 POST = 0x04, 00032 DELETE = 0x08 00033 }; 00034 00035 }; 00036 00037 struct mcc_resource_def { 00038 unsigned int object_id; 00039 unsigned int instance_id; 00040 unsigned int resource_id; 00041 String name; 00042 unsigned int method_mask; 00043 String value; 00044 bool observable; 00045 Callback<void(const char*)> *put_callback; 00046 Callback<void(void*)> *post_callback; 00047 Callback<void(const M2MBase&, const NoticationDeliveryStatus)> *notification_callback; 00048 }; 00049 00050 class SimpleMbedCloudClient; 00051 00052 class MbedCloudClientResource { 00053 public: 00054 MbedCloudClientResource(SimpleMbedCloudClient *client, const char *path, const char *name); 00055 00056 void observable(bool observable); 00057 void methods(unsigned int methodMask); 00058 void attach_put_callback(Callback<void(MbedCloudClientResource*, m2m::String)> callback); 00059 void attach_post_callback(Callback<void(MbedCloudClientResource*, const uint8_t*, uint16_t)> callback); 00060 void attach_notification_callback(Callback<void(MbedCloudClientResource*, const NoticationDeliveryStatus)> callback); 00061 void detach_put_callback(); 00062 void detach_post_callback(); 00063 void detach_notification_callback(); 00064 void set_value(int value); 00065 void set_value(const char *value); 00066 void set_value(float value); 00067 m2m::String get_value(); 00068 int get_value_int(); 00069 float get_value_float(); 00070 00071 void get_data(mcc_resource_def *resourceDef); 00072 void set_m2m_resource(M2MResource *res); 00073 M2MResource* get_m2m_resource(); 00074 00075 static const char * delivery_status_to_string(const NoticationDeliveryStatus status); 00076 00077 private: 00078 void internal_post_callback(void* params); 00079 void internal_put_callback(const char* resource); 00080 void internal_notification_callback(const M2MBase& m2mbase, const NoticationDeliveryStatus status); 00081 00082 SimpleMbedCloudClient *client; 00083 M2MResource *resource; 00084 m2m::String path; 00085 m2m::String name; 00086 m2m::String value; 00087 bool isObservable; 00088 unsigned int methodMask; 00089 00090 Callback<void(MbedCloudClientResource*, m2m::String)> putCallback; 00091 Callback<void(MbedCloudClientResource*, const uint8_t*, uint16_t)> postCallback; 00092 Callback<void(MbedCloudClientResource*, const NoticationDeliveryStatus)> notificationCallback; 00093 Callback<void(void*)> internalPostCallback; 00094 Callback<void(const char*)> internalPutCallback; 00095 Callback<void(const M2MBase&, const NoticationDeliveryStatus)> internalNotificationCallback; 00096 }; 00097 00098 #endif // MBED_CLOUD_CLIENT_RESOURCE_H
Generated on Tue Jul 12 2022 19:12:13 by 1.7.2