Home2L - C/C++ API  v1.2-2-ga4fe (2023-04-15)
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-2021 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 in C/C++
153 ## @brief Native API for defining custom drivers.
154 ## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__requests.html).
155 %}
156 #endif // SWIG
157 
158 
159 
160 
161 
162 // *************************** (Forward) Declararions ****************************
163 
164 
165 #ifndef SWIG
166 
167 
168 // Forward declarations (full declaration below)...
169 class CRcSubscriber;
170 class CRcRequest;
171 
172 
173 
174 // ***** Internal classes *****
175 
176 class CRcHost; // represents a (remote) host
177 class CRcDriver; // represents a (local) driver
178 class CRcSubscriberLink;
179 class CResourceLink;
180 
181 
182 #endif // #ifndef SWIG
183 
184 
185 
186 // ***** Request priorities *****
187 
190 #ifdef SWIG
191 %pythoncode %{
192 ## @addtogroup resources_requests
193 ## @{
194 %}
195 #endif // SWIG
196 
208 #define rcPrioMin 0
209 #define rcPrioNormal 3
210 #define rcPrioMax 9
211 
212 #define rcPrioDefault 0
213 #define rcPrioRuleMin 1
214 #define rcPrioRule 3
215 #define rcPrioRuleMax 5
216 #define rcPrioUser 6
217 #define rcPrioShell 7
218 #define rcPrioSafety 8
219 #define rcPrioIKnowWhatImDoing 9
220 
221 #define rcPrioNone -1
222 
224 
225 
228 
229 extern const char *const rcDefaultRequestId;
230 
231 
233 #ifdef SWIG
234 %pythoncode %{
235 ## @}
236 %}
237 #endif // SWIG
238 
239 
240 
241 
242 
243 // *************************** Values, Types and States ************************
244 
245 
248 #ifdef SWIG
249 %pythoncode %{
250 ## @addtogroup resources_values
251 ## @{
252 %}
253 #endif // SWIG
254 
255 
256 
257 
258 
259 // ***** Types *****
260 
261 
262 #define rctBasicTypesBase rctBool
263 #define rctBasicTypesLast rctTime
264 
265 #define rctSpecialTypesBase rctTrigger
266 #define rctSpecialTypesLast rctMutex
267 
268 #define rctUnitTypesBase 0x40
269 #define rctUnitTypesLast (rctUnitTypesEND-1)
270 
271 #define rctEnumTypesBase 0x80
272 #define rctEnumTypesLast (rctEnumTypesEND-1)
273 
274 
276 enum ERcType {
277  rctNone = 0,
278 
285  //~ rctBlob, ///< Binary data (not implemented yet, TBD)
287  //~ rctColor, ///< Color value (not implemented yet, TBD)
289 
293  rctMutex,
311 
320  rctPercent = rctUnitTypesBase,
323  rctUnitTypesEND,
325 
335  rctUseState = rctEnumTypesBase,
343  rctEnumTypesEND
345 };
346 
347 
348 // Type names ...
349 const char *RcTypeGetName (ERcType t);
350 ERcType RcTypeGetFromName (const char *name);
351 
352 // Get base type ...
357 
358 // Unit types ...
359 static inline bool RcTypeIsUnitType (ERcType t) { return t >= rctUnitTypesBase && t <= rctEnumTypesBase; }
361 const char *RcTypeGetUnit (ERcType t);
363 
364 // Enumeration types ...
365 static inline bool RcTypeIsEnumType (ERcType t) { return t >= rctEnumTypesBase; }
369 const char *RcTypeGetEnumValue (ERcType t, int idx, bool warn = true);
373 int RcTypeGetEnumIdx (ERcType t, const char *value, bool warn = true);
376 
377 
378 
379 
380 
381 // ***** Enum declarations for enumeration types *****
382 
383 
386  rcvUseDay = 0,
390 };
391 
392 
395  rcvWindowClosed = 0,
399 };
400 
401 
404  rcvPhoneIdle = 0,
407 };
408 
409 
412  rcvPlayerStopped = 0,
415 };
416 
417 
418 
419 
420 
421 // ***** Values *****
422 
423 
424 // Union for an untyped value (for internal use only) @private
425 #ifdef SWIG
426 %immutable vString;
427 //~ %immutable vBlob;
428 #endif
429 union URcValue {
430  uint64_t vAny; // Pseudo-field to clear/compare independent of type
431 
432  bool vBool;
433  int vInt; // Width/value range can be machine dependent, but must be at least 32 bits (-2^31 .. +2^31-1).
434  float vFloat; // Encoding must be 32-bit floating point according to IEEE 754
435  const char *vString; // Pointer to a dynamically allocated string; NULL <=> string is empty ("")
436  //~ uint8_t *vBlob; // Binary data of any size (not implemented yet, TBD)
437  TTicks vTime;
438  //~ uint32_t vColor; // Color value (ARGB) (not implemented yet, TBD)
439 };
440 
441 
442 #ifndef SWIG
443 STATIC_ASSERT(sizeof (URcValue) == sizeof (URcValue::vAny));
444 #endif
445 
446 
447 
448 
449 
450 // ***** State *****
451 
452 
454 enum ERcState {
458 
459  // Aliases ...
462 };
463 
464 
465 
466 
467 
468 // ***** CRcValueState *****
469 
470 
472 #ifdef SWIG
473 %feature("docstring") CRcValueState "Typed value tagged with a state and a time stamp.\n\n"
474  "The constants for type 'ERcType' have the prefix 'rct*'."
475  "The state may be one of:\n"
476  " 'rcsUnknown': The value is unknown.\n"
477  " 'rcsBusy': The value is known, the underlying device is busy.\n"
478  " 'rcsValid': The value is known and stable.\n"
479  "The time stamp reflects the age of a value (last change/update). It is\n"
480  "generally not valid to judge from the time stamp whether the value is\n"
481  "outdated, since there are other mechanisms in the library setting the\n"
482  "state to 'rcsUnknown' if, for example, the connection to a remote resource\n"
483  "got lost."
484 #endif
486  public:
487  CRcValueState () { type = rctNone; Clear (); }
488  CRcValueState (const CRcValueState *vs) { type = rctNone; Set (vs); if (vs) timeStamp = vs->timeStamp; }
489  CRcValueState (ERcType _type) { type = rctNone; Clear (_type); }
490 
491  CRcValueState (ERcType _type, bool _val, ERcState _state = rcsValid) { type = rctNone; SetBool (_val, _state); }
492  CRcValueState (ERcType _type, int _val, ERcState _state = rcsValid) { type = rctNone; SetGenericInt (_val, _type, _state); }
493  CRcValueState (ERcType _type, float _val, ERcState _state = rcsValid) { type = rctNone; SetGenericFloat (_val, _type, _state); }
494  CRcValueState (ERcType _type, const char *_val, ERcState _state = rcsValid) { type = rctNone; SetGenericString (_val, _type, _state); }
495  CRcValueState (ERcType _type, TTicks _val, ERcState _state = rcsValid) { type = rctNone; SetTime (_val, _state); }
496 
497  ~CRcValueState () { Clear (rctNone); }
498 
499 #ifndef SWIG
500  CRcValueState& operator = (const CRcValueState &_vs) { Set (&_vs); timeStamp = _vs.timeStamp; return *this; }
501 #endif
502 
508  void Clear () { Clear (type); }
510  void Clear (ERcType _type, ERcState _state = rcsUnknown);
516  void Set (const CRcValueState *vs2);
518 
532  void SetToReportBusyNewVal () { state = rcsBusy; }
536  void SetToReportNothing () { state = rcsUnknown; }
539 
547  void SetGenericInt (int _val, ERcType _type, ERcState _state = rcsValid);
549  void SetGenericFloat (float _val, ERcType _type, ERcState _state = rcsValid);
551  bool SetGenericString (const char *_val, ERcType _type, ERcState _state = rcsValid);
555 
558  void SetBool (bool _val, ERcState _state = rcsValid) { SetGenericInt (_val, rctBool, _state); }
559  void SetInt (int _val, ERcState _state = rcsValid) { SetGenericInt (_val, rctInt, _state); }
560  void SetFloat (float _val, ERcState _state = rcsValid) { SetGenericFloat (_val, rctFloat, _state); }
561  bool SetString (const char *_val, ERcState _state = rcsValid) { return SetGenericString (_val, rctMutex, _state); }
562  void SetTime (TTicks _val, ERcState _state = rcsValid);
563 
564  void SetTrigger (int _val = 1, ERcState _state = rcsValid) { SetGenericInt (_val, rctTrigger, _state); }
565  bool SetMutex (const char *_val, ERcState _state = rcsValid) { return SetGenericString (_val, rctMutex, _state); }
566 
567  void SetUnitInt (ERcType type, int _val, ERcState _state = rcsValid) { SetGenericInt (_val, type, _state); }
568  void SetUnitFloat (ERcType type, float _val, ERcState _state = rcsValid) { SetGenericFloat (_val, type, _state); }
569 
570  void SetEnum (ERcType type, int _val, ERcState _state = rcsValid) { SetGenericInt (_val, type, _state); }
572 
583  int GenericInt () const { ASSERT (RcTypeGetBaseType (type) == rctInt); return val.vInt; }
584  float GenericFloat () const { ASSERT (RcTypeGetBaseType (type) == rctFloat); return val.vFloat; }
585  const char * GenericString () const { ASSERT (RcTypeGetBaseType (type) == rctString); return val.vString; }
586 
587  bool Bool () const { ASSERT (type == rctBool); return val.vBool; }
588  int Int () const { ASSERT (type == rctInt); return val.vInt; }
589  float Float () const { ASSERT (type == rctFloat); return val.vFloat; }
590  const char * String () const { ASSERT (type == rctString); return val.vString; }
591  TTicks Time () const { ASSERT (type == rctTime); return val.vTime; }
592 
593  int Trigger () const { ASSERT (type == rctTrigger); return val.vInt; }
594  const char * Mutex () const { ASSERT (type == rctMutex); return val.vString; }
595 
596  int UnitInt (ERcType _type) const { ASSERT (type == _type); return val.vInt; }
597  float UnitFloat (ERcType _type) const { ASSERT (type == _type); return val.vFloat; }
598 
599  int EnumIdx () const { ASSERT (RcTypeIsEnumType (type)); return val.vInt; }
601 
602 #ifndef SWIG
614  ERcState GetValue (bool *retBool);
615  ERcState GetValue (int *retInt);
616  ERcState GetValue (float *retFloat);
617  ERcState GetValue (CString *retString);
618  ERcState GetValue (TTicks *retTime);
620 #endif
621 
631  bool ValidBool (bool defaultVal = false);
632  int ValidInt (int defaultVal = 0);
633  float ValidFloat (float defaultVal = 0.0);
634  const char * ValidString (const char *defaultVal = CString::emptyStr);
635  TTicks ValidTime (TTicks defaultVal = 0);
636 
637  int ValidTrigger (int defaultVal = 0) { return ValidInt (defaultVal); }
638  const char * ValidMutex (const char *defaultVal = CString::emptyStr) { return ValidString (defaultVal); }
639 
640  int ValidUnitInt (ERcType _type, int defaultVal = 0) const;
641  float ValidUnitFloat (ERcType _type, float defaultVal = 0.0) const;
642  int ValidEnumIdx (ERcType _type, int defaultVal = 0) const;
644 
647  void SetType (ERcType _type) { Clear (_type); }
649  void SetState (ERcState _state) { state = _state; }
650  void SetTimeStamp (TTicks _timeStamp) { timeStamp = _timeStamp; }
651 
652  ERcType Type () const { return type; }
653  ERcState State () const { return state; }
654  TTicks TimeStamp () const { return timeStamp; }
655 
656  bool IsValid () const { return state == rcsValid; }
658  bool IsBusy () const { return state == rcsBusy; }
660  bool IsKnown () const { return state != rcsUnknown; }
662 
663  bool Equals (const CRcValueState *vs2) const;
665  bool ValueEquals (const CRcValueState *vs2) const;
668 
671  bool Convert (ERcType _type);
675 
678  const char *ToStr (CString *ret, bool withType = false, bool withTimeStamp = false, bool precise = false, int stringChars = 20) const;
687 
688  bool SetFromStr (const char *str);
719  bool SetFromStrFast (const char *str, bool warn = true);
727 
728  protected:
729  friend class CResource;
730 
731  // Fields...
732  ERcType type;
733  URcValue val;
734  ERcState state;
736 };
737 
738 
739 // Python extension...
740 #ifdef SWIG
741 %extend CRcValueState {
742  %newobject __str__ ();
743  const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
744  %newobject __repr__ ();
745  const char *__repr__ () { CString s, s1; s.SetF ("(CRcValueState) %s", $self->ToStr (&s1, true)); return s.Disown (); }
746  bool __eq__ (CRcValueState *other) { return $self->Equals (other); }
747  bool __ne__ (CRcValueState *other) { return !$self->Equals (other); }
748  %pythoncode %{
749  pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
750 
751  ## Return the value as a Python object.
752  def Value(self):
753  """Return the value as a Python object. In case of a state of 'rcsUnknown' or\n\
754  if 'self' is not defined, 'None' is returned. 'self == None' is allowed.\n\
755  """
756  if not self: return None
757  if self.State () == rcsUnknown: return None
758  t = RcTypeGetBaseType (self.Type ())
759  if t == rctBool: return self.Bool()
760  elif t == rctInt: return self.GenericInt()
761  elif t == rctFloat: return self.GenericFloat()
762  elif t == rctString: return self.GenericString()
763  elif t == rctTime: return self.Time()
764  else: return None
765 
766  ## Return the most appropriate valid value as a Python object.
767  def ValidValue(self, defaultVal):
768  """Return the value as a Python object. Unlike 'Value', this method never\n\
769  returns 'None', but reverts to the given default value, if 'self' does not\n\
770  transort a valid value. 'self == None' is tolerated\n\
771  """
772  ret = self.Value ()
773  if ret == None: ret = defaultVal
774  return ret
775  %} // %pythoncode
776 }; // %extend CRcValueState
777 #endif
778 
779 
780 #define NO_VALUE_STATE ((CRcValueState *) NULL)
782 
783 
785 #ifdef SWIG
786 %pythoncode %{
787 ## @}
788 %}
789 #endif // SWIG
790 
791 
792 
793 
794 
795 // *************************** Resources ***************************************
796 
797 
865 #ifdef SWIG
866 %pythoncode %{
867 ## @addtogroup resources_rc
868 ## @{
869 %}
870 #endif // SWIG
871 
872 
888 #ifdef SWIG
889 %feature("docstring") CResource "Home2L Resource.\n\n"
890  "This is the most central class of the library. A 'Resource' may represent\n"
891  "a sensor, an actor, a stored value, a virtual device, a mutex, an event\n"
892  "trigger - almost anything. Resources are identified by a uniform resource\n"
893  "identifier (URI)."
894 #endif
895 class CResource /* final */ {
896  public:
897 
898 
899  // ***** For applications *****
900 
903  static CResource *Get (const char *uri, bool allowWait = false);
918  static void GarbageCollection ();
931 
934  const char *Uri () { return gid.Get (); }
935  const char *Gid () { return gid.Get (); }
936  const char *Lid () { return ATOMIC_READ (lid); }
938 
939  bool Is (const char *uri);
940  bool Is (CResource *rc) { return this == rc; }
941  bool IsLike (const char *pattern);
942 
943  ERcType Type () { return valueState.type; }
944  bool IsWritable () { return writable; }
946 
949  const char *ToStr (CString *ret, bool pathLocal = false); // semi-static, iff 'pathLocal' == true!!
951 
952 #ifndef SWIG
953 
965  void GetValueState (CRcValueState *retValueState);
967 
968  // Get value (relaxed typing) ...
969  ERcState GetValue (bool *retBool, TTicks *retTimeStamp = NULL);
977  ERcState GetValue (int *retInt, TTicks *retTimeStamp = NULL);
979  ERcState GetValue (float *retFloat, TTicks *retTimeStamp = NULL);
981  ERcState GetValue (CString *retString, TTicks *retTimeStamp = NULL);
985 
986  // Get value (relaxed typing with auto-correction) ...
987  bool ValidBool (bool defaultVal = false, TTicks *retTimeStamp = NULL);
991  int ValidInt (int defaultVal = 0, TTicks *retTimeStamp = NULL);
993  float ValidFloat (float defaultVal = 0.0, TTicks *retTimeStamp = NULL);
995  const char * ValidString (CString *ret, const char *defaultVal = CString::emptyStr, TTicks *retTimeStamp = NULL);
997  TTicks ValidTime (TTicks defaultVal = 0, TTicks *retTimeStamp = NULL);
999 
1000  int ValidTrigger (int defaultVal = 0, TTicks *retTimeStamp = NULL) { return ValidInt (defaultVal, retTimeStamp); }
1002  const char * ValidMutex (CString *ret, const char *defaultVal = CString::emptyStr, TTicks *retTimeStamp = NULL) { return ValidString (ret, defaultVal, retTimeStamp); }
1004 
1005  int ValidUnitInt (ERcType _type, int defaultVal = 0, TTicks *retTimeStamp = NULL);
1007  float ValidUnitFloat (ERcType _type, float defaultVal = 0.0, TTicks *retTimeStamp = NULL);
1009  int ValidEnumIdx (ERcType _type, int defaultVal = 0, TTicks *retTimeStamp = NULL);
1011 
1013 
1014 #endif
1015 
1029 
1030  CResource *Subscribe (CRcSubscriber *subscr) { SubscribePAL (subscr); return this; }
1036  void Unsubscribe (CRcSubscriber *subscr) { UnsubscribePAL (subscr); }
1038 
1040 
1050 
1051 #ifndef SWIG
1052  void SetRequestFromObj (CRcRequest *_request);
1053  void SetRequest (CRcRequest *_request) { SetRequestFromObj (_request); }
1057  void SetRequest (CRcValueState *value, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1071  void SetRequest (bool valBool, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1073  void SetRequest (int valInt, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1075  void SetRequest (float valFloat, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1077  void SetRequest (const char *valString, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1079  void SetRequest (TTicks valTime, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks t1 = NEVER, TTicks repeat = NEVER, TTicks hysteresis = NEVER);
1081  void SetRequestFromStr (const char *reqDef);
1084 
1085  void SetTrigger (const char *reqGid, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks repeat = NEVER);
1087  void SetTriggerFromStr (const char *reqDef);
1089 
1090  void DelRequest (const char *reqGid = NULL, TTicks t1 = NEVER);
1095 
1096 #endif // SWIG
1097 
1098  bool GetRequestSet (CRcRequestSet *ret, bool allowNet = true);
1106  CRcRequest *GetRequest (const char *reqGid, bool allowNet = true);
1125 
1127 
1132 
1133 #ifndef SWIG
1134  void ReadValueState (CRcValueState *retValueState, TTicks maxTime = -1);
1138 #endif
1139  void WriteValue (CRcValueState value, int priority = rcPrioNone, const char *reqGid = "write") { SetRequest (&value, reqGid, priority); }
1142  void UnWrite (const char *reqGid = "write") { DelRequest (reqGid); }
1143 
1145 
1146 
1147  // ***** For drivers *****
1148 
1151 
1152 #ifndef SWIG
1153  static CResource *Register (CRcDriver *_rcDriver, const char *_lid, ERcType _type, bool _writable, void *_data = NULL) { return Register (NULL, _rcDriver, _lid, _type, _writable, _data); }
1172  static CResource *Register (CRcDriver *_rcDriver, const char *_lid, const char *rcTypeDef, void *_data = NULL) { return Register (NULL, _rcDriver, _lid, rcTypeDef, _data); }
1176 #endif
1177 
1180  void SetDefault (bool valBool) { SetRequest (valBool, rcDefaultRequestId, rcPrioDefault); }
1181  void SetDefault (int valInt) { SetRequest (valInt, rcDefaultRequestId, rcPrioDefault); }
1182  void SetDefault (float valFloat) { SetRequest (valFloat, rcDefaultRequestId, rcPrioDefault); }
1183  void SetDefault (const char *valString) { SetRequest (valString, rcDefaultRequestId, rcPrioDefault); }
1184  void SetDefault (TTicks valTime) { SetRequest (valTime, rcDefaultRequestId, rcPrioDefault); }
1185 
1186  void Unregister ();
1191 
1193 
1196  void SetUserData (void *_data) { ATOMIC_WRITE (rcUserData, _data); }
1198  void *UserData () { return ATOMIC_READ (rcUserData); }
1201 
1210  void ReportValueState (const CRcValueState *_valueState);
1213 #ifndef SWIG
1214  void ReportValue (bool _value, ERcState _state = rcsValid);
1215  void ReportValue (int _value, ERcState _state = rcsValid);
1216  void ReportValue (float _value, ERcState _state = rcsValid);
1217  void ReportValue (const char *_value, ERcState _state = rcsValid);
1218  void ReportValue (TTicks _value, ERcState _state = rcsValid);
1219 #endif // SWIG
1220  void ReportTrigger ();
1222  void ReportState (ERcState _state) { CRcValueState vs; vs.SetState (_state); ReportValueState (&vs); }
1226  void ReportUnknown () { ReportValueState (NULL); }
1229 
1233  void RedriveValue (bool force = true) { EvaluateRequests (force); }
1245 
1246 
1247  // ***** For info & directory services *****
1248 
1251 
1252 #ifndef SWIG
1253  const char *GetInfo (CString *ret, int verbosity = 1, bool allowNet = true);
1262 #endif
1263  void PrintInfo (FILE *f = stdout, int verbosity = 1, bool allowNet = true);
1264 
1270  CRcSubscriber *GetLocalSubscriber (int n);
1271  void UnlockLocalSubscribers () { Unlock (); }
1272 
1278  CRcRequest *GetLocalRequest (int n);
1279  void UnlockLocalRequests () { Unlock (); }
1280 
1282 
1283 #ifndef SWIG
1284 
1289 
1290  class CRcHost *Host () { return ATOMIC_READ (rcHost); }
1291  class CRcDriver *Driver () { return ATOMIC_READ (rcDriver); }
1292 
1293  unsigned RegSeq () { return ATOMIC_READ (regSeq); }
1297 
1298  bool IsRegistered () { return (ATOMIC_READ (regSeq) & 1) == 1; }
1301  bool HasSubscribers () { return ATOMIC_READ (subscrList) != NULL; }
1303  bool HasRequests () { return ATOMIC_READ (requestList) != NULL; }
1305 
1307 
1308 #endif
1309 
1310 
1311  // ***** Private *****
1312 
1313  // Constructor/destructor (private!)...
1314  // Only this class itself is allowed to create or destroy new objects.
1315  // SWIG is the only reason why the con- & destructor are not declared private.
1316 #ifndef SWIG // for not offering the constructor in the API
1317  CResource ();
1318  ~CResource ();
1319 #endif
1320 
1321  private:
1322 
1323 #ifndef SWIG
1324  friend void CResourceRequestsTimerCallback (CTimer *, void *);
1325  friend class CRcSubscriber;
1326  friend class CRcHost;
1327 #endif
1328 
1329  // Registration and life cycle management ...
1330  static CResource *GetUnregistered (const char *uri);
1331  void PutUnregistered ();
1332 
1333  static CResource *Register (CRcHost *_rcHost, CRcDriver *_rcDriver, const char *_lid, ERcType _type, bool _writable, void *_data);
1334  // Generic & main registration method; used by all other 'Registration' variants
1335  static CResource *Register (CRcHost *_rcHost, CRcDriver *_rcDriver, const char *_lid, const char *rcTypeDef, void *_data);
1336  // Register with textual description; used by full textual registration (below) and for the "external" driver
1337  // Syntax of 'rcTypeDef': <type> (ro|wr)
1338  // returns 'NULL' on error and prints a warning
1339  static CResource *Register (const char *rcDef, void *_data);
1340  // Register with full textual description; used by 'rc_core' for remote resources
1341  // Syntax: <URI> <type> (ro|wr)
1342  // returns 'NULL' on error and prints a warning
1343 
1344  // Value & state...
1345  const CRcValueState *ValueState () { return &valueState; } // 'this' must be locked as long as the returned value is accessed
1346 
1347  // Reading values...
1348  void SubscribePAL (CRcSubscriber *subscr, bool resLocked = false, bool subLocked = false);
1349  // 'resLocked' and 'subLocked' must be set if a lock on the resource or subscription is already held.
1350  // The method may temporarily release a lock to avoid deadlocks.
1351  void UnsubscribePAL (CRcSubscriber *subscr, bool resLocked = false, bool subLocked = false);
1352  // 'resLocked' and 'subLocked' must be set if a lock on the resource or subscription is already held.
1353  // The method may shortly release a lock to avoid deadlocks.
1354 
1355  // Requests...
1356  void UpdatePersistentRequestAL (const char *reqId, CRcRequest *req);
1357  bool DoDelRequestAL (CRcRequest **pList, const char *reqGid, TTicks t1, bool updatePersistence);
1358  bool DelRequestNoEvaluate (const char *reqGid, TTicks t1);
1359  void SetRequestFromObjNoEvaluate (CRcRequest *_request);
1360 
1361  CRcRequest *GetWinningRequest (TTicks t);
1362  void EvaluateRequests (bool force = false); // check and process all pending requests
1363 
1364  // Drivers ...
1365  // The '...AL' method variants assume that the resource has already been locked by the caller.
1366  void NotifySubscribers (int evType, const char *evAttr = NULL);
1367  void NotifySubscribersAL (int evType, const char *evAttr = NULL); // 'evType' is effectively of type 'ERcEventType'
1368  void ReportNetLost ();
1369  // Report that the network connection to the server was lost (like 'ReportUnknown' but
1370  // with different time stamp behaviour; see above).
1371 
1372  void ReportValueStateAL (const CRcValueState *_valueState, TTicks _timeStamp = 0);
1373  void ReportUnknownAL () { CRcValueState vs (Type ()); ReportValueStateAL (&vs); }
1374 
1375  // Driving values to the real device...
1376  void DriveValue (CRcValueState *vs, bool force);
1377  // Propagate a new requested value to the driver (to make that happen in the real device).
1378  // 'force == true': Call the driver function in any case, not only on a true VS change
1379 
1380  // Helpers...
1381  void Lock () { mutex.Lock (); }
1382  void Unlock () { mutex.Unlock (); }
1383 
1384 
1385  // BEGIN static data (never changed after the initialization of the object)...
1386  // No locking required.
1387  CString gid; // aka URI
1388 
1389  // BEGIN semi-static data ...
1390  // Fields marked with "[atomic]" must be accessed using the 'ATOMIC_*' macros on each write access and on read accesses if'this' is not locked.
1391  // Fields marked with "[mutex]" may only be accessed if 'this' is locked.
1392  // The consistency of all semi-static data as a whole is protected by the sequence lock 'regSeq'.
1393 
1394  // Resource identification...
1395  class CRcHost *rcHost; // [atomic] 'NULL' => local resource or unregistered
1396  class CRcDriver *rcDriver; // [atomic] 'NULL' => remote resource or unregistered
1397  void *rcUserData; // optional user data that can be used by the driver (driver cares for concurrent access)
1398  const char *lid; // [atomic] local resources: relative path without driver; remote: with driver name as first component; points into 'gid.Get ()'.
1399 
1400  // Resource properties...
1401  unsigned regSeq; // [atomic]
1402  bool writable, persistent; // (not "atomic" since only one byte is relevant)
1403 
1404  // BEGIN dynamic data ...
1405  // All fields may only be accessed if 'this' is locked.
1406 
1407  // Current value, its type, and its state...
1408  CRcValueState valueState; // only state and value are dynamic; 'valueState.type' is semi-static (not "atomic" since only one byte is relevant)
1409 
1410  // Internal...
1411  // 'CResource' objects are managed by a 'CDict' associated with a driver (local resources) or
1412  // host (remote resources).
1413  CMutex mutex; // protects 'this' including the request list
1414  CRcRequest *requestList;
1415  CTimer requestTimer; // timer for the next evaluation of requests
1416  CRcSubscriberLink *subscrList;
1417 };
1418 
1419 
1420 // Python extensions...
1421 #ifdef SWIG
1422 %extend CResource {
1423  %newobject __str__ ();
1424  const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1425  %newobject __repr__ ();
1426  const char *__repr__ () { CString s, s2; s.SetF ("(CResource) %s", $self->ToStr (&s2)); return s.Disown (); }
1427  bool __eq__ (CResource *other) { return $self == other; }
1428  bool __ne__ (CResource *other) { return $self != other; }
1429 
1430  %delobject SetRequestFromObj ();
1431 
1432  %feature("docstring") ValueState "Get the current value and state of the resource."
1433  %newobject ValueState ();
1434  CRcValueState *ValueState () { CRcValueState *ret = new CRcValueState (); $self->GetValueState (ret); return ret; }
1435 
1436  void _SetRequestFromObj (CRcRequest *_request) { $self->SetRequestFromObj (_request); }
1437  void _DelRequest (const char *reqGid = NULL, TTicks t1 = NEVER) { $self->DelRequest (reqGid, t1); }
1438 
1439  %pythoncode %{
1440  pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
1441 
1442  def Value (self):
1443  """Get a value ('None' if invalid) of this resource (use ValueState() to get the complete value and state)."""
1444  return self.ValueState ().Value ()
1445 
1446  def ValidValue (self, defaultVal):
1447  """Get a valid value of this resource (use ValueState() to get the complete value and state)."""
1448  return self.ValueState ().ValidValue (defaultVal)
1449 
1450  def Type (self):
1451  """Get the type of this resource."""
1452  return self.ValueState ().Type ()
1453 
1454  def SetRequest (self, reqDef = None, attrs = None, value = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
1455  """Set or delete a request with selected attributes.\n\
1456  \n\
1457  This method allows to set any subset of attributes in a flexible way, either by (named) function arguments\n\
1458  or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
1459  \n\
1460  If the effective value is 'None' (no value is passed), the call will delete the request with\n\
1461  the specified ID passing 'delDelay' as the 't1' argument of DelRequest().\n\
1462  \n\
1463  See RcSetRequest() for a detailed explanation of the arguments and examples.\n\
1464  """
1465  if RcTypeIsStringBased (self.Type ()) and reqDef != None:
1466  print ("WARNING: Setting a request to the string-type resource '" + str(self) + "' using the 'reqDef' argument is ambiguous!")
1467  req = CRcRequest ()
1468  req.Set (reqDef = reqDef, attrs = attrs, value = value, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
1469  if req.Value ().IsKnown ():
1470  req.thisown = 0 # tell swig to disown the object ([2021-01-03]: '%delobject SetRequestFromObj ()' silently does not work)
1471  self._SetRequestFromObj (req)
1472  else:
1473  self.DelRequest (req.Gid (), delDelay)
1474 
1475  def SetTrigger (self, attrs = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
1476  """Set a request for a trigger resource with selected attributes."""
1477  req = CRcRequest ()
1478  req.Set (value = 1, attrs = attrs, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
1479  req.thisown = 0 # tell swig to disown the object ([2021-01-03]: '%delobject SetRequestFromObj ()' silently does not work)
1480  self._SetRequestFromObj (req)
1481 
1482  def DelRequest (self, reqId = None, t1 = None):
1483  """Delete a request by its ID."""
1484  if t1 == None: self._DelRequest (reqId)
1485  else: self._DelRequest (reqId, TicksAbsOf (t1))
1486 
1487  def ReportValue (self, value, state = rcsValid):
1488  """Report a new value and optionally its state. If '_value == None', 'ReportUnknown()' is called."""
1489  if value == None: self.ReportUnknown ()
1490  else: self.ReportValueState (CRcValueState (self.Type (), value, state))
1491 
1492  %}
1493 }; // %extend CResource
1494 #endif
1495 
1496 
1498 #ifdef SWIG
1499 %pythoncode %{
1500 ## @}
1501 %}
1502 #endif // SWIG
1503 
1504 
1505 
1506 
1507 
1508 // *************************** Events ******************************************
1509 
1510 
1525 #ifdef SWIG
1526 %pythoncode %{
1527 ## @addtogroup resources_subscribe
1528 ## @{
1529 %}
1530 #endif // SWIG
1531 
1532 
1535  rceNone = 0,
1536 
1538 
1543 
1544  rceDriveValue
1545 };
1546 
1547 
1548 
1549 // ***** CRcEvent *****
1550 
1551 
1556 #ifdef SWIG
1557 %feature("docstring") CRcEvent "Resource events delivered by a subscriber or to a driver.\n\n"
1558  "Possible event types are:\n"
1559  " rceTimer: Timer alarm.\n"
1560  " rceValueStateChanged: The resource has changed its value.\n"
1561  " rceRequestChanged: A request has been changed or deleted. The 'ValueState ()'\n"
1562  " attribute indicates the affected request ID (type is string).\n"
1563  " rceDisconnected: The connection to the (remote) resource has\n"
1564  " been lost.\n"
1565  " rceConnected: The connection to the (remote) resource has\n"
1566  " been established (again).\n"
1567  " rceDriveValue: Drive a value (for drivers).\n"
1568  " rceNone: Nothing (dummy event: ignore).\n"
1569  "The attribute 'MorePending ()' indicates whether more events are waiting for the\n"
1570  "same subscriber. This can be used for performance optimizations to avoid\n"
1571  "unecessary recomputations."
1572 #endif
1573 class CRcEvent {
1574  public:
1575  CRcEvent (ERcEventType _type = rceNone, CResource *_resource = NULL, CRcValueState *_valueState = NULL, void *_data = NULL) { Set (_type, _resource, _valueState, _data); }
1576 
1579  void Clear () { Set (); }
1580  void Set (ERcEventType _type = rceNone, CResource *_resource = NULL, CRcValueState *_valueState = NULL, void *_data = NULL);
1590 
1591  void SetType (ERcEventType _type) { type = _type; }
1592  void SetResource (CResource *_resource) { resource = _resource; }
1593  void SetValueState (CRcValueState *_valueState);
1594  void SetData (void *_data) { data = _data; }
1596 
1599  ERcEventType Type () { return type; }
1600  CResource *Resource () { return resource; }
1601  CRcValueState *ValueState () { return &valueState; }
1603  void *Data () { return data; }
1605 
1608  const char *ToStr (CString *ret);
1610 
1611  protected:
1612  friend class CRcEventProcessor;
1613 
1614  ERcEventType type; // event type
1615  CResource *resource;
1616  CRcValueState valueState; // a) value + state for 'rceValueStateChanged'
1617  // b) value for 'rceDriveValue'
1618  // c) request ID for 'rceRequestChanged'
1619  void *data; // user data
1620 
1621  bool morePending; // After 'PollEvent'/'WaitEvent' indicates whether more events are pending for
1622  // the current subscriber to allow for optimized processing afterwards.
1623  // Note: This should only be used if either all or no events are processed by callbacks.
1624 
1625  CRcEvent *next;
1626 };
1627 
1628 
1629 // Python extension...
1630 #ifdef SWIG
1631 %extend CRcEvent {
1632  %newobject __str__ ();
1633  const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1634  %newobject __repr__ ();
1635  const char *__repr__ () { CString s, s1; s.SetF ("(CRcEvent) %s", $self->ToStr (&s1)); return s.Disown (); }
1636 }
1637 #endif
1638 
1639 
1640 
1641 // ***** CRcEventProcessor *****
1642 
1643 
1644 typedef bool FRcEventFunc (class CRcEventProcessor *, CRcEvent *, void *);
1647 
1648 
1660  public:
1661  CRcEventProcessor (bool _inSelectSet = false);
1662  virtual ~CRcEventProcessor ();
1663 
1666  void PutEvent (CRcEvent *ev);
1668 
1669 #ifndef SWIG
1670 
1673  bool PollEvent (CRcEvent *ev);
1682  bool WaitEvent (CRcEvent *ev, TTicks *maxTime = NULL);
1695  void Interrupt ();
1696  void FlushEvents ();
1699 
1712  virtual bool OnEvent (CRcEvent *ev);
1717  void SetCbOnEvent (FRcEventFunc *_cbEvent, void *_cbEventData = NULL);
1718  void ClearCbOnEvent () { SetCbOnEvent (NULL, NULL); }
1720 
1721 #endif // SWIG
1722 
1725  void SetInSelectSet (bool _inSelectSet);
1727  bool InSelectSet () { return inSelectSet; }
1728 
1729  static CRcEventProcessor *Select (TTicks maxTime = -1);
1742  // TBD: Implement 'InterruptSelect' to interrupt a waiting 'Select'
1743 
1744  virtual const char *TypeId () { return CString::emptyStr; }
1745  virtual const char *InstId () { return CString::emptyStr; }
1747 
1750  const char *ToStr (CString *ret) { return StringF (ret, "%s:%s", TypeId (), InstId ()); }
1752 
1753  private:
1754 
1755  // Internal helpers ...
1756  bool DoPollEventAL (CRcEvent *ev);
1757 
1758  void DeleteFirstEventAL ();
1759 
1760  void LinkAL ();
1761  void UnlinkAL ();
1762  bool IsLinkedAL () { return next || pLastProc == &next; }
1763 
1764  // Dynamic data (protected by 'globMutex')...
1765  static CMutex globMutex; // protects dynamic data of all event processors
1766  static CCond globCond; // global condition variable for 'Select'
1767  CCond cond; // per-object condition variable for 'WaitEvent', mutex is 'globMutex'
1768  volatile bool interrupted; // used (only) in 'WaitEvent' and 'Interrupt'
1769 
1770  FRcEventFunc *cbEvent;
1771  void *cbEventData;
1772 
1773  CRcEvent *firstEv, **pLastEv; // linked list with efficient appending
1774 
1775  bool inSelectSet;
1776  static CRcEventProcessor *firstProc, **pLastProc; // linked list of event processors with pending events
1777  CRcEventProcessor *next; // 'next' pointer for 'firstProc'/'pLastProc' list
1778 };
1779 
1780 
1781 // Python extension...
1782 #ifdef SWIG
1783 %extend CRcEventProcessor {
1784  %newobject __str__ ();
1785  const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1786  %newobject __repr__ ();
1787  const char *__repr__ () { CString s, s1; s.SetF ("(CRcEventProcessor) %s", $self->ToStr (&s1)); return s.Disown (); }
1788 
1789  %newobject PollEvent ();
1790  CRcEvent *PollEvent () {
1791  CRcEvent ev, *ret;
1792  if (!$self->PollEvent (&ev)) return NULL;
1793  ret = new CRcEvent ();
1794  *ret = ev;
1795  //~ INFOF (("### Python: Pollevent () -> %08x", ret));
1796  return ret;
1797  }
1798 }; // %extend CRcEventProcessor
1799 #endif
1800 
1801 
1802 
1803 
1804 
1805 // ***** CRcEventTimer *****
1806 
1807 
1808 #ifdef SWIG
1809 %warnfilter(401) CRcEventTimer; // class 'CTimer' is not known to SWIG
1810 #endif
1811 
1813 class CRcEventTimer: public CTimer, public CRcEventProcessor {
1814  public:
1815  CRcEventTimer (const char *_id, void *_data = NULL) { id.Set (_id); Set (_data); }
1816  CRcEventTimer (TTicks _time, TTicks _interval = 0, void *_data = NULL) { Set (_time, _interval, _data); }
1817 
1818  void Set (void *_data) { CTimer::Set (NULL, _data, NULL); }
1820  void Set (TTicks _time, TTicks _interval = 0, void *_data = NULL) { CTimer::Set (_time, _interval, NULL, _data, NULL); }
1822 
1823  virtual void OnTime () { CRcEvent ev (rceTimer, NULL, NULL, data); PutEvent (&ev); }
1824 
1825  virtual const char *TypeId () { return "T"; } // hint for Python/SWIG API
1826  virtual const char *InstId () { return id.Get (); } // hint for Python/SWIG API
1827 
1828  protected:
1829  CString id;
1830 };
1831 
1832 
1834 #ifdef SWIG
1835 %pythoncode %{
1836 ## @}
1837 %}
1838 #endif // SWIG
1839 
1840 
1841 
1842 
1843 
1844 // *************************** Subscribers *************************************
1845 
1846 
1851 #ifdef SWIG
1852 %pythoncode %{
1853 ## @addtogroup resources_subscribe
1854 ## @{
1855 %}
1856 #endif // SWIG
1857 
1858 
1859 
1873 #ifdef SWIG
1874 %feature("docstring") CRcSubscriber "Subscription to any number of resources.\n\n"
1875  "A subscriber monitors any number of resources. The resources can be\n"
1876  "specified by their real URIs or alias names. Wildcards as well as\n"
1877  "presently unkown resources are allowed. Events can be fetched using\n"
1878  "'Select ()' and 'PollEvent'.\n"
1879 #endif
1881  public:
1882  CRcSubscriber () { resourceList = NULL; }
1883  CRcSubscriber (const char *_lid) { resourceList = NULL; Register (_lid); }
1884  virtual ~CRcSubscriber () { Unregister (); }
1885 
1888  bool Register (const char *_lid);
1891  void Unregister ();
1894 
1897  const char *Lid () { return lid.Get (); }
1898  const char *Gid () { return gid.Get (); }
1899 
1900  virtual const char *TypeId () { return "S"; } // hint for Python/SWIG API
1901  virtual const char *InstId () { return Lid (); } // hint for Python/SWIG API
1902 
1903  const char *ToStr (CString *ret);
1904 
1905  bool IsEmpty () { return resourceList == NULL && watchSet.Entries () == 0; }
1907 
1910  CResource *AddResource (CResource *rc);
1911  CResource *AddResources (const char *pattern);
1928  void DelResource (CResource *rc);
1929  void DelResources (const char *pattern);
1940  void Clear ();
1943 
1946  CResource *Subscribe (CResource *rc) { return AddResource (rc); }
1947  CResource *Subscribe (const char *uri) { return AddResources (uri); }
1948  void Unsubscribe (CResource *rc) { DelResource (rc); }
1949  void Unsubscribe (const char *pattern) { DelResources (pattern); }
1951 
1954 #ifndef SWIG
1955  void GetInfo (CString *ret, int verbosity = 1);
1957  static void GetInfoAll (CString *ret, int verbosity = 1);
1959  void GetPatternSet (CKeySet *retPatternSet);
1961 #endif // #ifndef SWIG
1962  void PrintInfo (FILE *f = stdout, int verbosity = 1);
1964 
1965  protected:
1966  friend class CResource;
1967  friend class CRcServer;
1968 
1969  // Locking...
1970  void Lock () { mutex.Lock (); } // INFOF (("# Thread #%08x: CRcSubscriber::Lock ()", pthread_self ()));
1971  void Unlock () { mutex.Unlock (); } // INFOF (("# Thread #08x: CRcSubscriber::Unlock ()", pthread_self ()));
1972 
1973  // Notifications from resource...
1974  void CheckNewResource (CResource *resource); // check if new resource fits a watch pattern and eventually adds it
1975  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.
1976  void NotifyAL (CRcEvent *ev) { PutEvent (ev); } // process an event from a resource; caller remains owner of 'ev'
1977 
1978  // Interaction with network server...
1979  void RegisterAsAgent (const char *_gid);
1980  // Alternative to 'Register' - register as an agent for some other (remote client) host.
1981  bool IsAgent () { return lid.Get () == gid.Get (); } // subscriber is an agent
1982 
1983  // Static data...
1984  CString lid, gid;
1985 
1986  // Dynamic data (protected by the mutex)...
1987  CMutex mutex;
1988  CResourceLink *resourceList;
1989  CKeySet watchSet; // contains URI patterns to be checked if new resources are registered
1990 };
1991 
1992 
1993 // Python extension...
1994 #ifdef SWIG
1995 %extend CRcSubscriber {
1996  %newobject __str__ ();
1997  const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
1998  %newobject __repr__ ();
1999  const char *__repr__ () { CString s, s1; s.SetF ("(CRcSubscriber) %s", $self->ToStr (&s1)); return s.Disown (); }
2000 }; // %extend CRcSubscriber
2001 #endif
2002 
2003 
2005 #ifdef SWIG
2006 %pythoncode %{
2007 ## @}
2008 %}
2009 #endif // SWIG
2010 
2011 
2012 
2013 
2014 
2015 // *************************** Requests ****************************************
2016 
2017 
2020 #ifdef SWIG
2021 %pythoncode %{
2022 ## @addtogroup resources_requests
2023 ## @{
2024 %}
2025 #endif // SWIG
2026 
2027 
2028 const char *RcGetUserRequestId ();
2030 const char *RcGetUserRequestAttrs ();
2032 
2033 
2044 #ifdef SWIG
2045 %feature("docstring") CRcRequest "Request specifications.\n\n"
2046  "Request objects define the request for a certain value together with some\n"
2047  "additional attributes. The concept of requests is introduced to deal with\n"
2048  "potentially concurrent write accesses to resources. Besides the requested\n"
2049  "value, a request has the following attributes:\n"
2050  " - a unique GID by which it can be later be changed or deleted.\n"
2051  " - a priority (see also: comments on the 'prio*' constants)\n"
2052  " - a start (on) time (optional)\n"
2053  " - an expiration (off) time (optional)\n"
2054  " - a hysteresis to avoid too frequent value changes (optional)"
2055 #endif
2056 class CRcRequest {
2057  public:
2058  CRcRequest () { Reset (); }
2059 #ifndef SWIG
2060  CRcRequest (CRcRequest *req) { Reset (); Set (req); }
2062  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); }
2064  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); }
2066  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); }
2068  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); }
2070  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); }
2072  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); }
2074 #endif // SWIG
2075 
2076  ~CRcRequest () {}
2077 
2080 
2081  void Reset ();
2084 
2085  void Set (CRcRequest *req);
2087  void Set (CRcValueState *_value = NULL, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2101 #ifndef SWIG
2102  void Set (bool _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2103  void Set (int _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2104  void Set (float _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2105  void Set (const char *_value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2106  void Set (TTicks _value, const char *_gid = NULL, int _priority = rcPrioNone, TTicks _t0 = NEVER, TTicks _t1 = NEVER, TTicks _repeat = NEVER, TTicks _hysteresis = NEVER);
2107 #endif // SWIG
2108 
2109  void SetValue (CRcValueState *_value);
2110  void SetValue (bool _value);
2111  void SetValue (int _value);
2112  void SetValue (float _value);
2113  void SetValue (const char *_value);
2114  void SetValue (TTicks _value);
2115 
2116  void SetGid (const char *_gid) { gid.Set (_gid); }
2117 
2118  void SetPriority (int _priority) { priority = _priority; }
2119  void SetTimeOn (TTicks _t0) { t0 = _t0; }
2120  void SetTimeOff (TTicks _t1) { t1 = _t1; }
2121  void SetRepeat (TTicks _repeat) { repeat = _repeat; }
2122  void SetHysteresis (TTicks _hysteresis) { hysteresis = _hysteresis; }
2123 
2124  void SetForTrigger ();
2127 
2130  void Convert (CResource *rc, bool warn = true);
2134 
2137 
2138  bool IsCompatible () { return isCompatible; }
2140  const char *Gid () { return gid.Get (); }
2143  const char *Origin () { return origin.Get (); }
2148 
2149  ERcType Type () { return value.Type (); }
2150  CRcValueState *Value () { return &value; }
2151  int Priority () { return priority; }
2152  TTicks TimeOn () { return t0; }
2153  TTicks TimeOff () { return t1; }
2154  TTicks Repeat () { return repeat; }
2155  TTicks Hysteresis () { return hysteresis; }
2156 
2158 
2161 
2162  bool SetFromStr (const char *str);
2172 
2173  bool SetAttrsFromStr (const char *str);
2208 
2209  const char *ToStr (CString *ret, bool precise = true, bool tabular = false, TTicks relativeTimeThreshold = NEVER, const char *skipAttrs = CString::emptyStr);
2226 
2228 
2229  protected:
2230  friend class CResource;
2231 
2232  void SetOrigin ();
2233  bool SetSingleAttrFromStr (const char *str);
2234 
2235  // Fields...
2236  bool isCompatible;
2237  CString gid, origin;
2238  CRcValueState value;
2239  int priority;
2240  TTicks t0, t1; // start and end time (NEVER = not set); t0 == t1 => value is set once (and may then stay)
2241  TTicks repeat; // repeat interval (ignored, if t0 == 0)
2242  TTicks hysteresis; // hysteresis in milliseconds
2243 
2244  // Internal fields...
2245  // Requests are managed as a linked list associated with a 'CResource' object.
2246  CRcRequest *next;
2247 };
2248 
2249 
2250 // Python extension...
2251 
2252 #ifdef SWIG
2253 %extend CRcRequest {
2254 
2255  %newobject __str__ ();
2256  const char *__str__ () { CString s; $self->ToStr (&s); return s.Disown (); }
2257  %newobject __repr__ ();
2258  const char *__repr__ () { CString s, s1; s.SetF ("(CRcRequest) %s", $self->ToStr (&s1)); return s.Disown (); }
2259  %pythoncode %{
2260  pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
2261 
2262  ## Versatile setter.
2263  def Set (self, reqDef = None, attrs = None, value = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
2264  """Set value and/or selected request attributes.\n\
2265  \n\
2266  This method allows to set any subset of attributes in a flexible way, either by (named) function arguments\n\
2267  or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
2268  \n\
2269  See RcSetRequest() for a detailed explanation of the arguments and examples.\n\
2270  """
2271  if reqDef != None:
2272  if isinstance (reqDef, str): self.SetFromStr (reqDef)
2273  elif value == None: value = reqDef
2274  if attrs != None: self.SetAttrsFromStr (attrs)
2275  if value != None: self.SetValue (value)
2276  if id != None: self.SetGid (id)
2277  if priority != None: self.SetPriority (priority)
2278  if t0 != None:
2279  ticks = TicksAbsOf (t0)
2280  if ticks: self.SetTimeOn (ticks)
2281  else: print ("WARNING: Invalid time specification '" + str(t0) + "' - ignoring!")
2282  if t1 != None:
2283  ticks = TicksAbsOf (t1)
2284  if ticks: self.SetTimeOff (ticks)
2285  else: print ("WARNING: Invalid time specification '" + str(t1) + "' - ignoring!")
2286  if repeat != None:
2287  ticks = TicksRelOf (repeat)
2288  if ticks: self.SetRepeat (ticks)
2289  else: print ("WARNING: Invalid time specification '" + str(repeat) + "' - ignoring!")
2290  if hysteresis != None: self.SetHysteresis (hysteresis)
2291 
2292  %} // %pythoncode
2293 }; // %extend CRcRequest
2294 #endif
2295 
2296 
2297 const char *RcGetUserRequestId ();
2299 const char *RcGetUserRequestAttrs ();
2301 
2302 
2304 #ifdef SWIG
2305 %pythoncode %{
2306 ## @}
2307 %}
2308 #endif // SWIG
2309 
2310 
2311 
2312 
2313 
2314 // *************************** Drivers *****************************************
2315 
2316 
2337 #ifdef SWIG
2338 %pythoncode %{
2339 ## @addtogroup resources_drivers
2340 ## @{
2341 %}
2342 #endif // SWIG
2343 
2344 
2345 #ifndef SWIG
2346 
2347 
2350 
2351  // For linking in C drivers...
2352  rcdOpInit = 0,
2361 
2362  // Using a base-class 'CRcDriver' object to drive something...
2363  rcdOpStop,
2369 };
2370 
2371 
2379 
2380 
2381 #define HOME2L_DRIVER(NAME) \
2382  extern "C" { void Home2lRcDriverFunc_##NAME (ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *); } \
2383  void Home2lRcDriverFunc_##NAME
2419 
2420 
2430 class CRcDriver {
2431  public:
2432  CRcDriver (const char *_lid, FRcDriverFunc *_func = NULL) { lid.Set (_lid); func = _func; }
2433  virtual ~CRcDriver () {}
2434 
2437  void Register ();
2441  static void RegisterAndInit (const char *_lid, FRcDriverFunc *_func);
2443  void Unregister ();
2448 
2451  const char *Lid () { return lid.Get (); }
2452  const char *ToStr (CString *) { return lid.Get (); }
2454 
2457  CResource *RegisterResource (const char *rcLid, ERcType _type, bool _writable, void *_data = NULL) { return CResource::Register (this, rcLid, _type, _writable, _data); }
2458  CResource *RegisterResource (const char *rcLid, const char *rcTypeDef, void *_data = NULL) { return CResource::Register (this, rcLid, rcTypeDef, _data); }
2464  void PrintInfo (FILE *f = stdout);
2465 
2466  CResource *GetResource (const char *rcLid) { return resourceMap.Get (rcLid); }
2467 
2468  int LockResources () { Lock (); return resourceMap.Entries (); }
2469  CResource *GetResource (int n) { return resourceMap.Get (n); }
2470  void UnlockResources () { Unlock (); }
2472 
2473  protected:
2474  friend class CResource;
2475  friend void RcDriversStop ();
2476 
2479  virtual void Stop ();
2482  virtual void DriveValue (CResource *rc, CRcValueState *vs);
2514 
2517  void Lock () { mutex.Lock (); }
2518  void Unlock () { mutex.Unlock (); }
2519 
2520  void ClearResources ();
2522 
2523  // Static data...
2524  CString lid;
2525  FRcDriverFunc *func;
2526 
2527  // Dynamic data (protected by the mutex)...
2528  CMutex mutex;
2529  CDictRef<CResource> resourceMap; // object does not own the resources; when deleted here, they must be unregistered manually.
2530 };
2531 
2532 
2533 #endif // #ifndef SWIG
2534 
2535 
2536 #ifdef SWIG
2537 %warnfilter(401) CRcEventDriver; // class 'CRcDriver' is not known to SWIG
2538 #endif
2539 
2540 
2546 class CRcEventDriver: public CRcDriver, public CRcEventProcessor {
2547  public:
2548  CRcEventDriver (const char *_lid, ERcState _successState = rcsBusy): CRcDriver (_lid) { successState = _successState; }
2556 
2557 #ifndef SWIG
2558  virtual const char *TypeId () { return "D"; } // hint for Python/SWIG API
2559  virtual const char *InstId () { return Lid (); } // hint for Python/SWIG API
2560 
2561  protected:
2562  virtual void Stop () {}
2563  virtual void DriveValue (CResource *rc, CRcValueState *vs);
2564 
2565  ERcState successState;
2566 #endif
2567 };
2568 
2569 
2571 #ifdef SWIG
2572 %pythoncode %{
2573 ## @}
2574 %}
2575 #endif // SWIG
2576 
2577 
2578 
2579 
2580 
2581 // ************ Directory operations and host/driver/resource lookup ***********
2582 
2583 
2590 #ifdef SWIG
2591 %pythoncode %{
2592 ## @addtogroup resources_directory
2593 ## @{
2594 %}
2595 #endif // SWIG
2596 
2597 
2598 
2599 // ***** Hosts *****
2600 
2601 
2604 
2605 int RcGetHosts ();
2606 CRcHost *RcGetHost (int n);
2607 
2608 CRcHost *RcGetHost (const char *id);
2609 const char *RcGetHostId (CRcHost *host);
2610 
2612 #ifndef SWIG
2613 extern CString localHostId;
2614 #endif
2615 static inline const char *RcLocalHostId () { return localHostId.Get (); }
2616 #ifdef SWIG
2617 %pythoncode %{
2618  pass
2619 
2620  ## Return a list of all known hosts (including our own one as #0).
2621  def RcHosts ():
2622  """Return a list of all known hosts (including our own one as #0)."""
2623  num = RcGetHosts ()
2624  ret = [ RcLocalHostId () ]
2625  for i in range (num):
2626  ret += [ RcGetHostId (RcGetHost (i)) ]
2627  return ret
2628 %}
2629 #endif
2630 
2632 
2633 
2634 
2635 // ***** Drivers (local) *****
2636 
2637 
2640 
2641 int RcGetDrivers ();
2642 CRcDriver *RcGetDriver (int n);
2643 
2644 CRcDriver *RcGetDriver (const char *lid);
2645 const char *RcGetDriverId (CRcDriver *cur);
2646 
2647 #ifdef SWIG
2648 %pythoncode %{
2649  pass
2650 
2651  ## Return a list of all locally defined drivers.
2652  def RcDrivers ():
2653  """Return a list of all locally defined drivers."""
2654  num = RcGetDrivers ()
2655  ret = []
2656  for i in range (num):
2657  ret += [ RcGetDriverId (RcGetDriver (i)) ]
2658  return ret
2659 %}
2660 #endif
2661 
2663 
2664 
2665 
2666 // ***** Resources *****
2667 
2668 
2671 
2672 int RcLockHostResources (CRcHost *host);
2678 CResource *RcGetHostResource (CRcHost *host, int n);
2679 void RcUnlockHostResources (CRcHost *host);
2680 
2681 int RcLockDriverResources (CRcDriver *driver);
2686 CResource *RcGetDriverResource (CRcDriver *driver, int n);
2687 void RcUnlockDriverResources (CRcDriver *driver);
2688 
2689 #ifdef SWIG
2690 %pythoncode %{
2691  pass
2692 
2693  ## Return all known resources of a remote host.
2694  def RcHostResources (hostName):
2695  """Return all known resources of a host. '/local' is an alias for the local host ID."""
2696  ret = []
2697  if hostName == RcLocalHostId () or hostName == "/local":
2698  for d in RcDrivers ():
2699  ret += RcDriverResources (d)
2700  else:
2701  h = RcGetHost (hostName)
2702  num = RcLockHostResources (h)
2703  for i in range (num):
2704  ret += [ RcGetHostResource (h, i).Uri () ]
2705  RcUnlockHostResources (h)
2706  return ret
2707 
2708  ## Return all local resources managed by a driver.
2709  def RcDriverResources (driverName):
2710  """Return all local resources managed by a driver."""
2711  d = RcGetDriver (driverName)
2712  num = RcLockDriverResources (d)
2713  ret = []
2714  for i in range (num):
2715  ret += [ RcGetDriverResource (d, i).Uri () ]
2716  RcUnlockDriverResources (d)
2717  return ret
2718 
2719  ## Return a complete list of all known resources.
2720  def RcResources ():
2721  """Return a complete list of all known resources."""
2722  ret = []
2723  for d in RcDrivers ():
2724  ret += RcDriverResources (d)
2725  for h in RcHosts ():
2726  ret += RcHostResources (h)
2727  return ret
2728 
2729 %}
2730 #endif // SWIG
2731 
2733 
2734 
2735 
2736 // ***** Subscribers *****
2737 
2738 
2741 
2742 #ifndef SWIG
2743 int RcLockSubscribers ();
2748 CRcSubscriber *RcGetSubscriber (int n);
2749 void RcUnlockSubscribers ();
2750 #endif
2751 
2753 
2754 
2755 // Requests and per-resource subscribers: see 'class CResource'
2756 
2757 
2759 #ifdef SWIG
2760 %pythoncode %{
2761 ## @}
2762 %}
2763 #endif // SWIG
2764 
2765 
2766 
2767 
2768 
2769 
2770 // *************************** High-level API **********************************
2771 
2772 
2773 // ***** General functions *****
2774 
2775 
2778 #ifdef SWIG
2779 %pythoncode %{
2780 ## @addtogroup resources_general
2781 ## @{
2782 %}
2783 #endif // SWIG
2784 
2785 
2786 #ifndef SWIG
2787 
2788 
2791 void RcInit (bool enableServer = false, bool inBackground = false);
2800 void RcStart ();
2803 void RcDone ();
2807 
2814 void RcIterate ();
2816 int RcRun (bool catchSignals = true);
2821 void RcStop ();
2825 
2826 #endif
2827 
2828 
2829 
2830 // ***** Looking up resources *****
2831 
2832 
2835 #ifdef SWIG
2836 %pythoncode %{
2837 ## @name Accessing resources ...
2838 ## @{
2839 %}
2840 #endif // SWIG
2841 
2842 
2843 #ifdef SWIG
2844 %feature("docstring") RcGetResource "Lookup a resource by its URI and return a reference to it."
2845 %feature("docstring") RcGet "Lookup a resource by its URI and return a reference to it (shortcut for 'RcGetResource()')."
2846 #endif
2847 
2848 static inline CResource *RcGetResource (const char *uri, bool allowWait = false) { return CResource::Get (uri, allowWait); }
2861 static inline CResource *RcGet (const char *uri, bool allowWait = false) { return CResource::Get (uri, allowWait); }
2863 
2865 static inline void RcGarbageCollection () { CResource::GarbageCollection (); }
2870 void RcBump (CResource *rc = NULL, bool soft = false);
2879 
2880 
2882 #ifdef SWIG
2883 %pythoncode %{
2884 ## @}
2885 %}
2886 #endif // SWIG
2887 
2888 
2889 
2890 // ***** Subscriptions *****
2891 
2892 
2895 #ifdef SWIG
2896 %pythoncode %{
2897 ## @name Subscriptions (from C/C++ API) ...
2898 ## Low-level operations to directly create and use @ref CRcSubscriber objects.
2899 ## Most probably, you will not need these functions.
2900 ## The preferred way in Python is to use the more compfortable decorators and
2901 ## operations in section "Subscriptions, events and timers (Python API)" below.
2902 ## @{
2903 %}
2904 #endif // SWIG
2905 
2906 
2907 #ifdef SWIG
2908 %feature("docstring") RcNewSubscriber "Create and register a new subscriber object, optionally subscribe to resources."
2909 %feature("docstring") RcUnsubscribeFromAll "Unsubscribe to all resources managed by the subscriber."
2910 %newobject RcNewSubscriber (const char *, CResource *);
2911 %newobject RcNewSubscriber (const char *, const char *);
2912 #endif
2913 
2914 CRcSubscriber *RcNewSubscriber (const char *subscrLid, CResource *rc = NULL);
2919 CRcSubscriber *RcNewSubscriber (const char *subscrLid, const char *pattern);
2924 
2925 static inline CRcSubscriber *RcSubscribe (CRcSubscriber *subscr, CResource *rc) { subscr->AddResource (rc); return subscr; }
2927 static inline CRcSubscriber *RcSubscribe (CRcSubscriber *subscr, const char *pattern) { subscr->AddResources (pattern); return subscr; }
2929 
2930 static inline void RcUnsubscribeFromAll (CRcSubscriber *subscr) { subscr->Clear (); }
2933 #ifndef SWIG
2934 static inline void RcUnsubscribeFromAll (CRcSubscriber **pSubscr) { if (*pSubscr) { delete *pSubscr; *pSubscr = NULL; } }
2936 #endif
2938 
2940 #ifdef SWIG
2941 %pythoncode %{
2942 ## @}
2943 %}
2944 #endif // SWIG
2945 
2946 
2947 
2948 // ***** Placing requests *****
2949 
2950 
2953 #ifdef SWIG
2954 %pythoncode %{
2955 ## @name Placing requests ...
2956 ## Details on the request arguments can be found in the
2957 ## [*C/C++ API documentation*](../home2l-api_c/classCRcRequest.html)
2958 ## and the [*Home2L Book*](../home2l-book.pdf).
2959 ## @{
2960 %}
2961 #endif // SWIG
2962 
2963 
2964 #ifndef SWIG
2965 
2966 // Requests...
2967 
2968 static inline void RcSetRequest (CResource *rc, CRcRequest *req) { rc->SetRequest (req); }
2969 void RcSetRequest (const char *rcUri, CRcRequest *req);
2973 static 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); }
2974 void 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);
2987 static 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); }
2988 void 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);
2990 static 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); }
2991 void 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);
2993 static 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); }
2994 void 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);
2996 static 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); }
2997 void 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);
2999 static inline void RcSetRequestFromStr (CResource *rc, const char *reqDef) { rc->SetRequestFromStr (reqDef); }
3000 void RcSetRequestFromStr (const char *rcUri, const char *reqDef);
3004 static inline void RcSetTrigger (CResource *rc, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks repeat = NEVER) { rc->SetTrigger (reqGid, priority, t0, repeat); }
3005 void RcSetTrigger (const char *rcUri, const char *reqGid = NULL, int priority = rcPrioNone, TTicks t0 = NEVER, TTicks repeat = NEVER);
3007 static inline void RcSetTriggerFromStr (CResource *rc, const char *reqDef) { rc->SetTriggerFromStr (reqDef); }
3008 void RcSetTriggerFromStr (const char *rcUri, const char *reqDef);
3010 
3011 static inline void RcDelRequest (CResource *rc, const char *reqGid = NULL, TTicks t1 = NEVER) { rc->DelRequest (reqGid, t1); }
3012 void RcDelRequest (const char *rcUri, const char *reqGid = NULL, TTicks t1 = NEVER);
3021 
3022 #else // SWIG
3023 
3024 %feature("docstring") RcSetRequest "Add or change a request to a resource."
3025 %feature("docstring") RcDelRequest "Delete a request from a resource."
3026 %feature("docstring") RcSetTrigger "Add a trigger request."
3027 
3028 %pythoncode %{
3029 
3030  def RcSetRequest (rc, reqDef = None, attrs = None, value = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
3031  """Set a request to a resource with selected attributes.\n\
3032  \n\
3033  The attributes can be set in a flexible way, either by (named) function arguments\n\
3034  or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
3035  \n\
3036  The parameters have the following meanings:\n\
3037  \n\
3038  - reqDef = full definition as a single string '<val> [<attrs>]' or just the value\n\
3039  Note: To avoid ambiguities, values of type string should never be passed by this,\n\
3040  but by the 'value' and 'attrs' arguments instead.\n\
3041  If 'reqDef' is not a string instance, it is used as a value ('val').\n\
3042  - attrs = attribute string (similar to 'reqDef', but without the first field interpreted as value)\n\
3043  \n\
3044  - value = value (any type or string)\n\
3045  - id = request ID [default = instance name]\n\
3046  - priority = request priority (0..9) [default = 3 (= rcPrioNormal)]\n\
3047  - t0 = on time\n\
3048  - t1 = off time\n\
3049  - repeat = repetition interval\n\
3050  - hysteresis = hysteresis time\n\
3051  - delDelay = deletion delay (if no value is passed and the call is used to delete the request)\n\
3052  \n\
3053  Information on the syntax of textual request definition can be found in the Home2L Book and\n\
3054  in the C/C++ API documentation for CRcRequest::SetFromStr(). Arguments representing absolute times\n\
3055  (e.g. 't0', 't1') can have any type and format as accepted by 'TicksAbsOf()'.\n\
3056  Arguments representing relative times (e.g. 'repeat', 'hysteresis', 'delDelay') can have any type\n\
3057  and format as accepted by 'TicksRelOf()'.\n\
3058  \n\
3059  If an attribute is set both by means of a string ('reqDef' or 'attrs') or a named parameter,\n\
3060  the named parameter is taken. If no attributes are specified, their defaults as specified in [...]\n\
3061  above are used.\n\
3062  \n\
3063  If the effective value is 'None' (no value is passed), the call will delete the request with\n\
3064  the specified ID passing 'delDelay' as the the 't1' argument of RcDelRequest().\n\
3065  \n\
3066  Examples:\n\
3067  \n\
3068  - Request integer value 7 with default attributes:\n\
3069  RcSetRequest (rc, 7);\n\
3070  RcSetRequest (rc, '7');\n\
3071  RcSetRequest (rc, value = '7');\n\
3072  RcSetRequest (rc, reqDef = '7');\n\
3073  \n\
3074  - Request integer value 7 with ID '#user' and priority 3:\n\
3075  RcSetRequest (rc, 7, id = 'user', priority = 3);\n\
3076  RcSetRequest (rc, 7, '#user *3');\n\
3077  RcSetRequest (rc, '7 #user *3');\n\
3078  \n\
3079  - Delete this request again:\n\
3080  RcSetRequest (rc, value = None, id = 'user');\n\
3081  RcSetRequest (rc, '? #user');\n\
3082  \n\
3083  - Delete this request in 5 seconds:\n\
3084  RcSetRequest (rc, value = None, id = 'user', delDelay = '5s');\n\
3085  \n\
3086  - Request string value 'Hello *3' with priority 5 and an off time at 6pm today:\n\
3087  RcSetRequest (rc, value = 'Hello *3', attrs = '*5 -18:00');\n\
3088  RcSetRequest (rc, value = 'Hello *3', prio = 5, t1 = '-18:00');\n\
3089  \n\
3090  - Set request with user-supplied attributes, some of which must not be changed by user\n\
3091  RcSetRequest (rc, 7, userAttrs, t1 = '-23:00') # t1 overrides an eventual off time in userAttrs\n\
3092  \n\
3093  - Set request with user-supplied attributes and defaults\n\
3094  req = CRcRequest (val = 7, t1 = '-23:00') # Set value and default attributes\n\
3095  req->Set (attrs = userAttrs) # userAttrs may override t1\n\
3096  \n\
3097  """
3098  if isinstance (rc, str): rc = RcGetResource (rc)
3099  rc.SetRequest (reqDef = reqDef, attrs = attrs, value = value, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis, delDelay = delDelay)
3100 
3101  def RcSetTrigger (rc, attrs = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
3102  """Set a request to a trigger resource with selected attributes."""
3103  if isinstance (rc, str): rc = RcGetResource (rc)
3104  rc.SetRequest (attrs = attrs, value = 1, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
3105 
3106  def RcDelRequest (rc, id = None, t1 = None):
3107  """Delete a request."""
3108  if isinstance (rc, str): rc = RcGetResource (rc)
3109  rc.DelRequest (id, t1)
3110 
3111  def RcSetDefault (rc, reqDef = None, attrs = None, value = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
3112  """Set a default request."""
3113  if isinstance (rc, str): rc = RcGetResource (rc)
3114  rc.SetRequest (reqDef = reqDef, attrs = attrs, value = value, id = rcDefaultRequestId, priority = rcPrioDefault, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
3115 
3116 %} // %pythoncode
3117 #endif // SWIG
3118 
3119 
3120 
3121 // Mutex operations (TBD:future) ...
3122 //~ static inline CRcSubscriber *RcMutexRequestLock (const char *rcUri, const char *regGid, CRcSubscriber *subscr == NULL) { RcSetRequest (rcUri, reqGid, reqGid); return subscr; }
3123 //~ void RcMutexWaitLock (const char *rcUri, const char *regGid, CRcSubscriber *subscr);
3124 //~ bool RcMutexPollLock (const char *rcUri, const char *regGid, CRcSubscriber *subscr);
3125 //~ void RcMutexUnlock (const char *rcUri, const char *regGid, CRcSubscriber *subscr);
3126 
3127 
3129 #ifdef SWIG
3130 %pythoncode %{
3131 ## @}
3132 %}
3133 #endif // SWIG
3134 
3135 
3136 
3137 // ***** Drivers *****
3138 
3139 
3144 #ifdef SWIG
3145 %pythoncode %{
3146 ## @name Drivers (from C/C++ API) ...
3147 ## Low-level operations to directly create and use 'CRcDriver' objects.
3148 ## Most probably, you will not need these functions.
3149 ## The preferred way in Python is to use the more compfortable decorators and
3150 ## operations in module "Home2L / Drivers".
3151 ## @{
3152 %}
3153 #endif // SWIG
3154 
3155 
3156 
3157 #ifdef SWIG
3158 %feature("docstring") RcRegisterDriver "Register a new driver."
3159 %feature("docstring") RcRegisterResource "Register a new resource to a driver."
3160 %feature("docstring") RcRegisterSignal "Register a new signal for the built-in 'signal' driver."
3161 #endif
3162 
3165 #ifndef SWIG
3166 static inline void RcRegisterDriver (CRcDriver *drv) { drv->Register (); }
3168 static inline void RcRegisterDriver (const char *drvLid, FRcDriverFunc *func) { CRcDriver::RegisterAndInit (drvLid, func); }
3171 #endif
3172 CRcEventDriver *RcRegisterDriver (const char *drvLid, ERcState _successState = rcsNoReport);
3187 
3191 #ifndef SWIG
3192 static inline CResource *RcRegisterResource (CRcDriver *drv, const char *rcLid, ERcType _type, bool _writable, void *_data = NULL) { return CResource::Register (drv, rcLid, _type, _writable, _data); }
3193 static inline CResource *RcRegisterResource (CRcDriver *drv, const char *rcLid, const char *rcTypeDef, void *_data = NULL) { return CResource::Register (drv, rcLid, rcTypeDef, _data); }
3194 #endif
3195 CResource *RcRegisterResource (const char *drvLid, const char *rcLid, ERcType _type, bool _writable, void *_data = NULL);
3196 CResource *RcRegisterResource (const char *drvLid, const char *rcLid, const char *rcTypeDef, void *_data = NULL);
3197 
3198 CResource *RcRegisterSignal (const char *name, ERcType type);
3200 CResource *RcRegisterSignal (const char *name, CRcValueState *vs);
3204 
3205 
3207 #ifdef SWIG
3208 %pythoncode %{
3209 ## @}
3210 %}
3211 #endif // SWIG
3212 
3213 
3214 
3215 
3216 // ***** Executing shell commands *****
3217 
3218 // TBD
3219 
3220 
3221 
3222 
3224 #ifdef SWIG
3225 %pythoncode %{
3226 ## @}
3227 %}
3228 #endif // SWIG
3229 
3230 
3231 
3232 
3233 
3234 
3235 // ***** Doxygen Footer *****
3236 
3238 #ifdef SWIG
3239 %pythoncode %{
3240 ## @}
3241 %}
3242 #endif // SWIG
3243 
3244 
3245 
3246 #endif // _RC_LIB_
Class to wrap (POSIX) condition variables.
Definition: base.H:1738
Dictionary.
Definition: base.H:1193
Set of strings (keys).
Definition: base.H:1304
int Entries() const
Get number of entries.
Definition: base.H:948
Class to wrap (POSIX) mutex objects.
Definition: base.H:1721
Driver for local resources.
Definition: resources.H:2433
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:2549
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:2562
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:2565
CRcEventDriver(const char *_lid, ERcState _successState=rcsBusy)
Initialize the driver (does not register).
Definition: resources.H:2551
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:2561
Event processor.
Definition: resources.H:1659
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:1744
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'.
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'.
static CRcEventProcessor * Select(TTicks maxTime=-1)
Wait until any of the existing 'CRcEventProcessor' objects has an event available.
void FlushEvents()
Remove all presently queued events; also waits until a concurrently running OnEvent() invocation retu...
virtual bool OnEvent(CRcEvent *ev)
Handle an event asynchronously (may have been called from any thread)
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:1745
void Interrupt()
Request a running WaitEvent() to stop now.
Timer that sends 'rceTimer' events over the event system.
Definition: resources.H:1813
virtual void OnTime()
[T:timer] Virtual function called when the timer triggers.
Definition: resources.H:1823
void Set(void *_data)
Setup timer without (re-)scheduling it.
Definition: resources.H:1818
void Set(TTicks _time, TTicks _interval=0, void *_data=NULL)
Setup and (re-)schedule timer (see CTimer::Set() ).
Definition: resources.H:1820
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:1826
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:1825
Events delivered by a subscriber or to a driver.
Definition: resources.H:1573
CRcValueState * ValueState()
Get the value/state attribute of the event. See Set() for further details.
Definition: resources.H:1601
const char * ToStr(CString *ret)
Get a readable string.
void Set(ERcEventType _type=rceNone, CResource *_resource=NULL, CRcValueState *_valueState=NULL, void *_data=NULL)
Set event attributes.
Request description object.
Definition: resources.H:2056
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:2060
const char * Origin()
Origin of the request. It is automatically set by Reset() to the request creation information in the ...
Definition: resources.H:2143
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:2068
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:2120
void SetRepeat(TTicks _repeat)
Set repetition interval (argument must be != NEVER).
Definition: resources.H:2121
void SetHysteresis(TTicks _hysteresis)
Set hysteresis (argument must be != NEVER).
Definition: resources.H:2122
void Reset()
Clear the value and set default attributes ( NO_VALUE_STATE, NEVER, NULL or equivalent; priority = rc...
CRcRequest()
Default constructor.
Definition: resources.H:2058
bool IsCompatible()
Returns whether the request is compatible with the type of the resource recently passed to Convert().
Definition: resources.H:2138
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:2140
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:2062
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:2070
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:2118
void SetGid(const char *_gid)
Set GID (argument must be != NULL).
Definition: resources.H:2116
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:2119
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.
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().
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:2066
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:2064
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:2072
Subscriber to follow an arbitrary set of resources.
Definition: resources.H:1880
void Clear()
Remove all resources.
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
Definition: resources.H:1901
void Unregister()
Clear and unregister the subscriber.
void GetPatternSet(CKeySet *retPatternSet)
Get current pattern set. Patterns from the watch set are followed by a "?".
void DelResources(const char *pattern)
Remove resources by pattern. See AddResources() for details on possible patterns.
static void GetInfoAll(CString *ret, int verbosity=1)
Get info for all subscribers of this instance (see GetInfo() for info on 'verbosity').
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Definition: resources.H:1900
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...
CResource * AddResources(const char *pattern)
Add new resources by pattern. The pattern is also stored internally to catch possible resources added...
Typed value tagged with a state and a time stamp.
Definition: resources.H:485
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:536
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:647
bool Equals(const CRcValueState *vs2) const
Strict comparison: state, type and value must match exactly; time stamps are not compared.
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 IsKnown() const
State is either rcsValid or rcsBusy; In other words: the value can be retrieved.
Definition: resources.H:660
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:532
void SetGenericInt(int _val, ERcType _type, ERcState _state=rcsValid)
Set from integer or boolean.
void Clear(ERcType _type, ERcState _state=rcsUnknown)
Clear to default value:
TTicks timeStamp
time of last value/state change or trigger
Definition: resources.H:735
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:489
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:526
void SetToReportBusyOldVal()
Modify object to auto-report a busy state with no value change. Note: Only for use in CRcDriver::Driv...
Definition: resources.H:528
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,...
bool IsBusy() const
State is rcsBusy, neither rcsValid nor rcsUnknown.
Definition: resources.H:658
void Clear()
Clear value, set state to 'rcsUnknown', and leave type unchanged.
Definition: resources.H:508
bool IsValid() const
State is rcsValid, neither rcsBusy nor rcsUnknown.
Definition: resources.H:656
Home2L Resource.
Definition: resources.H:895
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...
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:1172
void ReportState(ERcState _state)
Report state change only, value remains unmodified.
Definition: resources.H:1222
unsigned RegSeq()
The 'regSeq' number is incremented each time the resource is registered or unregistered....
Definition: resources.H:1293
void SetTriggerFromStr(const char *reqDef)
Set trigger request by textual definition.
CResource * Subscribe(CRcSubscriber *subscr)
Subscribe to this resource. The caller remains owner of 'subscr'.
Definition: resources.H:1030
void SetRequest(CRcRequest *_request)
Add or replace a request (generic version).
Definition: resources.H:1053
const char * GetInfo(CString *ret, int verbosity=1, bool allowNet=true)
Get textual information on this resource.
void Unsubscribe(CRcSubscriber *subscr)
Unsubscribe to this resource.
Definition: resources.H:1036
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.
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:936
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.
void * UserData()
Retrieve user-specified data.
Definition: resources.H:1198
int LockLocalSubscribers()
Return number of all active local subscribers for a resource and lock this object....
bool Is(CResource *rc)
Check identity (for Python & eventual wrapper classes).
Definition: resources.H:940
ERcState GetValue(CString *retString, TTicks *retTimeStamp=NULL)
Get a value of type "string" or a type based on it.
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...
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:1153
void SetUserData(void *_data)
Set user-specified data for this resource.
Definition: resources.H:1196
float ValidUnitFloat(ERcType _type, float defaultVal=0.0, TTicks *retTimeStamp=NULL)
Get a valid unit-type float value.
void ReportTrigger()
For triggers, this method must be called.
void Unregister()
Unregister a resource.
CRcRequest * GetRequest(const char *reqGid, bool allowNet=true)
Query a request by its request GID.
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:1139
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.
const char * Uri()
Get the URI (aka global ID / GID).
Definition: resources.H:934
void SetDefault(CRcValueState *vs)
Set a default value.
Definition: resources.H:1178
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:1301
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.
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.
bool HasRequests()
Return whether this resource has requests (dynamic, not semi-static).
Definition: resources.H:1303
static CResource * Get(const char *uri, bool allowWait=false)
Look up a resource by its URI and return a reference to it.
void ReportUnknown()
Report an unknown state.
Definition: resources.H:1226
void WaitForRegistration()
Wait until registered or a network timeout occured.
const char * ValidString(CString *ret, const char *defaultVal=CString::emptyStr, TTicks *retTimeStamp=NULL)
Get a valid string value.
void ReportBusy()
Report a busy state (without changing the value).
Definition: resources.H:1224
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,...
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).
void RedriveValue(bool force=true)
Drive the currently requested value again.
Definition: resources.H:1233
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".
const char * Gid()
Get the global ID.
Definition: resources.H:935
const char * ValidMutex(CString *ret, const char *defaultVal=CString::emptyStr, TTicks *retTimeStamp=NULL)
Get a valid mutex value.
Definition: resources.H:1002
int ValidTrigger(int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid trigger value.
Definition: resources.H:1000
Dynamically allocated string.
Definition: base.H:635
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
static const char *const emptyStr
Use this whenever you need an empty string ("")
Definition: base.H:676
void SetF(const char *fmt,...)
Set using printf() formatting.
char * Disown()
Return current string as a dynamic object and clear 'this'.
Timer class.
Definition: base.H:1580
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:1376
#define NEVER
Special value that may represent "never" for absolute or monotonic times. Other application-specific ...
Definition: base.H:1381
#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 ()'.
const char * RcGetHostId(CRcHost *host)
Get textual ID of 'host'.
CRcHost * RcGetHost(int n)
Get reference to host n, 0 <= n < number of hosts.
int RcLockHostResources(CRcHost *host)
Query number of resources for a remote host.
static const char * RcLocalHostId()
Get the ID of the local instance.
Definition: resources.H:2618
int RcGetHosts()
Get number of known hosts.
int RcLockSubscribers()
Query the number of existing subscribers and lock the subscriber database.
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:2372
ERcDriverOperation
Driver operations.
Definition: resources.H:2349
@ rcdOpDriveValue
Drive a value; refers to CRcDriver::DriveValue(). Parameters: CRcDriver *driver, CResource *rc,...
Definition: resources.H:2366
@ rcdOpInit
Initialize driver object(s) of a linked-in driver. Parameter: CRcDriver *drv.
Definition: resources.H:2352
@ rcdOpStop
Stop the driver; refers to CRcDriver::Stop(). Parameter: CRcDriver *drv.
Definition: resources.H:2363
void RcIterate()
Perform pending actions, call TimerIterate() and return.
static void RcGarbageCollection()
(For experts) Remove all presently unregistered resources from memory.
Definition: resources.H:2868
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.
CResource * RcRegisterSignal(const char *name, ERcType type)
Register a new resource for the built-in 'signal' driver.
void RcDone()
Shutdown the Resources library.
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...
static CResource * RcGetResource(const char *uri, bool allowWait=false)
Lookup a resource by its URI and return a reference to it.
Definition: resources.H:2851
void RcDelRequest(const char *rcUri, const char *reqGid=NULL, TTicks t1=NEVER)
Delete a request.
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:2864
static void RcUnsubscribeFromAll(CRcSubscriber *subscr)
Unsubscribe from all resources presently subscribed by 'subscr'. The caller remains owner of 'subscr'...
Definition: resources.H:2933
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:3169
void RcSetRequestFromStr(const char *rcUri, const char *reqDef)
Set request by textual definition - see CRcRequest::SetFromStr() and the Home2L Book for more informa...
static CRcSubscriber * RcSubscribe(CRcSubscriber *subscr, CResource *rc)
Subscribe to an additional resource.
Definition: resources.H:2928
CRcSubscriber * RcNewSubscriber(const char *subscrLid, CResource *rc=NULL)
Create and register a new subscriber object and optionally subscribe to the given resource.
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:212
CDict< CRcRequest > CRcRequestSet
Set of requests (for CResource::GetRequestSet() )
Definition: resources.H:226
#define rcPrioNone
Undefined priority (special value)
Definition: resources.H:221
bool FRcEventFunc(class CRcEventProcessor *, CRcEvent *, void *)
Event processor callback function. Example: bool OnEventFunc (CRcEventProcessor *ep,...
Definition: resources.H:1644
ERcEventType
Event type.
Definition: resources.H:1534
@ rceDisconnected
[subscriber] Connection to resource was lost
Definition: resources.H:1541
@ rceValueStateChanged
[subscriber] Value or state has changed
Definition: resources.H:1539
@ rceTimer
[timer] Timer alarm
Definition: resources.H:1537
@ rceNone
None (for dummy events)
Definition: resources.H:1535
@ rceConnected
[subscriber] Connection to resource is (re-)established
Definition: resources.H:1542
@ rceDriveValue
[driver] Drive a new value
Definition: resources.H:1544
@ rceRequestChanged
[subscriber] Request has changed
Definition: resources.H:1540
ERcState
Resource state.
Definition: resources.H:454
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:385
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:359
ERctWindowState
Window state (for 'rctWindowState')
Definition: resources.H:394
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,...
ERctPhoneState
Phone state (for 'rctPhoneState')
Definition: resources.H:403
static bool RcTypeIsEnumType(ERcType t)
Return whether the type is a enumeration type.
Definition: resources.H:365
ERcType
Resource major type.
Definition: resources.H:276
ERctPlayerState
Music player state (for 'rctPlayerState')
Definition: resources.H:411
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:460
@ rcsUnknown
Value is presently unknown (e.g. outdated).
Definition: resources.H:455
@ rcsValid
Value is valid.
Definition: resources.H:457
@ rcsBusy
Devices is busy and/or switching to the value indicated by the associate value.
Definition: resources.H:456
@ rcvUseVacation
User is away temporarily (e.g. for work)
Definition: resources.H:389
@ rcvUseNight
User is at home and present at day time.
Definition: resources.H:387
@ rcvUseAway
User is at home, but sleeping (e.g. doors should be locked)
Definition: resources.H:388
@ rcvWindowTilted
closed
Definition: resources.H:396
@ rcvWindowOpenOrTilted
(wide) open
Definition: resources.H:398
@ rcvWindowOpen
tilted
Definition: resources.H:397
@ rcvPhoneInCall
idle
Definition: resources.H:405
@ rcvPhoneRinging
in call, including any 'psDialing' and 'psTransfer...' states (anything where a user is actively usin...
Definition: resources.H:406
@ rctPercent
[float] Percentage (0.0 .. 100.0)
Definition: resources.H:320
@ rctMutex
[rctString] resource represents a mutex (not implemented yet)
Definition: resources.H:293
@ rctTime
Time.
Definition: resources.H:286
@ rctString
String.
Definition: resources.H:284
@ rctUseState
Use/presence state ("day", "night", "away", "vacation")
Definition: resources.H:335
@ rctWindowState
Window opening state ("closed", "tilted", "open", "openOrTilted")
Definition: resources.H:337
@ rctTrigger
[rctInt] Resource does not carry a value, but can transport events ("triggers"); 'vTriggerCount' coun...
Definition: resources.H:292
@ rctPhoneState
Phone state ("idle", "ringing", "inCall")
Definition: resources.H:339
@ rctPlayerState
Music player state ("stop", "pause", "play")
Definition: resources.H:341
@ rctInt
Integer.
Definition: resources.H:282
@ rctTemp
[float] Temperature in degree centigrade
Definition: resources.H:322
@ rctNone
No type.
Definition: resources.H:277
@ rctBool
Boolean.
Definition: resources.H:281
@ rctFloat
Float.
Definition: resources.H:283
@ rcvPlayerPlaying
paused
Definition: resources.H:414
@ rcvPlayerPaused
stopped
Definition: resources.H:413