CPP Device Virtualization API Reference for Oracle Internet of Things Cloud Service Client Software Library. Release 21.1.1.0.0-3. E92477-09
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
Data.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This software is dual-licensed to you under the MIT License (MIT) and
5  * the Universal Permissive License (UPL). See the LICENSE file in the root
6  * directory for license terms. You may choose either license, or both.
7  */
8 
9 #pragma once
10 
11 #include "iotcs_virtual_device.h"
12 #include <string>
13 #include <stdexcept>
14 #include <mutex>
15 #include <map>
16 #ifdef __MBED__
17 #include "mbed.h"
18 #include "rtos.h"
19 #define MUTEX_TYPE Mutex
20 #else
21 #define MUTEX_TYPE std::mutex
22 #endif
23 
36 namespace iotdcl {
37  class Data {
38  public:
42  virtual ~Data();
58  template <typename T> Data& set(const std::string &attributeName, const T& value) throw (std::invalid_argument);
69  void submit(void) throw (std::invalid_argument);
70 
79  virtual void setOnError(ErrorCallback *callback);
80  protected:
81  Data(VirtualDevice* device, iotcs_virtual_device_handle handle, const std::string &dataName) throw (std::invalid_argument);
82  static void onErrorCallback(void* handler, iotcs_virtual_device_error_event *event);
83  private:
84  Data();
85  iotcs_data_handle handle;
86  VirtualDevice* device;
87  static MUTEX_TYPE mapMutex;
88  static std::map<void*, std::pair<VirtualDevice*, ErrorCallback*> > onErrorCallbacks;
89  };
90 };
virtual void setOnError(ErrorCallback *callback)
Set a callback that is invoked if an error occurs when submit an.
A callback interface for errors in delivery of messages.
Definition: AbstractVirtualDevice.hpp:152
Definition: VirtualDevice.hpp:38
virtual ~Data()
Destructor.
Data & set(const std::string &attributeName, const T &value)
Set the value of a field in the Data.
Definition: Data.hpp:37
void submit(void)
Submit the data.