yocto_voc.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yocto_voc.cpp 28748 2017-10-03 08:23:39Z seb $
4  *
5  * Implements yFindVoc(), the high-level API for Voc functions
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 'AS IS' WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 
41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt
42 #include "yocto_voc.h"
43 #include "yapi/yjson.h"
44 #include "yapi/yapi.h"
45 #include <string.h>
46 #include <stdio.h>
47 #include <math.h>
48 #include <stdlib.h>
49 #define __FILE_ID__ "voc"
50 
51 YVoc::YVoc(const string& func): YSensor(func)
52 //--- (YVoc initialization)
53  ,_valueCallbackVoc(NULL)
54  ,_timedReportCallbackVoc(NULL)
55 //--- (end of YVoc initialization)
56 {
57  _className="Voc";
58 }
59 
61 {
62 //--- (YVoc cleanup)
63 //--- (end of YVoc cleanup)
64 }
65 //--- (YVoc implementation)
66 // static attributes
67 
68 
96 YVoc* YVoc::FindVoc(string func)
97 {
98  YVoc* obj = NULL;
99  int taken = 0;
100  if (YAPI::_apiInitialized) {
102  taken = 1;
103  }try {
104  obj = (YVoc*) YFunction::_FindFromCache("Voc", func);
105  if (obj == NULL) {
106  obj = new YVoc(func);
107  YFunction::_AddToCache("Voc", func, obj);
108  }
109  } catch (std::exception) {
111  throw;
112  }
114  return obj;
115 }
116 
129 {
130  string val;
131  if (callback != NULL) {
133  } else {
135  }
136  _valueCallbackVoc = callback;
137  // Immediately invoke value callback with current value
138  if (callback != NULL && this->isOnline()) {
139  val = _advertisedValue;
140  if (!(val == "")) {
141  this->_invokeValueCallback(val);
142  }
143  }
144  return 0;
145 }
146 
147 int YVoc::_invokeValueCallback(string value)
148 {
149  if (_valueCallbackVoc != NULL) {
150  _valueCallbackVoc(this, value);
151  } else {
153  }
154  return 0;
155 }
156 
169 {
170  YSensor* sensor = NULL;
171  sensor = this;
172  if (callback != NULL) {
174  } else {
176  }
177  _timedReportCallbackVoc = callback;
178  return 0;
179 }
180 
182 {
183  if (_timedReportCallbackVoc != NULL) {
184  _timedReportCallbackVoc(this, value);
185  } else {
187  }
188  return 0;
189 }
190 
192 {
193  string hwid;
194 
195  if(YISERR(_nextFunction(hwid)) || hwid=="") {
196  return NULL;
197  }
198  return YVoc::FindVoc(hwid);
199 }
200 
202 {
203  vector<YFUN_DESCR> v_fundescr;
204  YDEV_DESCR ydevice;
205  string serial, funcId, funcName, funcVal, errmsg;
206 
207  if(YISERR(YapiWrapper::getFunctionsByClass("Voc", 0, v_fundescr, sizeof(YFUN_DESCR), errmsg)) ||
208  v_fundescr.size() == 0 ||
209  YISERR(YapiWrapper::getFunctionInfo(v_fundescr[0], ydevice, serial, funcId, funcName, funcVal, errmsg))) {
210  return NULL;
211  }
212  return YVoc::FindVoc(serial+"."+funcId);
213 }
214 
215 //--- (end of YVoc implementation)
216 
217 //--- (YVoc functions)
218 //--- (end of YVoc functions)
string _advertisedValue
Definition: yocto_api.h:1569
YVoc(const string &func)
Definition: yocto_voc.cpp:51
static void _UpdateTimedReportCallbackList(YFunction *func, bool add)
Definition: yocto_api.cpp:3531
YVocTimedReportCallback _timedReportCallbackVoc
Definition: yocto_voc.h:76
static YVoc * FirstVoc(void)
Definition: yocto_voc.cpp:201
void(* YVocValueCallback)(YVoc *func, const string &functionValue)
Definition: yocto_voc.h:54
virtual int _invokeValueCallback(string value)
Definition: yocto_voc.cpp:147
void(* YVocTimedReportCallback)(YVoc *func, YMeasure measure)
Definition: yocto_voc.h:56
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:672
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
Definition: yocto_api.cpp:4930
YVoc * nextVoc(void)
Definition: yocto_voc.cpp:191
YAPI_FUNCTION YFUN_DESCR
Definition: yocto_api.h:230
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
Definition: yocto_api.cpp:2345
virtual int _invokeTimedReportCallback(YMeasure value)
Definition: yocto_api.cpp:7936
virtual int _invokeValueCallback(string value)
Definition: yocto_api.cpp:7645
YAPI_DEVICE YDEV_DESCR
Definition: yocto_api.h:229
static YFunction * _FindFromCache(const string &classname, const string &func)
Definition: yocto_api.cpp:2338
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
Definition: ythread.c:647
static yCRITICAL_SECTION _global_cs
Definition: yocto_api.h:476
virtual int registerValueCallback(YVocValueCallback callback)
Definition: yocto_voc.cpp:128
bool isOnline(void)
Definition: yocto_api.cpp:3291
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
Definition: yocto_api.cpp:4852
~YVoc()
Definition: yocto_voc.cpp:60
string _className
Definition: yocto_api.h:1558
virtual int registerTimedReportCallback(YVocTimedReportCallback callback)
Definition: yocto_voc.cpp:168
Definition: yocto_voc.h:67
YVocValueCallback _valueCallbackVoc
Definition: yocto_voc.h:75
virtual int _invokeTimedReportCallback(YMeasure value)
Definition: yocto_voc.cpp:181
static bool _apiInitialized
Definition: yocto_api.h:475
YRETCODE _nextFunction(string &hwId)
Definition: yocto_api.cpp:2709
static void _UpdateValueCallbackList(YFunction *func, bool add)
Definition: yocto_api.cpp:3509
#define YISERR(retcode)
Definition: ydef.h:394
static YVoc * FindVoc(string func)
Definition: yocto_voc.cpp:96


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:11