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
AbstractVirtualDevice.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 2018, 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 <string>
12 #include <DeviceModel.hpp>
13 #include <NamedValue.hpp>
14 
18 namespace iotdcl {
19  class VirtualDevice;
20 
25  template <class V> class Event {
26  public:
30  virtual ~Event() {
31  }
32 
37  virtual V* getVirtualDevice() = 0;
38 
45  virtual NamedValue* getNamedValue() const = 0;
46  protected:
47  VirtualDevice *vd;
48  NamedValue *value;
49 
50  Event(VirtualDevice *vd, NamedValue *value) {
51  this->vd = vd;
52  this->value = value;
53  }
54  private:
55  Event() {
56  }
57  };
58 
64  template <class V> class ChangeEvent: public Event<V> {
65  public:
69  virtual ~ChangeEvent() {
70  }
71  protected:
72  ChangeEvent(VirtualDevice *vd, NamedValue *value) : Event<V>(vd,value) {}
73  };
74 
80  template <class V> class ActionEvent: public Event<V> {
81  public:
86  virtual const std::string getName() const = 0;
90  virtual ~ActionEvent() {
91  }
92  protected:
93  ActionEvent(VirtualDevice *vd, NamedValue *value) : Event<V>(vd,value) {}
94  };
95 
100  public:
105  virtual void onAction(ActionEvent<VirtualDevice> &arguments) const = 0;
109  virtual ~ActionCallback() {
110  }
111  };
112 
119  public:
126  virtual void onChange(const ChangeEvent<VirtualDevice>& event) const = 0;
127  };
128 
136  template <class V> class ErrorEvent: public Event<V> {
137  public:
142  virtual const std::string getMessage() const = 0;
143  virtual ~ErrorEvent() {
144  }
145  protected:
146  ErrorEvent(VirtualDevice *vd, NamedValue *value) : Event<V>(vd,value) {}
147  };
148 
153  public:
161  virtual void onError(const ErrorEvent<VirtualDevice>& event) const = 0;
162  };
202  template<class V> class AbstractVirtualDevice {
203  public:
204 
209  }
210 
215  virtual const DeviceModel& getDeviceModel() = 0;
216 
221  virtual const std::string& getEndpointId() const = 0;
222 
237  template <typename T> V& set(const std::string &attributeName, T& value) {
238  V *this_ptr(dynamic_cast<V*>(this));
239  if (this_ptr != nullptr) {
240  this_ptr->template set<T>(attributeName, value);
241  }
242  return *this_ptr;
243  }
244 
254  template <typename T> T get(const std::string &attributeName) {
255  V *this_ptr(dynamic_cast<V*>(this));
256  if (this_ptr != nullptr) {
257  return this_ptr->template get<T>(attributeName);
258  }
259  return 0;
260  }
261 
277  virtual V& update(void) = 0;
278 
284  virtual void finish(void) = 0;
285 
299  virtual void setOnChange(const ChangeCallback *callback) = 0;
300 
314  virtual void setOnError(const ErrorCallback *callback) = 0;
333  virtual void setOnChange(const std::string &attributeName, const ChangeCallback *callback) = 0;
334 
353  virtual void setOnError(const std::string &attributeName, const ErrorCallback *callback) = 0;
354  };
355 };
virtual void onError(const ErrorEvent< VirtualDevice > &event) const =0
Notify that an error occured when attempting to deliver messages to the server.
virtual const DeviceModel & getDeviceModel()=0
Get the device model of this device object.
An event passed to the.
Definition: AbstractVirtualDevice.hpp:136
virtual V & update(void)=0
Set a mark for beginning an update transaction.
virtual void setOnChange(const ChangeCallback *callback)=0
Set a callback that is invoked when the value of any attribute in the device model is changed from th...
virtual V * getVirtualDevice()=0
Get the virtual device that is the source of the event.
virtual ~AbstractVirtualDevice()
Destructor.
Definition: AbstractVirtualDevice.hpp:208
A callback interface for receiving an event when the value of an attribute has changed.
Definition: AbstractVirtualDevice.hpp:118
An event passed to a callback.
Definition: AbstractVirtualDevice.hpp:25
virtual const std::string getMessage() const =0
Get the error message.
A callback interface for errors in delivery of messages.
Definition: AbstractVirtualDevice.hpp:152
virtual const std::string & getEndpointId() const =0
Get the endpoint id of the device.
virtual NamedValue * getNamedValue() const =0
Get the name-value pair from the event.
An event passed to the onChange callback.
Definition: AbstractVirtualDevice.hpp:64
V & set(const std::string &attributeName, T &value)
Set the value of an attribute.
Definition: AbstractVirtualDevice.hpp:237
virtual ~ActionEvent()
Destructor.
Definition: AbstractVirtualDevice.hpp:90
Definition: NamedValue.hpp:24
virtual void onChange(const ChangeEvent< VirtualDevice > &event) const =0
Callback for receiving an event when the value of an attribute has changed.
Detailed information on a device model.
Definition: DeviceModel.hpp:19
Definition: VirtualDevice.hpp:38
virtual ~ChangeEvent()
Destructor.
Definition: AbstractVirtualDevice.hpp:69
An event passed to the onChange callback.
Definition: AbstractVirtualDevice.hpp:80
A callback interface for receiving notification of an Action.
Definition: AbstractVirtualDevice.hpp:99
virtual ~ActionCallback()
Desctructor.
Definition: AbstractVirtualDevice.hpp:109
virtual ~Event()
Destructor.
Definition: AbstractVirtualDevice.hpp:30
virtual const std::string getName() const =0
Get the name of the action.
virtual void finish(void)=0
Causes the values set in an update transaction to be sent to the server and clears the update-transac...
virtual void onAction(ActionEvent< VirtualDevice > &arguments) const =0
Callback for receiving an action from the server for a VirtualDevice.
AbstractVirtualDevice is a representation of a device model implemented by an endpoint.
Definition: AbstractVirtualDevice.hpp:202
virtual void setOnError(const ErrorCallback *callback)=0
Set a callback that is invoked if an error occurs when setting the value of any attribute in the devi...