Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
resources.H
Go to the documentation of this file.
1/*
2 * This file is part of the Home2L project.
3 *
4 * (C) 2015-2024 Gundolf Kiefer
5 *
6 * Home2L is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Home2L is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Home2L. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21
22/* Home2L Resources interface file.
23 *
24 * This file contains the shared interface for the Home2L Resources library.
25 * It is the sole file to be included by any client application.
26 * Also, it serves as a SWIG input file for the Python library 'home2l'.
27 */
28
29
30#ifndef _RC_LIB_
31#define _RC_LIB_
32
33
34// This file is SWIG-readable and part of the Python library.
35
36
37#include "env.H"
38
39
40
41
42
43// ***** Doxygen Header *****
44
45
105#ifdef SWIG
106%pythoncode %{
107## @file
108##
109##
110## @defgroup resources Resources
111## @brief The *Home2L Resources* library.
112##
113## The API exports a large number of low-level C/C++ functions and classes, which in many cases
114## are not relevant for rules scripts or Python-based drivers and are not documented in detail here.
115## As a rule of thumb, the level of documentation reflects the relevance of some function.
116##
117## The most common functions can be found in section @ref resources_general.
118## Besides this, the classes CResource (@ref resources_rc) and CRcValueState (@ref resources_values)
119## are important for accessing the data transported via resource objects.
120##
121## Most of the information presented here is also available as *Python docstrings*
122## (avaliable via `help(<name>)` in a *Python* shell).
123## Additional information can be found in the
124## [*C/C++ API documentation*](../home2l-api_c/group__resources.html).
125##
126## @{
127##
128## @defgroup resources_general Main API
129## @brief Top-level functionality of the *Resources* library - most commonly used functions can be found here.
130##
131## @defgroup resources_values Values, Types and States
132## @brief Basic definitions for values and their types and state.
133## Most relevant is the CRcValueState class to access the present value and state of a resource.
134## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__values.html).
135##
136## @defgroup resources_rc Resource Objects
137## @brief Accessing resource objects.
138## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__rc.html).
139##
140## @defgroup resources_directory Directory Services
141## @brief Querying local metadata (for interactive debugging).
142## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__directory.html).
143##
144## @defgroup resources_subscribe Subscriptions
145## @brief Low-level access to the C/C++ subscriber classes.
146## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__subscribe.html).
147##
148## @defgroup resources_requests Requests
149## @brief Low-level access to the C/C++ request class.
150## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__requests.html).
151##
152## @defgroup resources_drivers Drivers
153## @brief Low-level access to the C/C++ driver-related classes.
154## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__drivers.html).
155## Normally, the functions and decorators described in module [*Home2L / Resources*](group__home2l__resources.html)
156## should be used to define custom drivers in Python.
157%}
158#endif // SWIG
159
160
161
162
163
164// *************************** (Forward) Declararions ****************************
165
166
167#ifndef SWIG
168
169
170// Forward declarations (full declaration below)...
171class CRcSubscriber;
172class CRcRequest;
173
174
175
176// ***** Internal classes *****
177
178class CRcHost; // represents a (remote) host
179class CRcDriver; // represents a (local) driver
180class CRcSubscriberLink;
181class CResourceLink;
182
183
184#endif // #ifndef SWIG
185
186
187
188// ***** Request priorities *****
189
192#ifdef SWIG
193%pythoncode %{
194## @addtogroup resources_requests
195## @{
196%}
197#endif // SWIG
198
210#define rcPrioMin 0
211#define rcPrioNormal 3
212#define rcPrioMax 9
213
214#define rcPrioDefault 0
215#define rcPrioRuleMin 1
216#define rcPrioRule 3
217#define rcPrioRuleMax 5
218#define rcPrioUser 6
219#define rcPrioShell 7
220#define rcPrioSafety 8
221#define rcPrioIKnowWhatImDoing 9
222
223#define rcPrioNone -1
224
226
227
230
231extern const char *const rcDefaultRequestId;
232
233
235#ifdef SWIG
236%pythoncode %{
237## @}
238%}
239#endif // SWIG
240
241
242
243
244
245// *************************** Values, Types and States ************************
246
247
250#ifdef SWIG
251%pythoncode %{
252## @addtogroup resources_values
253## @{
254%}
255#endif // SWIG
256
257
258
259
260
261// ***** Types *****
262
263
264#define rctBasicTypesBase rctBool
265#define rctBasicTypesLast rctTime
266
267#define rctSpecialTypesBase rctTrigger
268#define rctSpecialTypesLast rctMutex
269
270#define rctUnitTypesBase 0x40
271#define rctUnitTypesLast (rctUnitTypesEND-1)
272
273#define rctEnumTypesBase 0x80
274#define rctEnumTypesLast (rctEnumTypesEND-1)
275
276
280
287 //~ rctBlob, ///< Binary data (not implemented yet, TBD)
289 //~ rctColor, ///< Color value (not implemented yet, TBD)
291
295 rctMutex,
313
322 rctPercent = rctUnitTypesBase,
326 rctUnitTypesEND,
328
338 rctUseState = rctEnumTypesBase,
346 rctEnumTypesEND
348};
349
350
351// Type names ...
352const char *RcTypeGetName (ERcType t);
353ERcType RcTypeGetFromName (const char *name);
354
355// Get base type ...
360
361// Unit types ...
362static inline bool RcTypeIsUnitType (ERcType t) { return t >= rctUnitTypesBase && t <= rctEnumTypesBase; }
364const char *RcTypeGetUnit (ERcType t);
366
367// Enumeration types ...
368static inline bool RcTypeIsEnumType (ERcType t) { return t >= rctEnumTypesBase; }
372const char *RcTypeGetEnumValue (ERcType t, int idx, bool warn = true);
376int RcTypeGetEnumIdx (ERcType t, const char *value, bool warn = true);
379
380
381
382
383
384// ***** Enum declarations for enumeration types *****
385
386
389 rcvUseDay = 0,
394
395
398 rcvWindowClosed = 0,
403
404
407 rcvPhoneIdle = 0,
411
412
415 rcvPlayerStopped = 0,
419
420
421
422
423
424// ***** Values *****
425
426
427// Union for an untyped value (for internal use only) @private
428#ifdef SWIG
429%immutable vString;
430//~ %immutable vBlob;
431#endif
432union URcValue {
433 uint64_t vAny; // Pseudo-field to clear/compare independent of type
434
435 bool vBool;
436 int vInt; // Width/value range can be machine dependent, but must be at least 32 bits (-2^31 .. +2^31-1).
437 float vFloat; // Encoding must be 32-bit floating point according to IEEE 754
438 const char *vString; // Pointer to a dynamically allocated string; NULL <=> string is empty ("")
439 //~ uint8_t *vBlob; // Binary data of any size (not implemented yet, TBD)
440 TTicks vTime;
441 //~ uint32_t vColor; // Color value (ARGB) (not implemented yet, TBD)
442};
443
444
445#ifndef SWIG
446STATIC_ASSERT(sizeof (URcValue) == sizeof (URcValue::vAny));
447#endif
448
449
450
451
452
453// ***** State *****
454
455
461
462 // Aliases ...
466
467
468
469
470
471// ***** CRcValueState *****
472
473
475#ifdef SWIG
476%feature("docstring") CRcValueState "Typed value tagged with a state and a time stamp.\n\n"
477 "The constants for type 'ERcType' have the prefix 'rct*'."
478 "The state may be one of:\n"
479 " 'rcsUnknown': The value is unknown.\n"
480 " 'rcsBusy': The value is known, the underlying device is busy.\n"
481 " 'rcsValid': The value is known and stable.\n"
482 "The time stamp reflects the age of a value (last change/update). It is\n"
483 "generally not valid to judge from the time stamp whether the value is\n"
484 "outdated, since there are other mechanisms in the library setting the\n"
485 "state to 'rcsUnknown' if, for example, the connection to a remote resource\n"
486 "got lost."
487#endif
489 public:
490 CRcValueState () { type = rctNone; Clear (); }
491 CRcValueState (const CRcValueState *vs) { type = rctNone; Set (vs); if (vs) timeStamp = vs->timeStamp; }
492 CRcValueState (ERcType _type) { type = rctNone; Clear (_type); }
493
494 CRcValueState (ERcType _type, bool _val, ERcState _state = rcsValid) { type = rctNone; SetBool (_val, _state); }
495 CRcValueState (ERcType _type, int _val, ERcState _state = rcsValid) { type = rctNone; SetGenericInt (_val, _type, _state); }
496 CRcValueState (ERcType _type, float _val, ERcState _state = rcsValid) { type = rctNone; SetGenericFloat (_val, _type, _state); }
497 CRcValueState (ERcType _type, const char *_val, ERcState _state = rcsValid) { type = rctNone; SetGenericString (_val, _type, _state); }
498 CRcValueState (ERcType _type, TTicks _val, ERcState _state = rcsValid) { type = rctNone; SetTime (_val, _state); }
499
501
502#ifndef SWIG
503 CRcValueState& operator = (const CRcValueState &_vs) { Set (&_vs); timeStamp = _vs.timeStamp; return *this; }
504#endif
505
511 void Clear () { Clear (type); }
513 void Clear (ERcType _type, ERcState _state = rcsUnknown);
519 void Set (const CRcValueState *vs2);
521
535 void SetToReportBusyNewVal () { state = rcsBusy; }
539 void SetToReportNothing () { state = rcsUnknown; }
542
550 void SetGenericInt (int _val, ERcType _type, ERcState _state = rcsValid);
552 void SetGenericFloat (float _val, ERcType _type, ERcState _state = rcsValid);
554 bool SetGenericString (const char *_val, ERcType _type, ERcState _state = rcsValid);
558
561 void SetBool (bool _val, ERcState _state = rcsValid) { SetGenericInt (_val, rctBool, _state); }
562 void SetInt (int _val, ERcState _state = rcsValid) { SetGenericInt (_val, rctInt, _state); }
563 void SetFloat (float _val, ERcState _state = rcsValid) { SetGenericFloat (_val, rctFloat, _state); }
564 bool SetString (const char *_val, ERcState _state = rcsValid) { return SetGenericString (_val, rctMutex, _state); }
565 void SetTime (TTicks _val, ERcState _state = rcsValid);
566
567 void SetTrigger (int _val = 1, ERcState _state = rcsValid) { SetGenericInt (_val, rctTrigger, _state); }
568 bool SetMutex (const char *_val, ERcState _state = rcsValid) { return SetGenericString (_val, rctMutex, _state); }
569
570 void SetUnitInt (ERcType type, int _val, ERcState _state = rcsValid) { SetGenericInt (_val, type, _state); }
571 void SetUnitFloat (ERcType type, float _val, ERcState _state = rcsValid) { SetGenericFloat (_val, type, _state); }
572
573 void SetEnum (ERcType type, int _val, ERcState _state = rcsValid) { SetGenericInt (_val, type, _state); }
575
586 int GenericInt () const { ASSERT (RcTypeGetBaseType (type) == rctInt); return val.vInt; }
587 float GenericFloat () const { ASSERT (RcTypeGetBaseType (type) == rctFloat); return val.vFloat; }
588 const char * GenericString () const { ASSERT (RcTypeGetBaseType (type) == rctString); return val.vString; }
589
590 bool Bool () const { ASSERT (type == rctBool); return val.vBool; }
591 int Int () const { ASSERT (type == rctInt); return val.vInt; }
592 float Float () const { ASSERT (type == rctFloat); return val.vFloat; }
593 const char * String () const { ASSERT (type == rctString); return val.vString; }
594 TTicks Time () const { ASSERT (type == rctTime); return val.vTime; }
595
596 int Trigger () const { ASSERT (type == rctTrigger); return val.vInt; }
597 const char * Mutex () const { ASSERT (type == rctMutex); return val.vString; }
598
599 int UnitInt (ERcType _type) const { ASSERT (type == _type); return val.vInt; }
600 float UnitFloat (ERcType _type) const { ASSERT (type == _type); return val.vFloat; }
601
602 int EnumIdx () const { ASSERT (RcTypeIsEnumType (type)); return val.vInt; }
604
605#ifndef SWIG
617 ERcState GetValue (bool *retBool);
618 ERcState GetValue (int *retInt);
619 ERcState GetValue (float *retFloat);
620 ERcState GetValue (CString *retString);
621 ERcState GetValue (TTicks *retTime);
623#endif
624
634 bool ValidBool (bool defaultVal = false);
635 int ValidInt (int defaultVal = 0);
636 float ValidFloat (float defaultVal = 0.0);
637 const char * ValidString (const char *defaultVal = CString::emptyStr);
638 TTicks ValidTime (TTicks defaultVal = 0);
639
640 int ValidTrigger (int defaultVal = 0) { return ValidInt (defaultVal); }
641 const char * ValidMutex (const char *defaultVal = CString::emptyStr) { return ValidString (defaultVal); }
642
643 int ValidUnitInt (ERcType _type, int defaultVal = 0) const;
644 float ValidUnitFloat (ERcType _type, float defaultVal = 0.0) const;
645 int ValidEnumIdx (ERcType _type, int defaultVal = 0) const;
647
650 void SetType (ERcType _type) { Clear (_type); }
652 void SetState (ERcState _state) { state = _state; }
653 void SetTimeStamp (TTicks _timeStamp) { timeStamp = _timeStamp; }
654
655 ERcType Type () const { return type; }
656 ERcState State () const { return state; }
657 TTicks TimeStamp () const { return timeStamp; }
658
659 bool IsValid () const { return state == rcsValid; }
661 bool IsBusy () const { return state == rcsBusy; }
663 bool IsKnown () const { return state != rcsUnknown; }
665
666 bool Equals (const CRcValueState *vs2) const;
668 bool ValueEquals (const CRcValueState *vs2) const;
671
674 bool Convert (ERcType _type);
678
681 const char *ToStr (CString *ret, bool withType = false, bool withTimeStamp = false, bool precise = false, int stringChars = 20) const;
690
691 bool SetFromStr (const char *str);
722 bool SetFromStrFast (const char *str, bool warn = true);
730
733 void ToHuman (char *retBuf, int retBufSize);
741
742 protected:
743 friend class CResource;
744
745 // Fields...
746 ERcType type;
747 URcValue val;
748 ERcState state;
750};
751
752
753// Python extension...
754#ifdef SWIG
755%extend CRcValueState {
756 %newobject __str__ ();
757 const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
758 %newobject __repr__ ();
759 const char *__repr__ () { CString s, s1; s.SetF ("(CRcValueState) %s", $self->ToStr (&s1, true)); return s.Disown (); }
760 bool __eq__ (CRcValueState *other) { return $self->Equals (other); }
761 bool __ne__ (CRcValueState *other) { return !$self->Equals (other); }
762 %pythoncode %{
763 pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
764
765 ## Return the value as a Python object.
766 def Value(self):
767 """Return the value as a Python object. In case of a state of 'rcsUnknown' or\n\
768 if 'self' is not defined, 'None' is returned. 'self == None' is allowed.\n\
769 """
770 if not self: return None
771 if self.State () == rcsUnknown: return None
772 t = RcTypeGetBaseType (self.Type ())
773 if t == rctBool: return self.Bool()
774 elif t == rctInt: return self.GenericInt()
775 elif t == rctFloat: return self.GenericFloat()
776 elif t == rctString: return self.GenericString()
777 elif t == rctTime: return self.Time()
778 else: return None
779
780 ## Return the most appropriate valid value as a Python object.
781 def ValidValue(self, defaultVal):
782 """Return the value as a Python object. Unlike 'Value', this method never\n\
783 returns 'None', but reverts to the given default value, if 'self' does not\n\
784 transort a valid value. 'self == None' is tolerated\n\
785 """
786 ret = self.Value ()
787 if ret == None: ret = defaultVal
788 return ret
789 %} // %pythoncode
790}; // %extend CRcValueState
791#endif
792
793
794#define NO_VALUE_STATE ((CRcValueState *) NULL)
796
797
799#ifdef SWIG
800%pythoncode %{
801## @}
802%}
803#endif // SWIG
804
805
806
807
808
809// *************************** Resources ***************************************
810
811
879#ifdef SWIG
880%pythoncode %{
881## @addtogroup resources_rc
882## @{
883%}
884#endif // SWIG
885
886
902#ifdef SWIG
903%feature("docstring") CResource "Home2L Resource.\n\n"
904 "This is the most central class of the library. A 'Resource' may represent\n"
905 "a sensor, an actor, a stored value, a virtual device, a mutex, an event\n"
906 "trigger - almost anything. Resources are identified by a uniform resource\n"
907 "identifier (URI)."
908#endif
909class CResource /* final */ {
910 public:
911
912
913 // ***** For applications *****
914
917 static CResource *Get (const char *uri, bool allowWait = false);
932 static void GarbageCollection ();
945
948 const char *Uri () { return gid.Get (); }
949 const char *Gid () { return gid.Get (); }
950 const char *Lid () { return ATOMIC_READ (lid); }
952
953 bool Is (const char *uri);
954 bool Is (CResource *rc) { return this == rc; }
955 bool IsLike (const char *pattern);
956
957 bool IsWritable () { return writable; }
959
962 const char *ToStr (CString *ret, bool pathLocal = false); // semi-static, iff 'pathLocal' == true!!
964
976
977#ifndef SWIG
978
979 void GetValueState (CRcValueState *retValueState);
981
982 // Get value (relaxed typing) ...
983 ERcState GetValue (bool *retBool, TTicks *retTimeStamp = NULL);
991 ERcState GetValue (int *retInt, TTicks *retTimeStamp = NULL);
993 ERcState GetValue (float *retFloat, TTicks *retTimeStamp = NULL);
995 ERcState GetValue (CString *retString, TTicks *retTimeStamp = NULL);
999
1000 // Get value (relaxed typing with auto-correction) ...
1001 bool ValidBool (bool defaultVal = false, TTicks *retTimeStamp = NULL);
1005 int ValidInt (int defaultVal = 0, TTicks *retTimeStamp = NULL);
1007 float ValidFloat (float defaultVal = 0.0, TTicks *retTimeStamp = NULL);
1009 const char * ValidString (CString *ret, const char *defaultVal = CString::emptyStr, TTicks *retTimeStamp = NULL);
1011 TTicks ValidTime (TTicks defaultVal = 0, TTicks *retTimeStamp = NULL);
1013
1014 int ValidTrigger (int defaultVal = 0, TTicks *retTimeStamp = NULL) { return ValidInt (defaultVal, retTimeStamp); }
1016 const char * ValidMutex (CString *ret, const char *defaultVal = CString::emptyStr, TTicks *retTimeStamp = NULL) { return ValidString (ret, defaultVal, retTimeStamp); }
1018
1019 int ValidUnitInt (ERcType _type, int defaultVal = 0, TTicks *retTimeStamp = NULL);
1021 float ValidUnitFloat (ERcType _type, float defaultVal = 0.0, TTicks *retTimeStamp = NULL);
1023 int ValidEnumIdx (ERcType _type, int defaultVal = 0, TTicks *retTimeStamp = NULL);
1025
1026#endif
1027
1028 // Get attributes ...
1029 ERcType Type () const { return ATOMIC_READ (valueState.type); }
1030 ERcState State () const { return ATOMIC_READ (valueState.state); }
1031 TTicks TimeStamp () const { return ATOMIC_READ (valueState.timeStamp); }
1032
1033 bool IsValid () const { return ATOMIC_READ (valueState.state) == rcsValid; }
1035 bool IsBusy () const { return ATOMIC_READ (valueState.state) == rcsBusy; }
1037 bool IsKnown () const { return ATOMIC_READ (valueState.state) != rcsUnknown; }
1039
1040 bool Equals (const CRcValueState *vs2) { CRcValueState vs; GetValueState (&vs); return vs.Equals (vs2); }
1042 bool ValueEquals (const CRcValueState *vs2) { CRcValueState vs; GetValueState (&vs); return vs.ValueEquals (vs2); }
1044
1046
1060
1061 CResource *Subscribe (CRcSubscriber *subscr) { SubscribePAL (subscr); return this; }
1067 void Unsubscribe (CRcSubscriber *subscr) { UnsubscribePAL (subscr); }
1069
1071
1081
1082#ifndef SWIG
1083 void SetRequestFromObj (CRcRequest *_request);
1084 void SetRequest (CRcRequest *_request) { SetRequestFromObj (_request); }
1088 void SetRequest (CRcValueState *value, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1102 void SetRequest (bool valBool, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1104 void SetRequest (int valInt, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1106 void SetRequest (float valFloat, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1108 void SetRequest (const char *valString, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1110 void SetRequest (TTicks valTime, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1112 void SetRequestFromStr (const char *reqDef);
1115
1116 void SetTrigger (const char *reqGid, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks repeat = NEVER);
1118 void SetTriggerFromStr (const char *reqDef);
1120
1121 void DelRequest (const char *reqGid = NULL, TTicks t1 = NEVER);
1126
1127#endif // SWIG
1128
1129 bool GetRequestSet (CRcRequestSet *ret, bool allowNet = true);
1137 CRcRequest *GetRequest (const char *reqGid, bool allowNet = true);
1156
1158
1163
1164#ifndef SWIG
1165 void ReadValueState (CRcValueState *retValueState, TTicks maxTime = -1);
1169#endif
1170 void WriteValue (CRcValueState value, int priority = rcPrioNone, const char *reqGid = "write") { SetRequest (&value, reqGid, priority); }
1173 void UnWrite (const char *reqGid = "write") { DelRequest (reqGid); }
1174
1176
1177
1178 // ***** For drivers *****
1179
1182
1183#ifndef SWIG
1184 static CResource *Register (CRcDriver *_rcDriver, const char *_lid, ERcType _type, bool _writable, void *_data = NULL) { return Register (NULL, _rcDriver, _lid, _type, _writable, _data); }
1203 static CResource *Register (CRcDriver *_rcDriver, const char *_lid, const char *rcTypeDef, void *_data = NULL) { return Register (NULL, _rcDriver, _lid, rcTypeDef, _data); }
1207#endif
1208
1211 void SetDefault (bool valBool) { SetRequest (valBool, rcDefaultRequestId, rcPrioDefault); }
1212 void SetDefault (int valInt) { SetRequest (valInt, rcDefaultRequestId, rcPrioDefault); }
1213 void SetDefault (float valFloat) { SetRequest (valFloat, rcDefaultRequestId, rcPrioDefault); }
1214 void SetDefault (const char *valString) { SetRequest (valString, rcDefaultRequestId, rcPrioDefault); }
1215 void SetDefault (TTicks valTime) { SetRequest (valTime, rcDefaultRequestId, rcPrioDefault); }
1216
1217 void Unregister ();
1222
1224
1227 void SetUserData (void *_data) { ATOMIC_WRITE (rcUserData, _data); }
1229 void *UserData () { return ATOMIC_READ (rcUserData); }
1232
1241 void ReportValueState (const CRcValueState *_valueState);
1244#ifndef SWIG
1245 void ReportValue (bool _value, ERcState _state = rcsValid);
1246 void ReportValue (int _value, ERcState _state = rcsValid);
1247 void ReportValue (float _value, ERcState _state = rcsValid);
1248 void ReportValue (const char *_value, ERcState _state = rcsValid);
1249 void ReportValue (TTicks _value, ERcState _state = rcsValid);
1250#endif // SWIG
1253 void ReportState (ERcState _state) { CRcValueState vs; vs.SetState (_state); ReportValueState (&vs); }
1260
1264 void RedriveValue (bool force = true) { EvaluateRequests (force); }
1276
1277
1278 // ***** For info & directory services *****
1279
1282
1283#ifndef SWIG
1284 const char *GetInfo (CString *ret, int verbosity = 1, bool allowNet = true);
1293#endif
1294 void PrintInfo (FILE *f = stdout, int verbosity = 1, bool allowNet = true);
1295
1301 CRcSubscriber *GetLocalSubscriber (int n);
1302 void UnlockLocalSubscribers () { Unlock (); }
1303
1309 CRcRequest *GetLocalRequest (int n);
1310 void UnlockLocalRequests () { Unlock (); }
1311
1313
1314#ifndef SWIG
1315
1320
1321 class CRcHost *Host () { return ATOMIC_READ (rcHost); }
1322 class CRcDriver *Driver () { return ATOMIC_READ (rcDriver); }
1323
1324 unsigned RegSeq () { return ATOMIC_READ (regSeq); }
1328
1329 bool IsRegistered () { return (ATOMIC_READ (regSeq) & 1) == 1; }
1332 bool HasSubscribers () { return ATOMIC_READ (subscrList) != NULL; }
1334 bool HasRequests () { return ATOMIC_READ (requestList) != NULL; }
1336
1338
1339#endif
1340
1341
1342 // ***** Private *****
1343
1344 // Constructor/destructor (private!)...
1345 // Only this class itself is allowed to create or destroy new objects.
1346 // SWIG is the only reason why the con- & destructor are not declared private.
1347#ifndef SWIG // for not offering the constructor in the API
1348 CResource ();
1349 ~CResource ();
1350#endif
1351
1352 private:
1353
1354#ifndef SWIG
1355 friend void CResourceRequestsTimerCallback (CTimer *, void *);
1356 friend class CRcSubscriber;
1357 friend class CRcHost;
1358#endif
1359
1360 // Registration and life cycle management ...
1361 static CResource *GetUnregistered (const char *uri);
1362 void PutUnregistered ();
1363
1364 static CResource *Register (CRcHost *_rcHost, CRcDriver *_rcDriver, const char *_lid, ERcType _type, bool _writable, void *_data);
1365 // Generic & main registration method; used by all other 'Registration' variants
1366 static CResource *Register (CRcHost *_rcHost, CRcDriver *_rcDriver, const char *_lid, const char *rcTypeDef, void *_data);
1367 // Register with textual description; used by full textual registration (below) and for the "external" driver
1368 // Syntax of 'rcTypeDef': <type> (ro|wr)
1369 // returns 'NULL' on error and prints a warning
1370 static CResource *Register (const char *rcDef, void *_data);
1371 // Register with full textual description; used by 'rc_core' for remote resources
1372 // Syntax: <URI> <type> (ro|wr)
1373 // returns 'NULL' on error and prints a warning
1374
1375 // Value & state...
1376 const CRcValueState *ValueState () { return &valueState; } // 'this' must be locked as long as the returned value is accessed
1377
1378 // Reading values...
1379 void SubscribePAL (CRcSubscriber *subscr, bool resLocked = false, bool subLocked = false);
1380 // 'resLocked' and 'subLocked' must be set if a lock on the resource or subscription is already held.
1381 // The method may temporarily release a lock to avoid deadlocks.
1382 void UnsubscribePAL (CRcSubscriber *subscr, bool resLocked = false, bool subLocked = false);
1383 // 'resLocked' and 'subLocked' must be set if a lock on the resource or subscription is already held.
1384 // The method may shortly release a lock to avoid deadlocks.
1385
1386 // Requests...
1387 void UpdatePersistentRequestAL (const char *reqId, CRcRequest *req);
1388 bool DoDelRequestAL (CRcRequest **pList, const char *reqGid, TTicks t1, bool updatePersistence);
1389 bool DelRequestNoEvaluate (const char *reqGid, TTicks t1);
1390 void SetRequestFromObjNoEvaluate (CRcRequest *_request);
1391
1392 CRcRequest *GetWinningRequest (TTicks t);
1393 void EvaluateRequests (bool force = false); // check and process all pending requests
1394
1395 // Drivers ...
1396 // The '...AL' method variants assume that the resource has already been locked by the caller.
1397 void NotifySubscribers (int evType, const char *evAttr = NULL);
1398 void NotifySubscribersAL (int evType, const char *evAttr = NULL); // 'evType' is effectively of type 'ERcEventType'
1399 void ReportNetLost ();
1400 // Report that the network connection to the server was lost (like 'ReportUnknown' but
1401 // with different time stamp behaviour; see above).
1402
1403 void ReportValueStateAL (const CRcValueState *_valueState, TTicks _timeStamp = 0);
1404 void ReportUnknownAL () { CRcValueState vs (Type ()); ReportValueStateAL (&vs); }
1405
1406 // Driving values to the real device...
1407 void DriveValue (CRcValueState *vs, bool force);
1408 // Propagate a new requested value to the driver (to make that happen in the real device).
1409 // 'force == true': Call the driver function in any case, not only on a true VS change
1410
1411 // Helpers...
1412 void Lock () { mutex.Lock (); }
1413 void Unlock () { mutex.Unlock (); }
1414
1415
1416 // BEGIN static data (never changed after the initialization of the object)...
1417 // No locking required.
1418 CString gid; // aka URI
1419
1420 // BEGIN semi-static data ...
1421 // Fields marked with "[atomic]" must be accessed using the 'ATOMIC_*' macros on each write access and on read accesses if'this' is not locked.
1422 // Fields marked with "[mutex]" may only be accessed if 'this' is locked.
1423 // The consistency of all semi-static data as a whole is protected by the sequence lock 'regSeq'.
1424
1425 // Resource identification...
1426 class CRcHost *rcHost; // [atomic] 'NULL' => local resource or unregistered
1427 class CRcDriver *rcDriver; // [atomic] 'NULL' => remote resource or unregistered
1428 void *rcUserData; // optional user data that can be used by the driver (driver cares for concurrent access)
1429 const char *lid; // [atomic] local resources: relative path without driver; remote: with driver name as first component; points into 'gid.Get ()'.
1430
1431 // Resource properties...
1432 unsigned regSeq; // [atomic]
1433 bool writable, persistent; // (not "atomic" since only one byte is relevant)
1434
1435 // BEGIN dynamic data ...
1436 // All fields may only be accessed if 'this' is locked.
1437
1438 // Current value, its type, and its state...
1439 CRcValueState valueState; // only state and value are dynamic; 'valueState.type' is semi-static (not "atomic" since only one byte is relevant)
1440
1441 // Internal...
1442 // 'CResource' objects are managed by a 'CDict' associated with a driver (local resources) or
1443 // host (remote resources).
1444 CMutex mutex; // protects 'this' including the request list
1445 CRcRequest *requestList;
1446 CTimer requestTimer; // timer for the next evaluation of requests
1447 CRcSubscriberLink *subscrList;
1448};
1449
1450
1451// Python extensions...
1452#ifdef SWIG
1453%extend CResource {
1454 %newobject __str__ ();
1455 const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1456 %newobject __repr__ ();
1457 const char *__repr__ () { CString s, s2; s.SetF ("(CResource) %s", $self->ToStr (&s2)); return s.Disown (); }
1458 bool __eq__ (CResource *other) { return $self == other; }
1459 bool __ne__ (CResource *other) { return $self != other; }
1460
1461 %delobject SetRequestFromObj ();
1462
1463 %feature("docstring") ValueState "Get the current value and state of the resource."
1464 %newobject ValueState ();
1465 CRcValueState *ValueState () { CRcValueState *ret = new CRcValueState (); $self->GetValueState (ret); return ret; }
1466
1467 void _SetRequestFromObj (CRcRequest *_request) { $self->SetRequestFromObj (_request); }
1468 void _DelRequest (const char *reqGid = NULL, TTicks t1 = NEVER) { $self->DelRequest (reqGid, t1); }
1469
1470 %pythoncode %{
1471 pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
1472
1473 def Value (self):
1474 """Get a value ('None' if invalid) of this resource (use ValueState() to get the complete value and state)."""
1475 return self.ValueState ().Value ()
1476
1477 def ValidValue (self, defaultVal):
1478 """Get a valid value of this resource (use ValueState() to get the complete value and state)."""
1479 return self.ValueState ().ValidValue (defaultVal)
1480
1481 def SetRequest (self, reqDef = None, attrs = None, value = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
1482 """Set or delete a request with selected attributes.\n\
1483 \n\
1484 This method allows to set any subset of attributes in a flexible way, either by (named) function arguments\n\
1485 or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
1486 \n\
1487 If the effective value is 'None' (no value is passed), the call will delete the request with\n\
1488 the specified ID passing 'delDelay' as the 't1' argument of DelRequest().\n\
1489 \n\
1490 See RcSetRequest() for a detailed explanation of the arguments and examples.\n\
1491 """
1492 if RcTypeIsStringBased (self.Type ()) and reqDef != None:
1493 print ("WARNING: Setting a request to the string-type resource '" + str(self) + "' using the 'reqDef' argument is ambiguous!")
1494 req = CRcRequest ()
1495 req.Set (reqDef = reqDef, attrs = attrs, value = value, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
1496 if req.Value ().IsKnown ():
1497 req.thisown = 0 # tell swig to disown the object ([2021-01-03]: '%delobject SetRequestFromObj ()' silently does not work)
1498 self._SetRequestFromObj (req)
1499 else:
1500 self.DelRequest (req.Gid (), delDelay)
1501
1502 def SetTrigger (self, attrs = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
1503 """Set a request for a trigger resource with selected attributes."""
1504 req = CRcRequest ()
1505 req.Set (value = 1, attrs = attrs, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
1506 req.thisown = 0 # tell swig to disown the object ([2021-01-03]: '%delobject SetRequestFromObj ()' silently does not work)
1507 self._SetRequestFromObj (req)
1508
1509 def DelRequest (self, reqId = None, t1 = None):
1510 """Delete a request by its ID."""
1511 if t1 == None: self._DelRequest (reqId)
1512 else: self._DelRequest (reqId, TicksAbsOf (t1))
1513
1514 def ReportValue (self, value, state = rcsValid):
1515 """Report a new value and optionally its state. If '_value == None', 'ReportUnknown()' is called."""
1516 if value == None: self.ReportUnknown ()
1517 else: self.ReportValueState (CRcValueState (self.Type (), value, state))
1518
1519 %}
1520}; // %extend CResource
1521#endif
1522
1523
1525#ifdef SWIG
1526%pythoncode %{
1527## @}
1528%}
1529#endif // SWIG
1530
1531
1532
1533
1534
1535// *************************** Events ******************************************
1536
1537
1552#ifdef SWIG
1553%pythoncode %{
1554## @addtogroup resources_subscribe
1555## @{
1556%}
1557#endif // SWIG
1558
1559
1563
1565
1570
1573
1574
1575
1576// ***** CRcEvent *****
1577
1578
1583#ifdef SWIG
1584%feature("docstring") CRcEvent "Resource events delivered by a subscriber or to a driver.\n\n"
1585 "Possible event types are:\n"
1586 " rceTimer: Timer alarm.\n"
1587 " rceValueStateChanged: The resource has changed its value.\n"
1588 " rceRequestChanged: A request has been changed or deleted. The 'ValueState ()'\n"
1589 " attribute indicates the affected request ID (type is string).\n"
1590 " rceDisconnected: The connection to the (remote) resource has\n"
1591 " been lost.\n"
1592 " rceConnected: The connection to the (remote) resource has\n"
1593 " been established (again).\n"
1594 " rceDriveValue: Drive a value (for drivers).\n"
1595 " rceNone: Nothing (dummy event: ignore).\n"
1596 "The attribute 'MorePending ()' indicates whether more events are waiting for the\n"
1597 "same subscriber. This can be used for performance optimizations to avoid\n"
1598 "unecessary recomputations."
1599#endif
1601 public:
1602 CRcEvent (ERcEventType _type = rceNone, CResource *_resource = NULL, CRcValueState *_valueState = NULL, void *_data = NULL) { Set (_type, _resource, _valueState, _data); }
1603
1606 void Clear () { Set (); }
1607 void Set (ERcEventType _type = rceNone, CResource *_resource = NULL, CRcValueState *_valueState = NULL, void *_data = NULL);
1617
1618 void SetType (ERcEventType _type) { type = _type; }
1619 void SetResource (CResource *_resource) { resource = _resource; }
1620 void SetValueState (CRcValueState *_valueState);
1621 void SetData (void *_data) { data = _data; }
1623
1626 ERcEventType Type () { return type; }
1627 CResource *Resource () { return resource; }
1628 CRcValueState *ValueState () { return &valueState; }
1630 void *Data () { return data; }
1632
1635 const char *ToStr (CString *ret);
1637
1638 protected:
1639 friend class CRcEventProcessor;
1640
1641 ERcEventType type; // event type
1642 CResource *resource;
1643 CRcValueState valueState; // a) value + state for 'rceValueStateChanged'
1644 // b) value for 'rceDriveValue'
1645 // c) request ID for 'rceRequestChanged'
1646 void *data; // user data
1647
1648 bool morePending; // After 'PollEvent'/'WaitEvent' indicates whether more events are pending for
1649 // the current subscriber to allow for optimized processing afterwards.
1650 // Note: This should only be used if either all or no events are processed by callbacks.
1651
1652 CRcEvent *next;
1653};
1654
1655
1656// Python extension...
1657#ifdef SWIG
1658%extend CRcEvent {
1659 %newobject __str__ ();
1660 const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1661 %newobject __repr__ ();
1662 const char *__repr__ () { CString s, s1; s.SetF ("(CRcEvent) %s", $self->ToStr (&s1)); return s.Disown (); }
1663}
1664#endif
1665
1666
1667
1668// ***** CRcEventProcessor *****
1669
1670
1671typedef bool FRcEventFunc (class CRcEventProcessor *, CRcEvent *, void *);
1674
1675
1687 public:
1688 CRcEventProcessor (bool _inSelectSet = false);
1689 virtual ~CRcEventProcessor ();
1690
1693 void PutEvent (CRcEvent *ev);
1695
1696#ifndef SWIG
1697
1709 bool WaitEvent (CRcEvent *ev, TTicks *maxTime = NULL);
1722 void Interrupt ();
1723 void FlushEvents ();
1726
1739 virtual bool OnEvent (CRcEvent *ev);
1744 void SetCbOnEvent (FRcEventFunc *_cbEvent, void *_cbEventData = NULL);
1745 void ClearCbOnEvent () { SetCbOnEvent (NULL, NULL); }
1747
1748#endif // SWIG
1749
1752 void SetInSelectSet (bool _inSelectSet);
1754 bool InSelectSet () { return inSelectSet; }
1755
1756 static CRcEventProcessor *Select (TTicks maxTime = -1);
1769 // TBD: Implement 'InterruptSelect' to interrupt a waiting 'Select'
1770
1771 virtual const char *TypeId () { return CString::emptyStr; }
1772 virtual const char *InstId () { return CString::emptyStr; }
1774
1777 const char *ToStr (CString *ret) { return StringF (ret, "%s:%s", TypeId (), InstId ()); }
1779
1780 private:
1781
1782 // Internal helpers ...
1783 bool DoPollEventAL (CRcEvent *ev);
1784
1785 void DeleteFirstEventAL ();
1786
1787 void LinkAL ();
1788 void UnlinkAL ();
1789 bool IsLinkedAL () { return next || pLastProc == &next; }
1790
1791 // Dynamic data (protected by 'globMutex')...
1792 static CMutex globMutex; // protects dynamic data of all event processors
1793 static CCond globCond; // global condition variable for 'Select'
1794 CCond cond; // per-object condition variable for 'WaitEvent', mutex is 'globMutex'
1795 volatile bool interrupted; // used (only) in 'WaitEvent' and 'Interrupt'
1796
1797 FRcEventFunc *cbEvent;
1798 void *cbEventData;
1799
1800 CRcEvent *firstEv, **pLastEv; // linked list with efficient appending
1801
1802 bool inSelectSet;
1803 static CRcEventProcessor *firstProc, **pLastProc; // linked list of event processors with pending events
1804 CRcEventProcessor *next; // 'next' pointer for 'firstProc'/'pLastProc' list
1805};
1806
1807
1808// Python extension...
1809#ifdef SWIG
1810%extend CRcEventProcessor {
1811 %newobject __str__ ();
1812 const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1813 %newobject __repr__ ();
1814 const char *__repr__ () { CString s, s1; s.SetF ("(CRcEventProcessor) %s", $self->ToStr (&s1)); return s.Disown (); }
1815
1816 %newobject PollEvent ();
1817 CRcEvent *PollEvent () {
1818 CRcEvent ev, *ret;
1819 if (!$self->PollEvent (&ev)) return NULL;
1820 ret = new CRcEvent ();
1821 *ret = ev;
1822 //~ INFOF (("### Python: Pollevent () -> %08x", ret));
1823 return ret;
1824 }
1825}; // %extend CRcEventProcessor
1826#endif
1827
1828
1829
1830
1831
1832// ***** CRcEventTimer *****
1833
1834
1835#ifdef SWIG
1836%warnfilter(401) CRcEventTimer; // class 'CTimer' is not known to SWIG
1837#endif
1838
1841 public:
1842 CRcEventTimer (const char *_id, void *_data = NULL) { id.Set (_id); Set (_data); }
1843 CRcEventTimer (TTicks _time, TTicks _interval = 0, void *_data = NULL) { Set (_time, _interval, _data); }
1844
1845 void Set (void *_data) { CTimer::Set (NULL, _data, NULL); }
1847 void Set (TTicks _time, TTicks _interval = 0, void *_data = NULL) { CTimer::Set (_time, _interval, NULL, _data, NULL); }
1849
1850 virtual void OnTime () { CRcEvent ev (rceTimer, NULL, NULL, data); PutEvent (&ev); }
1851
1852 virtual const char *TypeId () { return "T"; } // hint for Python/SWIG API
1853 virtual const char *InstId () { return id.Get (); } // hint for Python/SWIG API
1854
1855 protected:
1856 CString id;
1857};
1858
1859
1861#ifdef SWIG
1862%pythoncode %{
1863## @}
1864%}
1865#endif // SWIG
1866
1867
1868
1869
1870
1871// *************************** Subscribers *************************************
1872
1873
1878#ifdef SWIG
1879%pythoncode %{
1880## @addtogroup resources_subscribe
1881## @{
1882%}
1883#endif // SWIG
1884
1885
1886
1900#ifdef SWIG
1901%feature("docstring") CRcSubscriber "Subscription to any number of resources.\n\n"
1902 "A subscriber monitors any number of resources. The resources can be\n"
1903 "specified by their real URIs or alias names. Wildcards as well as\n"
1904 "presently unkown resources are allowed. Events can be fetched using\n"
1905 "'Select ()' and 'PollEvent'.\n"
1906#endif
1908 public:
1909 CRcSubscriber () { resourceList = NULL; }
1910 CRcSubscriber (const char *_lid) { resourceList = NULL; Register (_lid); }
1911 virtual ~CRcSubscriber () { Unregister (); }
1912
1915 bool Register (const char *_lid);
1918 void Unregister ();
1921
1924 const char *Lid () { return lid.Get (); }
1925 const char *Gid () { return gid.Get (); }
1926
1927 virtual const char *TypeId () { return "S"; } // hint for Python/SWIG API
1928 virtual const char *InstId () { return Lid (); } // hint for Python/SWIG API
1929
1930 const char *ToStr (CString *ret);
1931
1932 bool IsEmpty () { return resourceList == NULL && watchSet.Entries () == 0; }
1934
1937 CResource *AddResource (CResource *rc);
1938 CResource *AddResources (const char *pattern);
1955 void DelResource (CResource *rc);
1956 void DelResources (const char *pattern);
1967 void Clear ();
1970
1973 CResource *Subscribe (CResource *rc) { return AddResource (rc); }
1974 CResource *Subscribe (const char *uri) { return AddResources (uri); }
1975 void Unsubscribe (CResource *rc) { DelResource (rc); }
1976 void Unsubscribe (const char *pattern) { DelResources (pattern); }
1978
1981#ifndef SWIG
1982 void GetInfo (CString *ret, int verbosity = 1);
1984 static void GetInfoAll (CString *ret, int verbosity = 1);
1986 void GetPatternSet (CKeySet *retPatternSet);
1988#endif // #ifndef SWIG
1989 void PrintInfo (FILE *f = stdout, int verbosity = 1);
1991
1992 protected:
1993 friend class CResource;
1994 friend class CRcServer;
1995
1996 // Locking...
1997 void Lock () { mutex.Lock (); } // INFOF (("# Thread #%08x: CRcSubscriber::Lock ()", pthread_self ()));
1998 void Unlock () { mutex.Unlock (); } // INFOF (("# Thread #08x: CRcSubscriber::Unlock ()", pthread_self ()));
1999
2000 // Notifications from resource...
2001 void CheckNewResource (CResource *resource); // check if new resource fits a watch pattern and eventually adds it
2002 void UnlinkResourceAL (CResource *resource); // remove a resource and adds its name to the watch set (for temporarilly unregistered resources); Assumes that 'resource' is already locked for us.
2003 void NotifyAL (CRcEvent *ev) { PutEvent (ev); } // process an event from a resource; caller remains owner of 'ev'
2004
2005 // Interaction with network server...
2006 void RegisterAsAgent (const char *_gid);
2007 // Alternative to 'Register' - register as an agent for some other (remote client) host.
2008 bool IsAgent () { return lid.Get () == gid.Get (); } // subscriber is an agent
2009
2010 // Static data...
2011 CString lid, gid;
2012
2013 // Dynamic data (protected by the mutex)...
2014 CMutex mutex;
2015 CResourceLink *resourceList;
2016 CKeySet watchSet; // contains URI patterns to be checked if new resources are registered
2017};
2018
2019
2020// Python extension...
2021#ifdef SWIG
2022%extend CRcSubscriber {
2023 %newobject __str__ ();
2024 const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
2025 %newobject __repr__ ();
2026 const char *__repr__ () { CString s, s1; s.SetF ("(CRcSubscriber) %s", $self->ToStr (&s1)); return s.Disown (); }
2027}; // %extend CRcSubscriber
2028#endif
2029
2030
2032#ifdef SWIG
2033%pythoncode %{
2034## @}
2035%}
2036#endif // SWIG
2037
2038
2039
2040
2041
2042// *************************** Requests ****************************************
2043
2044
2047#ifdef SWIG
2048%pythoncode %{
2049## @addtogroup resources_requests
2050## @{
2051%}
2052#endif // SWIG
2053
2054
2055const char *RcGetUserRequestId ();
2059
2060
2071#ifdef SWIG
2072%feature("docstring") CRcRequest "Request specifications.\n\n"
2073 "Request objects define the request for a certain value together with some\n"
2074 "additional attributes. The concept of requests is introduced to deal with\n"
2075 "potentially concurrent write accesses to resources. Besides the requested\n"
2076 "value, a request has the following attributes:\n"
2077 " - a unique GID by which it can be later be changed or deleted.\n"
2078 " - a priority (see also: comments on the 'prio*' constants)\n"
2079 " - a start (on) time (optional)\n"
2080 " - an expiration (off) time (optional)\n"
2081 " - a hysteresis to avoid too frequent value changes (optional)"
2082#endif
2084 public:
2085 CRcRequest () { Reset (); }
2086#ifndef SWIG
2087 CRcRequest (CRcRequest *req) { Reset (); Set (req); }
2089 CRcRequest (CRcValueState *_value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks repeat = NEVER, TTicks _hysteresis = NEVER) { Reset (); Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2091 CRcRequest (bool _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks repeat = NEVER, TTicks _hysteresis = NEVER) { Reset (); Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2093 CRcRequest (int _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks repeat = NEVER, TTicks _hysteresis = NEVER) { Reset (); Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2095 CRcRequest (float _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks repeat = NEVER, TTicks _hysteresis = NEVER) { Reset (); Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2097 CRcRequest (const char *_value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks repeat = NEVER, TTicks _hysteresis = NEVER) { Reset (); Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2099 CRcRequest (TTicks _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks repeat = NEVER, TTicks _hysteresis = NEVER) { Reset (); Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2101#endif // SWIG
2102
2103 ~CRcRequest () {}
2104
2107
2108 void Reset ();
2111
2112 void Set (CRcRequest *req);
2114 void Set (CRcValueState *_value = NULL, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2128#ifndef SWIG
2129 void Set (bool _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2130 void Set (int _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2131 void Set (float _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2132 void Set (const char *_value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2133 void Set (TTicks _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2134#endif // SWIG
2135
2136 void SetValue (CRcValueState *_value);
2137 void SetValue (bool _value);
2138 void SetValue (int _value);
2139 void SetValue (float _value);
2140 void SetValue (const char *_value);
2141 void SetValue (TTicks _value);
2142
2143 void SetGid (const char *_gid) { gid.Set (_gid); }
2144
2145 void SetPriority (int _priority) { priority = _priority; }
2146 void SetTimeOn (TTicks _t0) { t0 = _t0; }
2147 void SetTimeOff (TTicks _t1) { t1 = _t1; }
2148 void SetRepeat (TTicks _repeat) { repeat = _repeat; }
2149 void SetHysteresis (TTicks _hysteresis) { hysteresis = _hysteresis; }
2150
2154
2157 void Convert (CResource *rc, bool warn = true);
2161
2164
2165 bool IsCompatible () { return isCompatible; }
2167 const char *Gid () { return gid.Get (); }
2170 const char *Origin () { return origin.Get (); }
2175
2176 ERcType Type () { return value.Type (); }
2177 CRcValueState *Value () { return &value; }
2178 int Priority () { return priority; }
2179 TTicks TimeOn () { return t0; }
2180 TTicks TimeOff () { return t1; }
2181 TTicks Repeat () { return repeat; }
2182 TTicks Hysteresis () { return hysteresis; }
2183
2185
2188
2189 bool SetFromStr (const char *str);
2199
2200 bool SetAttrsFromStr (const char *str);
2235
2236 const char *ToStr (CString *ret, bool precise = true, bool tabular = false, TTicks relativeTimeThreshold = NEVER, const char *skipAttrs = CString::emptyStr);
2253
2255
2256 protected:
2257 friend class CResource;
2258
2259 void SetOrigin ();
2260 bool SetSingleAttrFromStr (const char *str);
2261
2262 // Fields...
2263 bool isCompatible;
2264 CString gid, origin;
2265 CRcValueState value;
2266 int priority;
2267 TTicks t0, t1; // start and end time (NEVER = not set); t0 == t1 => value is set once (and may then stay)
2268 TTicks repeat; // repeat interval (ignored, if t0 == 0)
2269 TTicks hysteresis; // hysteresis in milliseconds
2270
2271 // Internal fields...
2272 // Requests are managed as a linked list associated with a 'CResource' object.
2273 CRcRequest *next;
2274};
2275
2276
2277// Python extension...
2278
2279#ifdef SWIG
2280%extend CRcRequest {
2281
2282 %newobject __str__ ();
2283 const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
2284 %newobject __repr__ ();
2285 const char *__repr__ () { CString s, s1; s.SetF ("(CRcRequest) %s", $self->ToStr (&s1)); return s.Disown (); }
2286 %pythoncode %{
2287 pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
2288
2289 ## Versatile setter.
2290 def Set (self, reqDef = None, attrs = None, value = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
2291 """Set value and/or selected request attributes.\n\
2292 \n\
2293 This method allows to set any subset of attributes in a flexible way, either by (named) function arguments\n\
2294 or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
2295 \n\
2296 See RcSetRequest() for a detailed explanation of the arguments and examples.\n\
2297 """
2298 if reqDef != None:
2299 if isinstance (reqDef, str): self.SetFromStr (reqDef)
2300 elif value == None: value = reqDef
2301 if attrs != None: self.SetAttrsFromStr (attrs)
2302 if value != None: self.SetValue (value)
2303 if id != None: self.SetGid (id)
2304 if priority != None: self.SetPriority (priority)
2305 if t0 != None:
2306 ticks = TicksAbsOf (t0)
2307 if ticks: self.SetTimeOn (ticks)
2308 else: print ("WARNING: Invalid time specification '" + str(t0) + "' - ignoring!")
2309 if t1 != None:
2310 ticks = TicksAbsOf (t1)
2311 if ticks: self.SetTimeOff (ticks)
2312 else: print ("WARNING: Invalid time specification '" + str(t1) + "' - ignoring!")
2313 if repeat != None:
2314 ticks = TicksRelOf (repeat)
2315 if ticks: self.SetRepeat (ticks)
2316 else: print ("WARNING: Invalid time specification '" + str(repeat) + "' - ignoring!")
2317 if hysteresis != None: self.SetHysteresis (hysteresis)
2318
2319 %} // %pythoncode
2320}; // %extend CRcRequest
2321#endif
2322
2323
2324const char *RcGetUserRequestId ();
2326const char *RcGetUserRequestAttrs ();
2328
2329
2331#ifdef SWIG
2332%pythoncode %{
2333## @}
2334%}
2335#endif // SWIG
2336
2337
2338
2339
2340
2341// *************************** Drivers *****************************************
2342
2343
2364#ifdef SWIG
2365%pythoncode %{
2366## @addtogroup resources_drivers
2367## @{
2368%}
2369#endif // SWIG
2370
2371
2372#ifndef SWIG
2373
2374
2377
2378 // For linking in C drivers...
2379 rcdOpInit = 0,
2388
2389 // Using a base-class 'CRcDriver' object to drive something...
2390 rcdOpStop,
2397
2398
2406
2407
2408#define HOME2L_DRIVER(NAME) \
2409 extern "C" { void Home2lRcDriverFunc_##NAME (ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *); } \
2410 void Home2lRcDriverFunc_##NAME
2446
2447
2457class CRcDriver {
2458 public:
2459 CRcDriver (const char *_lid, FRcDriverFunc *_func = NULL) { lid.Set (_lid); func = _func; }
2460 virtual ~CRcDriver () {}
2461
2464 void Register ();
2468 static void RegisterAndInit (const char *_lid, FRcDriverFunc *_func);
2470 void Unregister ();
2475
2478 const char *Lid () { return lid.Get (); }
2479 const char *ToStr (CString *) { return lid.Get (); }
2481
2484 CResource *RegisterResource (const char *rcLid, ERcType _type, bool _writable, void *_data = NULL) { return CResource::Register (this, rcLid, _type, _writable, _data); }
2485 CResource *RegisterResource (const char *rcLid, const char *rcTypeDef, void *_data = NULL) { return CResource::Register (this, rcLid, rcTypeDef, _data); }
2491 void PrintInfo (FILE *f = stdout);
2492
2493 CResource *GetResource (const char *rcLid) { return resourceMap.Get (rcLid); }
2494
2495 int LockResources () { Lock (); return resourceMap.Entries (); }
2496 CResource *GetResource (int n) { return resourceMap.Get (n); }
2497 void UnlockResources () { Unlock (); }
2499
2500 protected:
2501 friend class CResource;
2502 friend void RcDriversStop ();
2503
2506 virtual void Stop ();
2509 virtual void DriveValue (CResource *rc, CRcValueState *vs);
2541
2544 void Lock () { mutex.Lock (); }
2545 void Unlock () { mutex.Unlock (); }
2546
2547 void ClearResources ();
2549
2550 // Static data...
2551 CString lid;
2552 FRcDriverFunc *func;
2553
2554 // Dynamic data (protected by the mutex)...
2555 CMutex mutex;
2556 CDictRef<CResource> resourceMap; // object does not own the resources; when deleted here, they must be unregistered manually.
2557};
2558
2559
2560#endif // #ifndef SWIG
2561
2562
2563#ifdef SWIG
2564%warnfilter(401) CRcEventDriver; // class 'CRcDriver' is not known to SWIG
2565#endif
2566
2567
2573class CRcEventDriver: public CRcDriver, public CRcEventProcessor {
2574 public:
2575 CRcEventDriver (const char *_lid, ERcState _successState = rcsBusy): CRcDriver (_lid) { successState = _successState; }
2583
2584#ifndef SWIG
2585 virtual const char *TypeId () { return "D"; } // hint for Python/SWIG API
2586 virtual const char *InstId () { return Lid (); } // hint for Python/SWIG API
2587
2588 protected:
2589 virtual void Stop () {}
2590 virtual void DriveValue (CResource *rc, CRcValueState *vs);
2591
2592 ERcState successState;
2593#endif
2594};
2595
2596
2598#ifdef SWIG
2599%pythoncode %{
2600## @}
2601%}
2602#endif // SWIG
2603
2604
2605
2606
2607
2608// ************ Directory operations and host/driver/resource lookup ***********
2609
2610
2617#ifdef SWIG
2618%pythoncode %{
2619## @addtogroup resources_directory
2620## @{
2621%}
2622#endif // SWIG
2623
2624
2625
2626// ***** Hosts *****
2627
2628
2631
2632int RcGetHosts ();
2633CRcHost *RcGetHost (int n);
2634
2635CRcHost *RcGetHost (const char *id);
2636const char *RcGetHostId (CRcHost *host);
2637
2639#ifndef SWIG
2640extern CString localHostId;
2641#endif
2642static inline const char *RcLocalHostId () { return localHostId.Get (); }
2643#ifdef SWIG
2644%pythoncode %{
2645 pass
2646
2647 ## Return a list of all known hosts (including our own one as #0).
2648 def RcHosts ():
2649 """Return a list of all known hosts (including our own one as #0)."""
2650 num = RcGetHosts ()
2651 ret = [ RcLocalHostId () ]
2652 for i in range (num):
2653 ret += [ RcGetHostId (RcGetHost (i)) ]
2654 return ret
2655%}
2656#endif
2657
2659
2660
2661
2662// ***** Drivers (local) *****
2663
2664
2667
2668int RcGetDrivers ();
2669CRcDriver *RcGetDriver (int n);
2670
2671CRcDriver *RcGetDriver (const char *lid);
2672const char *RcGetDriverId (CRcDriver *cur);
2673
2674#ifdef SWIG
2675%pythoncode %{
2676 pass
2677
2678 ## Return a list of all locally defined drivers.
2679 def RcDrivers ():
2680 """Return a list of all locally defined drivers."""
2681 num = RcGetDrivers ()
2682 ret = []
2683 for i in range (num):
2684 ret += [ RcGetDriverId (RcGetDriver (i)) ]
2685 return ret
2686%}
2687#endif
2688
2690
2691
2692
2693// ***** Resources *****
2694
2695
2698
2699int RcLockHostResources (CRcHost *host);
2705CResource *RcGetHostResource (CRcHost *host, int n);
2706void RcUnlockHostResources (CRcHost *host);
2707
2708int RcLockDriverResources (CRcDriver *driver);
2713CResource *RcGetDriverResource (CRcDriver *driver, int n);
2714void RcUnlockDriverResources (CRcDriver *driver);
2715
2716#ifdef SWIG
2717%pythoncode %{
2718 pass
2719
2720 ## Return all known resources of a remote host.
2721 def RcHostResources (hostName):
2722 """Return all known resources of a host. '/local' is an alias for the local host ID."""
2723 ret = []
2724 if hostName == RcLocalHostId () or hostName == "/local":
2725 for d in RcDrivers ():
2726 ret += RcDriverResources (d)
2727 else:
2728 h = RcGetHost (hostName)
2729 num = RcLockHostResources (h)
2730 for i in range (num):
2731 ret += [ RcGetHostResource (h, i).Uri () ]
2732 RcUnlockHostResources (h)
2733 return ret
2734
2735 ## Return all local resources managed by a driver.
2736 def RcDriverResources (driverName):
2737 """Return all local resources managed by a driver."""
2738 d = RcGetDriver (driverName)
2739 num = RcLockDriverResources (d)
2740 ret = []
2741 for i in range (num):
2742 ret += [ RcGetDriverResource (d, i).Uri () ]
2743 RcUnlockDriverResources (d)
2744 return ret
2745
2746 ## Return a complete list of all known resources.
2747 def RcResources ():
2748 """Return a complete list of all known resources."""
2749 ret = []
2750 for d in RcDrivers ():
2751 ret += RcDriverResources (d)
2752 for h in RcHosts ():
2753 ret += RcHostResources (h)
2754 return ret
2755
2756%}
2757#endif // SWIG
2758
2760
2761
2762
2763// ***** Subscribers *****
2764
2765
2768
2769#ifndef SWIG
2770int RcLockSubscribers ();
2775CRcSubscriber *RcGetSubscriber (int n);
2776void RcUnlockSubscribers ();
2777#endif
2778
2780
2781
2782// Requests and per-resource subscribers: see 'class CResource'
2783
2784
2786#ifdef SWIG
2787%pythoncode %{
2788## @}
2789%}
2790#endif // SWIG
2791
2792
2793
2794
2795
2796
2797// *************************** High-level API **********************************
2798
2799
2800// ***** General functions *****
2801
2802
2805#ifdef SWIG
2806%pythoncode %{
2807## @addtogroup resources_general
2808## @{
2809%}
2810#endif // SWIG
2811
2812
2813#ifndef SWIG
2814
2815
2818void RcInit (bool enableServer = false, bool inBackground = false);
2827void RcStart ();
2830void RcDone ();
2834
2841void RcIterate ();
2843int RcRun (bool catchSignals = true);
2848void RcStop ();
2852
2853#endif
2854
2855
2856
2857// ***** Looking up resources *****
2858
2859
2862#ifdef SWIG
2863%pythoncode %{
2864## @name Accessing resources ...
2865## @{
2866%}
2867#endif // SWIG
2868
2869
2870#ifdef SWIG
2871%feature("docstring") RcGetResource "Lookup a resource by its URI and return a reference to it."
2872%feature("docstring") RcGet "Lookup a resource by its URI and return a reference to it (shortcut for 'RcGetResource()')."
2873#endif
2874
2875static inline CResource *RcGetResource (const char *uri, bool allowWait = false) { return CResource::Get (uri, allowWait); }
2888static inline CResource *RcGet (const char *uri, bool allowWait = false) { return CResource::Get (uri, allowWait); }
2890
2892static inline void RcGarbageCollection () { CResource::GarbageCollection (); }
2897void RcBump (CResource *rc = NULL, bool soft = false);
2906
2907
2909#ifdef SWIG
2910%pythoncode %{
2911## @}
2912%}
2913#endif // SWIG
2914
2915
2916
2917// ***** Subscriptions *****
2918
2919
2922#ifdef SWIG
2923%pythoncode %{
2924## @name Subscriptions (from C/C++ API) ...
2925## Low-level operations to directly create and use @ref CRcSubscriber objects.
2926## Most probably, you will not need these functions.
2927## The preferred way in Python is to use the more compfortable decorators and
2928## operations in section "Subscriptions, events and timers (Python API)" below.
2929## @{
2930%}
2931#endif // SWIG
2932
2933
2934#ifdef SWIG
2935%feature("docstring") RcNewSubscriber "Create and register a new subscriber object, optionally subscribe to resources."
2936%feature("docstring") RcUnsubscribeFromAll "Unsubscribe to all resources managed by the subscriber."
2937%newobject RcNewSubscriber (const char *, CResource *);
2938%newobject RcNewSubscriber (const char *, const char *);
2939#endif
2940
2941CRcSubscriber *RcNewSubscriber (const char *subscrLid, CResource *rc = NULL);
2946CRcSubscriber *RcNewSubscriber (const char *subscrLid, const char *pattern);
2951
2952static inline CRcSubscriber *RcSubscribe (CRcSubscriber *subscr, CResource *rc) { subscr->AddResource (rc); return subscr; }
2954static inline CRcSubscriber *RcSubscribe (CRcSubscriber *subscr, const char *pattern) { subscr->AddResources (pattern); return subscr; }
2956
2957static inline void RcUnsubscribeFromAll (CRcSubscriber *subscr) { subscr->Clear (); }
2960#ifndef SWIG
2961static inline void RcUnsubscribeFromAll (CRcSubscriber **pSubscr) { if (*pSubscr) { delete *pSubscr; *pSubscr = NULL; } }
2963#endif
2965
2967#ifdef SWIG
2968%pythoncode %{
2969## @}
2970%}
2971#endif // SWIG
2972
2973
2974
2975// ***** Placing requests *****
2976
2977
2980#ifdef SWIG
2981%pythoncode %{
2982## @name Placing requests ...
2983## Details on the request arguments can be found in the
2984## [*C/C++ API documentation*](../home2l-api_c/classCRcRequest.html)
2985## and the [*Home2L Book*](../home2l-book.pdf).
2986## @{
2987%}
2988#endif // SWIG
2989
2990
2991#ifndef SWIG
2992
2993// Requests...
2994
2995static inline void RcSetRequest (CResource *rc, CRcRequest *req) { rc->SetRequest (req); }
2996void RcSetRequest (const char *rcUri, CRcRequest *req);
3000static inline void RcSetRequest (CResource *rc, CRcValueState *value, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER) { rc->SetRequest (value, reqGid, priority, t0, t1, repeat, hysteresis); }
3001void RcSetRequest (const char *rcUri, CRcValueState *value, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
3014static inline void RcSetRequest (CResource *rc, bool valBool, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER) { rc->SetRequest (valBool, reqGid, priority, t0, t1, repeat, hysteresis); }
3015void RcSetRequest (const char *rcUri, bool valBool, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
3017static inline void RcSetRequest (CResource *rc, int valInt, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER) { rc->SetRequest (valInt, reqGid, priority, t0, t1, repeat, hysteresis); }
3018void RcSetRequest (const char *rcUri, int valInt, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
3020static inline void RcSetRequest (CResource *rc, float valFloat, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER) { rc->SetRequest (valFloat, reqGid, priority, t0, t1, repeat, hysteresis); }
3021void RcSetRequest (const char *rcUri, float valFloat, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
3023static inline void RcSetRequest (CResource *rc, const char *valString, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER) { rc->SetRequest (valString, reqGid, priority, t0, t1, repeat, hysteresis); }
3024void RcSetRequest (const char *rcUri, const char *valString, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
3026static inline void RcSetRequestFromStr (CResource *rc, const char *reqDef) { rc->SetRequestFromStr (reqDef); }
3027void RcSetRequestFromStr (const char *rcUri, const char *reqDef);
3031static inline void RcSetTrigger (CResource *rc, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks repeat = NEVER) { rc->SetTrigger (reqGid, priority, t0, repeat); }
3032void RcSetTrigger (const char *rcUri, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks repeat = NEVER);
3034static inline void RcSetTriggerFromStr (CResource *rc, const char *reqDef) { rc->SetTriggerFromStr (reqDef); }
3035void RcSetTriggerFromStr (const char *rcUri, const char *reqDef);
3037
3038static inline void RcDelRequest (CResource *rc, const char *reqGid = NULL, TTicks t1 = NEVER) { rc->DelRequest (reqGid, t1); }
3039void RcDelRequest (const char *rcUri, const char *reqGid = NULL, TTicks t1 = NEVER);
3048
3049#else // SWIG
3050
3051%feature("docstring") RcSetRequest "Add or change a request to a resource."
3052%feature("docstring") RcDelRequest "Delete a request from a resource."
3053%feature("docstring") RcSetTrigger "Add a trigger request."
3054
3055%pythoncode %{
3056
3057 def RcSetRequest (rc, reqDef = None, attrs = None, value = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
3058 """Set a request to a resource with selected attributes.\n\
3059 \n\
3060 The attributes can be set in a flexible way, either by (named) function arguments\n\
3061 or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
3062 \n\
3063 The parameters have the following meanings:\n\
3064 \n\
3065 - reqDef = full definition as a single string '<val> [<attrs>]' or just the value\n\
3066 Note: To avoid ambiguities, values of type string should never be passed by this,\n\
3067 but by the 'value' and 'attrs' arguments instead.\n\
3068 If 'reqDef' is not a string instance, it is used as a value ('val').\n\
3069 - attrs = attribute string (similar to 'reqDef', but without the first field interpreted as value)\n\
3070 \n\
3071 - value = value (any type or string)\n\
3072 - id = request ID [default = instance name]\n\
3073 - priority = request priority (0..9) [default = 3 (= rcPrioNormal)]\n\
3074 - t0 = on time\n\
3075 - t1 = off time\n\
3076 - repeat = repetition interval\n\
3077 - hysteresis = hysteresis time\n\
3078 - delDelay = deletion delay (if no value is passed and the call is used to delete the request)\n\
3079 \n\
3080 Information on the syntax of textual request definition can be found in the Home2L Book and\n\
3081 in the C/C++ API documentation for CRcRequest::SetFromStr(). Arguments representing absolute times\n\
3082 (e.g. 't0', 't1') can have any type and format as accepted by 'TicksAbsOf()'.\n\
3083 Arguments representing relative times (e.g. 'repeat', 'hysteresis', 'delDelay') can have any type\n\
3084 and format as accepted by 'TicksRelOf()'.\n\
3085 \n\
3086 If an attribute is set both by means of a string ('reqDef' or 'attrs') or a named parameter,\n\
3087 the named parameter is taken. If no attributes are specified, their defaults as specified in [...]\n\
3088 above are used.\n\
3089 \n\
3090 If the effective value is 'None' (no value is passed), the call will delete the request with\n\
3091 the specified ID passing 'delDelay' as the the 't1' argument of RcDelRequest().\n\
3092 \n\
3093 Examples:\n\
3094 \n\
3095 - Request integer value 7 with default attributes:\n\
3096 RcSetRequest (rc, 7);\n\
3097 RcSetRequest (rc, '7');\n\
3098 RcSetRequest (rc, value = '7');\n\
3099 RcSetRequest (rc, reqDef = '7');\n\
3100 \n\
3101 - Request integer value 7 with ID '#user' and priority 3:\n\
3102 RcSetRequest (rc, 7, id = 'user', priority = 3);\n\
3103 RcSetRequest (rc, 7, '#user *3');\n\
3104 RcSetRequest (rc, '7 #user *3');\n\
3105 \n\
3106 - Delete this request again:\n\
3107 RcSetRequest (rc, value = None, id = 'user');\n\
3108 RcSetRequest (rc, '? #user');\n\
3109 \n\
3110 - Delete this request in 5 seconds:\n\
3111 RcSetRequest (rc, value = None, id = 'user', delDelay = '5s');\n\
3112 \n\
3113 - Request string value 'Hello *3' with priority 5 and an off time at 6pm today:\n\
3114 RcSetRequest (rc, value = 'Hello *3', attrs = '*5 -18:00');\n\
3115 RcSetRequest (rc, value = 'Hello *3', priority = 5, t1 = '-18:00');\n\
3116 \n\
3117 - Set request with user-supplied attributes, some of which must not be changed by user\n\
3118 RcSetRequest (rc, 7, userAttrs, t1 = '-23:00') # t1 overrides an eventual off time in userAttrs\n\
3119 \n\
3120 - Set request with user-supplied attributes and defaults\n\
3121 req = CRcRequest (val = 7, t1 = '-23:00') # Set value and default attributes\n\
3122 req->Set (attrs = userAttrs) # userAttrs may override t1\n\
3123 \n\
3124 """
3125 if isinstance (rc, str): rc = RcGetResource (rc)
3126 rc.SetRequest (reqDef = reqDef, attrs = attrs, value = value, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis, delDelay = delDelay)
3127
3128 def RcSetTrigger (rc, attrs = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
3129 """Set a request to a trigger resource with selected attributes."""
3130 if isinstance (rc, str): rc = RcGetResource (rc)
3131 rc.SetRequest (attrs = attrs, value = 1, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
3132
3133 def RcDelRequest (rc, id = None, t1 = None):
3134 """Delete a request."""
3135 if isinstance (rc, str): rc = RcGetResource (rc)
3136 rc.DelRequest (id, t1)
3137
3138 def RcSetDefault (rc, reqDef = None, attrs = None, value = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
3139 """Set a default request."""
3140 if isinstance (rc, str): rc = RcGetResource (rc)
3141 rc.SetRequest (reqDef = reqDef, attrs = attrs, value = value, id = rcDefaultRequestId, priority = rcPrioDefault, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
3142
3143%} // %pythoncode
3144#endif // SWIG
3145
3146
3147
3148// Mutex operations (TBD:future) ...
3149//~ static inline CRcSubscriber *RcMutexRequestLock (const char *rcUri, const char *regGid, CRcSubscriber *subscr == NULL) { RcSetRequest (rcUri, reqGid, reqGid); return subscr; }
3150//~ void RcMutexWaitLock (const char *rcUri, const char *regGid, CRcSubscriber *subscr);
3151//~ bool RcMutexPollLock (const char *rcUri, const char *regGid, CRcSubscriber *subscr);
3152//~ void RcMutexUnlock (const char *rcUri, const char *regGid, CRcSubscriber *subscr);
3153
3154
3156#ifdef SWIG
3157%pythoncode %{
3158## @}
3159%}
3160#endif // SWIG
3161
3162
3163
3164// ***** Drivers *****
3165
3166
3171#ifdef SWIG
3172%pythoncode %{
3173## @name Drivers (from C/C++ API) ...
3174## Low-level operations to directly create and use 'CRcDriver' objects.
3175## Most probably, you will not need these functions.
3176## The preferred way in Python is to use the more compfortable decorators and
3177## operations in module "Home2L / Drivers".
3178## @{
3179%}
3180#endif // SWIG
3181
3182
3183
3184#ifdef SWIG
3185%feature("docstring") RcRegisterDriver "Register a new driver."
3186%feature("docstring") RcRegisterResource "Register a new resource to a driver."
3187%feature("docstring") RcRegisterSignal "Register a new signal for the built-in 'signal' driver."
3188#endif
3189
3192#ifndef SWIG
3193static inline void RcRegisterDriver (CRcDriver *drv) { drv->Register (); }
3195static inline void RcRegisterDriver (const char *drvLid, FRcDriverFunc *func) { CRcDriver::RegisterAndInit (drvLid, func); }
3198#endif
3199CRcEventDriver *RcRegisterDriver (const char *drvLid, ERcState _successState = rcsNoReport);
3214
3218#ifndef SWIG
3219static inline CResource *RcRegisterResource (CRcDriver *drv, const char *rcLid, ERcType _type, bool _writable, void *_data = NULL) { return CResource::Register (drv, rcLid, _type, _writable, _data); }
3220static inline CResource *RcRegisterResource (CRcDriver *drv, const char *rcLid, const char *rcTypeDef, void *_data = NULL) { return CResource::Register (drv, rcLid, rcTypeDef, _data); }
3221#endif
3222CResource *RcRegisterResource (const char *drvLid, const char *rcLid, ERcType _type, bool _writable, void *_data = NULL);
3223CResource *RcRegisterResource (const char *drvLid, const char *rcLid, const char *rcTypeDef, void *_data = NULL);
3224
3225CResource *RcRegisterSignal (const char *name, ERcType type);
3227CResource *RcRegisterSignal (const char *name, CRcValueState *vs);
3231
3232
3234#ifdef SWIG
3235%pythoncode %{
3236## @}
3237%}
3238#endif // SWIG
3239
3240
3241
3242
3243// ***** Executing shell commands *****
3244
3245// TBD
3246
3247
3248
3249
3251#ifdef SWIG
3252%pythoncode %{
3253## @}
3254%}
3255#endif // SWIG
3256
3257
3258
3259
3260
3261
3262// ***** Doxygen Footer *****
3263
3265#ifdef SWIG
3266%pythoncode %{
3267## @}
3268%}
3269#endif // SWIG
3270
3271
3272
3273#endif // _RC_LIB_
Class to wrap (POSIX) condition variables.
Definition: base.H:1740
Dictionary.
Definition: base.H:1195
Set of strings (keys).
Definition: base.H:1306
int Entries() const
Get number of entries.
Definition: base.H:950
Class to wrap (POSIX) mutex objects.
Definition: base.H:1723
Driver for local resources.
Definition: resources.H:2460
void Unregister()
Unregister the driver. This is only allowed in the elaboration phase or on shutdown....
virtual void DriveValue(CResource *rc, CRcValueState *vs)
Callback to drive a new value, will be called from CResource::DriveValue().
static void RegisterAndInit(const char *_lid, FRcDriverFunc *_func)
Create, register and initialize a function-based driver.
virtual void Stop()
Stop all (own) threads and close all I/Os properly; Will be called from RcDone(). Resources are still...
void ClearResources()
Unregister all resources.
void Register()
Register and enable the driver. This must be done between the calls to RcInit() and RcStart(),...
Local driver using the event processor mechanism for the 'DriveValue()' functionality.
Definition: resources.H:2576
virtual void DriveValue(CResource *rc, CRcValueState *vs)
Callback to drive a new value, will be called from CResource::DriveValue().
virtual void Stop()
The caller/owner must do this before 'RcDone()'. (The event processor may not work anymore by the tim...
Definition: resources.H:2592
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:2588
CRcEventDriver(const char *_lid, ERcState _successState=rcsBusy)
Initialize the driver (does not register).
Definition: resources.H:2578
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:2589
Event processor.
Definition: resources.H:1686
void SetInSelectSet(bool _inSelectSet)
Set whether or not the event processor is contained in the set of upcoming Select() operations.
bool WaitEvent(CRcEvent *ev, TTicks *maxTime=NULL)
Wait for an event and return it at '*ev'.
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:1771
bool PollEvent(CRcEvent *ev)
Check for an event (non-blocking) and return it at '*ev'.
void PutEvent(CRcEvent *ev)
Enqueue/process an event; caller remains owner of 'ev'.
void FlushEvents()
Remove all presently queued events; also waits until a concurrently running OnEvent() invocation retu...
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:1772
virtual bool OnEvent(CRcEvent *ev)
Handle an event asynchronously (may have been called from any thread)
static CRcEventProcessor * Select(TTicks maxTime=-1)
Wait until any of the existing 'CRcEventProcessor' objects has an event available.
void Interrupt()
Request a running WaitEvent() to stop now.
Timer that sends 'rceTimer' events over the event system.
Definition: resources.H:1840
virtual void OnTime()
[T:timer] Virtual function called when the timer triggers.
Definition: resources.H:1850
void Set(void *_data)
Setup timer without (re-)scheduling it.
Definition: resources.H:1845
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:1853
void Set(TTicks _time, TTicks _interval=0, void *_data=NULL)
Setup and (re-)schedule timer (see CTimer::Set() ).
Definition: resources.H:1847
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:1852
Events delivered by a subscriber or to a driver.
Definition: resources.H:1600
const char * ToStr(CString *ret)
Get a readable string.
CRcValueState * ValueState()
Get the value/state attribute of the event. See Set() for further details.
Definition: resources.H:1628
void Set(ERcEventType _type=rceNone, CResource *_resource=NULL, CRcValueState *_valueState=NULL, void *_data=NULL)
Set event attributes.
Request description object.
Definition: resources.H:2083
const char * ToStr(CString *ret, bool precise=true, bool tabular=false, TTicks relativeTimeThreshold=NEVER, const char *skipAttrs=CString::emptyStr)
Return a string in the format accepted by SetFromStr().
const char * Gid()
Requests only have a global ID, no local ID, since they do not "belong" to the initiating host or pro...
Definition: resources.H:2167
void SetValue(CRcValueState *_value)
Set value (no state!) (argument must be != NULL).
CRcRequest(CRcRequest *req)
Construct by cloning an existing request object (the origin is set, not cloned).
Definition: resources.H:2087
CRcRequest(float _value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
Definition: resources.H:2095
void SetForTrigger()
Set value and type suitable for 'rctTrigger' resources and reset fields irrelevant for triggers.
void SetTimeOff(TTicks _t1)
Set off time (argument must be != NEVER).
Definition: resources.H:2147
void SetRepeat(TTicks _repeat)
Set repetition interval (argument must be != NEVER).
Definition: resources.H:2148
void SetHysteresis(TTicks _hysteresis)
Set hysteresis (argument must be != NEVER).
Definition: resources.H:2149
void Reset()
Clear the value and set default attributes ( NO_VALUE_STATE, NEVER, NULL or equivalent; priority = rc...
CRcRequest()
Default constructor.
Definition: resources.H:2085
bool IsCompatible()
Returns whether the request is compatible with the type of the resource recently passed to Convert().
Definition: resources.H:2165
CRcRequest(CRcValueState *_value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
Definition: resources.H:2089
CRcRequest(const char *_value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
Definition: resources.H:2097
void Convert(CResource *rc, bool warn=true)
Try to convert type to match the given resource and set 'isCompatible' according to the success....
void SetPriority(int _priority)
Set GID (argument must be != rcPrioNone).
Definition: resources.H:2145
void SetGid(const char *_gid)
Set GID (argument must be != NULL).
Definition: resources.H:2143
const char * Origin()
Origin of the request. It is automatically set by Reset() to the request creation information in the ...
Definition: resources.H:2170
bool SetFromStr(const char *str)
Set the request based on a textual definition.
bool SetAttrsFromStr(const char *str)
Set request attributes (no value) base on a textual definition.
void SetTimeOn(TTicks _t0)
Set on time (argument must be != NEVER).
Definition: resources.H:2146
void Set(CRcValueState *_value=NULL, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks _repeat=NEVER, TTicks _hysteresis=NEVER)
Define a request with all parameters and attributes.
void Set(CRcRequest *req)
Define a request by copying attributes from another. The origin is not copied.
CRcRequest(int _value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
Definition: resources.H:2093
CRcRequest(bool _value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
Definition: resources.H:2091
CRcRequest(TTicks _value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
Definition: resources.H:2099
Subscriber to follow an arbitrary set of resources.
Definition: resources.H:1907
void Clear()
Remove all resources.
void Unregister()
Clear and unregister the subscriber.
void GetPatternSet(CKeySet *retPatternSet)
Get current pattern set. Patterns from the watch set are followed by a "?".
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:1927
void DelResources(const char *pattern)
Remove resources by pattern. See AddResources() for details on possible patterns.
CResource * AddResources(const char *pattern)
Add new resources by pattern. The pattern is also stored internally to catch possible resources added...
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:1928
static void GetInfoAll(CString *ret, int verbosity=1)
Get info for all subscribers of this instance (see GetInfo() for info on 'verbosity').
void GetInfo(CString *ret, int verbosity=1)
Get Info. 'verbosity == 0': single line, 1: list entries / resources.
bool Register(const char *_lid)
Enable the subscriber, set its LID and GID. Caller remains owner of object. If '_lid' refers to an in...
Typed value tagged with a state and a time stamp.
Definition: resources.H:488
bool SetFromStr(const char *str)
Set the value and state based on textual information.
bool SetFromStrFast(const char *str, bool warn=true)
Set the object based on textual information (fast version).
void SetToReportNothing()
Modify object to not auto-report anything.
Definition: resources.H:539
bool ValueEquals(const CRcValueState *vs2) const
Relaxed comparison: type and value must match exactly; state and time stamps are not compared.
void SetType(ERcType _type)
Change type in a hard way; implies resetting the state to 'rcsUnkown'.
Definition: resources.H:650
bool Equals(const CRcValueState *vs2) const
Strict comparison: state, type and value must match exactly; time stamps are not compared.
bool IsKnown() const
State is either rcsValid or rcsBusy; In other words: the value can be retrieved.
Definition: resources.H:663
void SetToReportBusyNewVal()
Modify object to auto-report a busy state together with a value. This is to be used in CRcDriver::Dri...
Definition: resources.H:535
void SetGenericInt(int _val, ERcType _type, ERcState _state=rcsValid)
Set from integer or boolean.
void ToHuman(char *retBuf, int retBufSize)
Output a human-readable string representation for UIs.
void Clear(ERcType _type, ERcState _state=rcsUnknown)
Clear to default value:
TTicks timeStamp
time of last value/state change or trigger
Definition: resources.H:749
bool Convert(ERcType _type)
Try to convert the current value to a new type. If a conversion is not possible, 'false' is returned ...
CRcValueState(ERcType _type)
for initializing type, but without setting value
Definition: resources.H:492
void SetGenericFloat(float _val, ERcType _type, ERcState _state=rcsValid)
Set from float.
void SetToReportBusy()
Modify object to auto-report a busy state.
Definition: resources.H:529
void SetToReportBusyOldVal()
Modify object to auto-report a busy state with no value change. Note: Only for use in CRcDriver::Driv...
Definition: resources.H:531
bool SetGenericString(const char *_val, ERcType _type, ERcState _state=rcsValid)
Set from string. On syntax error, a warning is emitted, the state is set to rcsUnknown,...
const char * ToStr(CString *ret, bool withType=false, bool withTimeStamp=false, bool precise=false, int stringChars=20) const
Output the object contents as a string according to the synax described for 'SetFromStr'.
bool IsBusy() const
State is rcsBusy, neither rcsValid nor rcsUnknown.
Definition: resources.H:661
void Clear()
Clear value, set state to 'rcsUnknown', and leave type unchanged.
Definition: resources.H:511
bool IsValid() const
State is rcsValid, neither rcsBusy nor rcsUnknown.
Definition: resources.H:659
Home2L Resource.
Definition: resources.H:909
void GetValueState(CRcValueState *retValueState)
Get the value and state.
void SetRequest(CRcValueState *value, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (generic value, direct parameters). The request attributes are explaind in t...
void ReportState(ERcState _state)
Report state change only, value remains unmodified.
Definition: resources.H:1253
bool IsKnown() const
State is either rcsValid or rcsBusy; In other words: the value can be retrieved.
Definition: resources.H:1037
static CResource * Register(CRcDriver *_rcDriver, const char *_lid, ERcType _type, bool _writable, void *_data=NULL)
Register a new local resource for a driver.
Definition: resources.H:1184
unsigned RegSeq()
The 'regSeq' number is incremented each time the resource is registered or unregistered....
Definition: resources.H:1324
void SetTriggerFromStr(const char *reqDef)
Set trigger request by textual definition.
void SetRequest(CRcRequest *_request)
Add or replace a request (generic version).
Definition: resources.H:1084
void Unsubscribe(CRcSubscriber *subscr)
Unsubscribe to this resource.
Definition: resources.H:1067
int ValidInt(int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid integer value.
void DelRequest(const char *reqGid=NULL, TTicks t1=NEVER)
Delete a request.
bool Is(const char *uri)
Check identity by exact match.
ERcState GetValue(int *retInt, TTicks *retTimeStamp=NULL)
Get a value of type "int" or a type based on it.
int LockLocalSubscribers()
Return number of all active local subscribers for a resource and lock this object....
const char * Lid()
Get the local ID (LID). This is the path relative to a) 'this's host (remote resource) or b) driver (...
Definition: resources.H:950
bool Is(CResource *rc)
Check identity (for Python & eventual wrapper classes).
Definition: resources.H:954
ERcState GetValue(CString *retString, TTicks *retTimeStamp=NULL)
Get a value of type "string" or a type based on it.
static CResource * Register(CRcDriver *_rcDriver, const char *_lid, const char *rcTypeDef, void *_data=NULL)
Register a new local resource for a driver based on a textual type description. 'rcTypeDef' is a text...
Definition: resources.H:1203
const char * ValidMutex(CString *ret, const char *defaultVal=CString::emptyStr, TTicks *retTimeStamp=NULL)
Get a valid mutex value.
Definition: resources.H:1016
bool IsValid() const
State is rcsValid, neither rcsBusy nor rcsUnknown.
Definition: resources.H:1033
bool ValidBool(bool defaultVal=false, TTicks *retTimeStamp=NULL)
Get a valid Boolean value. This and the following methods are shortcuts for first obtaining the 'Valu...
void SetUserData(void *_data)
Set user-specified data for this resource.
Definition: resources.H:1227
float ValidUnitFloat(ERcType _type, float defaultVal=0.0, TTicks *retTimeStamp=NULL)
Get a valid unit-type float value.
const char * Uri()
Get the URI (aka global ID / GID).
Definition: resources.H:948
const char * ValidString(CString *ret, const char *defaultVal=CString::emptyStr, TTicks *retTimeStamp=NULL)
Get a valid string value.
void ReportTrigger()
For triggers, this method must be called.
void Unregister()
Unregister a resource.
void WriteValue(CRcValueState value, int priority=rcPrioNone, const char *reqGid="write")
Write a value by issueing or updating a request with the given global id. The implementation of this ...
Definition: resources.H:1170
void ReadValueState(CRcValueState *retValueState, TTicks maxTime=-1)
Perform a blocking read to obtain an up-to-date value from the driver. Internally,...
void SetRequest(const char *valString, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
int ValidUnitInt(ERcType _type, int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid unit-type integer value.
bool ValueEquals(const CRcValueState *vs2)
Relaxed comparison: type and value must match exactly; state and time stamps are not compared.
Definition: resources.H:1042
void SetDefault(CRcValueState *vs)
Set a default value.
Definition: resources.H:1209
void SetRequestFromStr(const char *reqDef)
Set request by textual definition. See CRcRequest::SetFromStr() and the Home2L Book for more informat...
bool HasSubscribers()
Return whether this resource is currently subscribed (dynamic, not semi-static).
Definition: resources.H:1332
static CResource * Get(const char *uri, bool allowWait=false)
Look up a resource by its URI and return a reference to it.
void SetTrigger(const char *reqGid, int priority=rcPrioNone, TTicks t0=NEVER, TTicks repeat=NEVER)
Set a trigger request (no value needs to be given).
void SetRequest(float valFloat, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
static void GarbageCollection()
Remove all unregistered resources.
ERcState GetValue(float *retFloat, TTicks *retTimeStamp=NULL)
Get a value of type "float" or a type based on it.
CRcRequest * GetRequest(const char *reqGid, bool allowNet=true)
Query a request by its request GID.
void * UserData()
Retrieve user-specified data.
Definition: resources.H:1229
void ReportValueState(const CRcValueState *_valueState)
Report value and state; if different from previous value/state, notify all subscribers....
void SetRequest(TTicks valTime, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
bool IsLike(const char *pattern)
Check identity by pattern.
const char * Gid()
Get the global ID.
Definition: resources.H:949
bool HasRequests()
Return whether this resource has requests (dynamic, not semi-static).
Definition: resources.H:1334
bool IsBusy() const
State is rcsBusy, neither rcsValid nor rcsUnknown.
Definition: resources.H:1035
void ReportUnknown()
Report an unknown state.
Definition: resources.H:1257
bool Equals(const CRcValueState *vs2)
Strict comparison: state, type and value must match exactly; time stamps are not compared.
Definition: resources.H:1040
void WaitForRegistration()
Wait until registered or a network timeout occured.
void ReportBusy()
Report a busy state (without changing the value).
Definition: resources.H:1255
bool GetRequestSet(CRcRequestSet *ret, bool allowNet=true)
Query all pending requests.
int ValidEnumIdx(ERcType _type, int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid enumeration value index.
void SetRequest(bool valBool, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
TTicks ValidTime(TTicks defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid time value.
int LockLocalRequests()
Return number of active requests for a local resource and lock this object. During the locked state,...
const char * GetInfo(CString *ret, int verbosity=1, bool allowNet=true)
Get textual information on this resource.
float ValidFloat(float defaultVal=0.0, TTicks *retTimeStamp=NULL)
Get a valid float value.
void SetRequest(int valInt, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
CResource * Subscribe(CRcSubscriber *subscr)
Subscribe to this resource. The caller remains owner of 'subscr'.
Definition: resources.H:1061
void RedriveValue(bool force=true)
Drive the currently requested value again.
Definition: resources.H:1264
ERcState GetValue(bool *retBool, TTicks *retTimeStamp=NULL)
Get a value of type "Bool" or a type based on it.
ERcState GetValue(TTicks *retTime)
Get a value of type "time".
int ValidTrigger(int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid trigger value.
Definition: resources.H:1014
Dynamically allocated string.
Definition: base.H:635
static const char *const emptyStr
Use this whenever you need an empty string ("")
Definition: base.H:676
char * Disown()
Return current string as a dynamic object and clear 'this'.
void SetF(const char *fmt,...)
Set using printf() formatting.
char * Get() const
Get the C string. Unless explicitely set by 'SetC', this will never return NULL or an invalid pointer...
Definition: base.H:687
Timer class.
Definition: base.H:1582
void Set(FTimerCallback *_func, void *_data=NULL, void *_creator=NULL)
Setup timer without (re-)scheduling it.
int64_t TTicks
Time value (relative, absolute, or monotonic).
Definition: base.H:1378
#define NEVER
Special value that may represent "never" for absolute or monotonic times. Other application-specific ...
Definition: base.H:1383
#define ASSERT(COND)
Check a condition and abort the application if not true.
Definition: base.H:276
#define WARNING(MSG)
Print a warning message to the console.
Definition: base.H:244
const char * StringF(class CString *ret, const char *fmt,...)
Return 'ret->Get ()'.
int RcLockHostResources(CRcHost *host)
Query number of resources for a remote host.
CRcHost * RcGetHost(int n)
Get reference to host n, 0 <= n < number of hosts.
static const char * RcLocalHostId()
Get the ID of the local instance.
Definition: resources.H:2645
int RcGetHosts()
Get number of known hosts.
int RcLockSubscribers()
Query the number of existing subscribers and lock the subscriber database.
const char * RcGetHostId(CRcHost *host)
Get textual ID of 'host'.
int RcLockDriverResources(CRcDriver *driver)
Query the number of resources for a local driver.
void FRcDriverFunc(ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *)
Resources driver function.
Definition: resources.H:2399
ERcDriverOperation
Driver operations.
Definition: resources.H:2376
@ rcdOpDriveValue
Drive a value; refers to CRcDriver::DriveValue(). Parameters: CRcDriver *driver, CResource *rc,...
Definition: resources.H:2393
@ rcdOpInit
Initialize driver object(s) of a linked-in driver. Parameter: CRcDriver *drv.
Definition: resources.H:2379
@ rcdOpStop
Stop the driver; refers to CRcDriver::Stop(). Parameter: CRcDriver *drv.
Definition: resources.H:2390
void RcIterate()
Perform pending actions, call TimerIterate() and return.
static void RcGarbageCollection()
(For experts) Remove all presently unregistered resources from memory.
Definition: resources.H:2895
void RcStop()
Stop a loop started by RcRun().
int RcRun(bool catchSignals=true)
Run RcStart(), then RcIterate() in a main event loop until RcStop() is called.
void RcDone()
Shutdown the Resources library.
static CRcSubscriber * RcSubscribe(CRcSubscriber *subscr, CResource *rc)
Subscribe to an additional resource.
Definition: resources.H:2955
static CResource * RcGetResource(const char *uri, bool allowWait=false)
Lookup a resource by its URI and return a reference to it.
Definition: resources.H:2878
void RcBump(CResource *rc=NULL, bool soft=false)
(For experts) Try to reconnect a remote host now.
void RcStart()
Complete the elaboration phase and start active operation. No more drivers and resources may be decla...
void RcInit(bool enableServer=false, bool inBackground=false)
Initialize the Resources library (and start the elaboration phase). This may be followed by driver de...
void RcDelRequest(const char *rcUri, const char *reqGid=NULL, TTicks t1=NEVER)
Delete a request.
static void RcUnsubscribeFromAll(CRcSubscriber *subscr)
Unsubscribe from all resources presently subscribed by 'subscr'. The caller remains owner of 'subscr'...
Definition: resources.H:2960
void RcSetTriggerFromStr(const char *rcUri, const char *reqDef)
Set trigger request by textual definition.
static void RcRegisterDriver(CRcDriver *drv)
Register a pre-initialized driver object (typically an object of a derived class with overloaded meth...
Definition: resources.H:3196
void RcSetRequestFromStr(const char *rcUri, const char *reqDef)
Set request by textual definition - see CRcRequest::SetFromStr() and the Home2L Book for more informa...
CResource * RcRegisterSignal(const char *name, ERcType type)
Register a new resource for the built-in 'signal' driver.
CRcSubscriber * RcNewSubscriber(const char *subscrLid, CResource *rc=NULL)
Create and register a new subscriber object and optionally subscribe to the given resource.
static CResource * RcGet(const char *uri, bool allowWait=false)
Lookup a resource by its URI and return a reference to it (shortcut for RcGetResource() ).
Definition: resources.H:2891
void RcSetTrigger(const char *rcUri, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks repeat=NEVER)
Set a trigger request (no value needs to be given).
void RcSetRequest(const char *rcUri, CRcRequest *req)
Add or replace a request (generic version).
const char *const rcDefaultRequestId
Request ID for default requests ("default")
const char * RcGetUserRequestId()
Get the request ID for user interactions (see 'rc.userReqId').
const char * RcGetUserRequestAttrs()
Get the default request attributes for user interactions (see 'rc.userReqAttrs').
#define rcPrioDefault
Preset defaults (typically by the driver)
Definition: resources.H:214
CDict< CRcRequest > CRcRequestSet
Set of requests (for CResource::GetRequestSet() )
Definition: resources.H:228
#define rcPrioNone
Undefined priority (special value)
Definition: resources.H:223
bool FRcEventFunc(class CRcEventProcessor *, CRcEvent *, void *)
Event processor callback function. Example: bool OnEventFunc (CRcEventProcessor *ep,...
Definition: resources.H:1671
ERcEventType
Event type.
Definition: resources.H:1561
@ rceDisconnected
[subscriber] Connection to resource was lost
Definition: resources.H:1568
@ rceValueStateChanged
[subscriber] Value or state has changed
Definition: resources.H:1566
@ rceTimer
[timer] Timer alarm
Definition: resources.H:1564
@ rceNone
None (for dummy events)
Definition: resources.H:1562
@ rceConnected
[subscriber] Connection to resource is (re-)established
Definition: resources.H:1569
@ rceDriveValue
[driver] Drive a new value
Definition: resources.H:1571
@ rceRequestChanged
[subscriber] Request has changed
Definition: resources.H:1567
ERcState
Resource state.
Definition: resources.H:457
int RcTypeGetEnumIdx(ERcType t, const char *value, bool warn=true)
Return the index of some value for an enumeration type. If the 'value' is out of range,...
int RcTypeGetEnumValues(ERcType t)
Return the number of possible values for an enumeration type.
bool RcTypeIsStringBased(ERcType t)
Return if the base type is 'rctString'; This is the set of types that have dynamic data.
ERctUseState
Use/presence state of the home (for 'rctUseState')
Definition: resources.H:388
ERcType RcTypeGetBaseType(ERcType t)
Return the underlying base type as a unique representative for compatible classes (e....
static bool RcTypeIsUnitType(ERcType t)
Return whether the type is a unit type.
Definition: resources.H:362
ERctWindowState
Window state (for 'rctWindowState')
Definition: resources.H:397
ERctPhoneState
Phone state (for 'rctPhoneState')
Definition: resources.H:406
static bool RcTypeIsEnumType(ERcType t)
Return whether the type is a enumeration type.
Definition: resources.H:368
ERcType
Resource major type.
Definition: resources.H:278
ERctPlayerState
Music player state (for 'rctPlayerState')
Definition: resources.H:414
const char * RcTypeGetEnumValue(ERcType t, int idx, bool warn=true)
Return the value for 'idx' for an enumeration type. Allowed index vaules range from 0 to N-1,...
const char * RcTypeGetUnit(ERcType t)
Return the unit string; For non-unit types, an empty string is returned.
@ rcsNoReport
Alias to make the 'successState' attribute in CRcEventDriver more intuitive.
Definition: resources.H:463
@ rcsUnknown
Value is presently unknown (e.g. outdated).
Definition: resources.H:458
@ rcsValid
Value is valid.
Definition: resources.H:460
@ rcsBusy
Devices is busy and/or switching to the value indicated by the associate value.
Definition: resources.H:459
@ rcvUseVacation
User is away temporarily (e.g. for work)
Definition: resources.H:392
@ rcvUseNight
User is at home and present at day time.
Definition: resources.H:390
@ rcvUseAway
User is at home, but sleeping (e.g. doors should be locked)
Definition: resources.H:391
@ rcvWindowTilted
closed
Definition: resources.H:399
@ rcvWindowOpenOrTilted
(wide) open
Definition: resources.H:401
@ rcvWindowOpen
tilted
Definition: resources.H:400
@ rcvPhoneInCall
idle
Definition: resources.H:408
@ rcvPhoneRinging
in call, including any 'psDialing' and 'psTransfer...' states (anything where a user is actively usin...
Definition: resources.H:409
@ rctPercent
[float] Percentage (0.0 .. 100.0)
Definition: resources.H:322
@ rctMutex
[rctString] resource represents a mutex (not implemented yet)
Definition: resources.H:295
@ rctTime
Time.
Definition: resources.H:288
@ rctString
String.
Definition: resources.H:286
@ rctUseState
Use/presence state ("day", "night", "away", "vacation")
Definition: resources.H:338
@ rctWindowState
Window opening state ("closed", "tilted", "open", "openOrTilted")
Definition: resources.H:340
@ rctPower
[float] Electrical power in Watts
Definition: resources.H:325
@ rctTrigger
[rctInt] Resource does not carry a value, but can transport events ("triggers"); 'vTriggerCount' coun...
Definition: resources.H:294
@ rctPhoneState
Phone state ("idle", "ringing", "inCall")
Definition: resources.H:342
@ rctPlayerState
Music player state ("stop", "pause", "play")
Definition: resources.H:344
@ rctInt
Integer.
Definition: resources.H:284
@ rctTemp
[float] Temperature in degree centigrade
Definition: resources.H:324
@ rctNone
No type.
Definition: resources.H:279
@ rctBool
Boolean.
Definition: resources.H:283
@ rctFloat
Float.
Definition: resources.H:285
@ rcvPlayerPlaying
paused
Definition: resources.H:417
@ rcvPlayerPaused
stopped
Definition: resources.H:416