110## @defgroup resources Resources
111## @brief The *Home2L Resources* library.
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.
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.
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).
128## @defgroup resources_general Main API
129## @brief Top-level functionality of the *Resources* library - most commonly used functions can be found here.
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).
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).
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).
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).
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).
152## @defgroup resources_drivers Drivers
153## @brief Low-level access to the C/C++ driver-related classes.
154## More details can be found in the [*C/C++ API documentation*](../home2l-api_c/group__resources__drivers.html).
155## Normally, the functions and decorators described in module [*Home2L / Resources*](group__home2l__resources.html)
156## should be used to define custom drivers in Python.
180class CRcSubscriberLink;
194## @addtogroup resources_requests
211#define rcPrioNormal 3
214#define rcPrioDefault 0
215#define rcPrioRuleMin 1
217#define rcPrioRuleMax 5
220#define rcPrioSafety 8
221#define rcPrioIKnowWhatImDoing 9
252## @addtogroup resources_values
264#define rctBasicTypesBase rctBool
265#define rctBasicTypesLast rctTime
267#define rctSpecialTypesBase rctTrigger
268#define rctSpecialTypesLast rctMutex
270#define rctUnitTypesBase 0x40
271#define rctUnitTypesLast (rctUnitTypesEND-1)
273#define rctEnumTypesBase 0x80
274#define rctEnumTypesLast (rctEnumTypesEND-1)
352const char *RcTypeGetName (
ERcType t);
353ERcType RcTypeGetFromName (
const char *name);
415 rcvPlayerStopped = 0,
446STATIC_ASSERT(
sizeof (URcValue) ==
sizeof (URcValue::vAny));
476%feature(
"docstring")
CRcValueState "Typed value tagged with a state and a time stamp.\n\n"
477 "The constants for type '
ERcType' have the prefix 'rct*'."
478 "The state may be one of:\n"
480 " '
rcsBusy': The value is known, the underlying device is busy.\n"
481 " '
rcsValid': The value is known and stable.\n"
482 "The time stamp reflects the age of a value (last change/update). It is\n"
483 "generally not valid to judge from the time stamp whether the value is\n"
484 "outdated, since there are other mechanisms in the library setting the\n"
485 "state to '
rcsUnknown' if, for example, the connection to a remote resource\n"
590 bool Bool ()
const {
ASSERT (type ==
rctBool);
return val.vBool; }
591 int Int ()
const {
ASSERT (type ==
rctInt);
return val.vInt; }
592 float Float ()
const {
ASSERT (type ==
rctFloat);
return val.vFloat; }
593 const char * String ()
const {
ASSERT (type ==
rctString);
return val.vString; }
597 const char * Mutex ()
const {
ASSERT (type ==
rctMutex);
return val.vString; }
599 int UnitInt (
ERcType _type)
const {
ASSERT (type == _type);
return val.vInt; }
600 float UnitFloat (
ERcType _type)
const {
ASSERT (type == _type);
return val.vFloat; }
619 ERcState GetValue (
float *retFloat);
634 bool ValidBool (
bool defaultVal =
false);
635 int ValidInt (
int defaultVal = 0);
636 float ValidFloat (
float defaultVal = 0.0);
640 int ValidTrigger (
int defaultVal = 0) {
return ValidInt (defaultVal); }
641 const char * ValidMutex (
const char *defaultVal =
CString::emptyStr) {
return ValidString (defaultVal); }
643 int ValidUnitInt (
ERcType _type,
int defaultVal = 0)
const;
644 float ValidUnitFloat (
ERcType _type,
float defaultVal = 0.0)
const;
645 int ValidEnumIdx (
ERcType _type,
int defaultVal = 0)
const;
652 void SetState (
ERcState _state) { state = _state; }
655 ERcType Type ()
const {
return type; }
656 ERcState State ()
const {
return state; }
681 const char *
ToStr (
CString *ret,
bool withType =
false,
bool withTimeStamp =
false,
bool precise =
false,
int stringChars = 20)
const;
756 %newobject __str__ ();
757 const char *__str__ () {
CString s; $self->ToStr (&s);
return s.
Disown (); }
758 %newobject __repr__ ();
759 const char *__repr__ () {
CString s, s1; s.
SetF (
"(CRcValueState) %s", $self->ToStr (&s1,
true));
return s.
Disown (); }
760 bool __eq__ (
CRcValueState *other) {
return $self->Equals (other); }
761 bool __ne__ (
CRcValueState *other) {
return !$self->Equals (other); }
763 pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
765 ## Return the value as a Python object.
767 """Return the value as a Python object. In case of a state of 'rcsUnknown' or\n\
768 if 'self' is not defined, 'None' is returned. 'self == None' is allowed.\n\
770 if not self: return None
773 if t ==
rctBool: return self.Bool()
774 elif t ==
rctInt: return self.GenericInt()
775 elif t ==
rctFloat: return self.GenericFloat()
776 elif t ==
rctString: return self.GenericString()
777 elif t ==
rctTime: return self.Time()
780 ## Return the most appropriate valid value as a Python object.
781 def ValidValue(self, defaultVal):
782 """Return the value as a Python object. Unlike 'Value', this method never\n\
783 returns 'None', but reverts to the given default value, if 'self' does not\n\
784 transort a valid value. 'self == None' is tolerated\n\
787 if ret == None: ret = defaultVal
794#define NO_VALUE_STATE ((CRcValueState *) NULL)
881## @addtogroup resources_rc
903%feature(
"docstring")
CResource "Home2L Resource.\n\n"
904 "This is the most central class of the library. A 'Resource' may represent\n"
905 "a sensor, an actor, a stored value, a virtual device, a mutex, an event\n"
906 "trigger - almost anything. Resources are identified by a uniform resource\n"
948 const char *
Uri () {
return gid.
Get (); }
949 const char *
Gid () {
return gid.
Get (); }
950 const char *
Lid () {
return ATOMIC_READ (lid); }
953 bool Is (
const char *uri);
957 bool IsWritable () {
return writable; }
962 const char *ToStr (
CString *ret,
bool pathLocal =
false);
1029 ERcType Type ()
const {
return ATOMIC_READ (valueState.type); }
1030 ERcState State ()
const {
return ATOMIC_READ (valueState.state); }
1031 TTicks TimeStamp ()
const {
return ATOMIC_READ (valueState.
timeStamp); }
1083 void SetRequestFromObj (
CRcRequest *_request);
1173 void UnWrite (
const char *reqGid =
"write") {
DelRequest (reqGid); }
1294 void PrintInfo (FILE *f = stdout,
int verbosity = 1,
bool allowNet =
true);
1302 void UnlockLocalSubscribers () { Unlock (); }
1310 void UnlockLocalRequests () { Unlock (); }
1321 class CRcHost *Host () {
return ATOMIC_READ (rcHost); }
1322 class CRcDriver *Driver () {
return ATOMIC_READ (rcDriver); }
1324 unsigned RegSeq () {
return ATOMIC_READ (regSeq); }
1329 bool IsRegistered () {
return (ATOMIC_READ (regSeq) & 1) == 1; }
1355 friend void CResourceRequestsTimerCallback (
CTimer *,
void *);
1357 friend class CRcHost;
1361 static CResource *GetUnregistered (
const char *uri);
1362 void PutUnregistered ();
1379 void SubscribePAL (
CRcSubscriber *subscr,
bool resLocked =
false,
bool subLocked =
false);
1382 void UnsubscribePAL (
CRcSubscriber *subscr,
bool resLocked =
false,
bool subLocked =
false);
1387 void UpdatePersistentRequestAL (
const char *reqId,
CRcRequest *req);
1388 bool DoDelRequestAL (
CRcRequest **pList,
const char *reqGid,
TTicks t1,
bool updatePersistence);
1389 bool DelRequestNoEvaluate (
const char *reqGid,
TTicks t1);
1390 void SetRequestFromObjNoEvaluate (
CRcRequest *_request);
1393 void EvaluateRequests (
bool force =
false);
1397 void NotifySubscribers (
int evType,
const char *evAttr = NULL);
1398 void NotifySubscribersAL (
int evType,
const char *evAttr = NULL);
1399 void ReportNetLost ();
1404 void ReportUnknownAL () {
CRcValueState vs (Type ()); ReportValueStateAL (&vs); }
1412 void Lock () { mutex.Lock (); }
1413 void Unlock () { mutex.Unlock (); }
1426 class CRcHost *rcHost;
1433 bool writable, persistent;
1447 CRcSubscriberLink *subscrList;
1454 %newobject __str__ ();
1455 const char *__str__ () {
CString s; $self->ToStr (&s);
return s.
Disown (); }
1456 %newobject __repr__ ();
1457 const char *__repr__ () {
CString s, s2; s.
SetF (
"(CResource) %s", $self->ToStr (&s2));
return s.
Disown (); }
1458 bool __eq__ (
CResource *other) {
return $self == other; }
1459 bool __ne__ (
CResource *other) {
return $self != other; }
1461 %delobject SetRequestFromObj ();
1463 %feature(
"docstring") ValueState "Get the current value and state of the resource."
1464 %newobject ValueState ();
1467 void _SetRequestFromObj (
CRcRequest *_request) { $self->SetRequestFromObj (_request); }
1468 void _DelRequest (
const char *reqGid = NULL,
TTicks t1 =
NEVER) { $self->DelRequest (reqGid, t1); }
1471 pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
1474 """Get a value ('None' if invalid) of this resource (use ValueState() to get the complete value and state)."""
1475 return self.ValueState ().Value ()
1477 def ValidValue (self, defaultVal):
1478 """Get a valid value of this resource (use ValueState() to get the complete value and state)."""
1479 return self.ValueState ().ValidValue (defaultVal)
1481 def SetRequest (self, reqDef = None, attrs = None, value = None,
id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
1482 """Set or delete a request with selected attributes.\n\
1484 This method allows to set any subset of attributes in a flexible way, either by (named) function arguments\n\
1485 or by a textual description as accepted by the Home2L Shell or
CRcRequest::SetFromStr().\n\
1487 If the effective value is 'None' (no value is passed), the call will delete the request with\n\
1488 the specified ID passing 'delDelay' as the 't1' argument of DelRequest().\n\
1490 See
RcSetRequest() for a detailed explanation of the arguments and examples.\n\
1493 print ("
WARNING: Setting a request to the
string-type resource '" + str(self) + "' using the 'reqDef' argument is ambiguous!")
1495 req.Set (reqDef = reqDef, attrs = attrs, value = value,
id =
id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
1496 if req.Value ().IsKnown ():
1497 req.thisown = 0
# tell swig to disown the object ([2021-01-03]: '%delobject SetRequestFromObj ()' silently does not work)
1498 self._SetRequestFromObj (req)
1500 self.DelRequest (req.Gid (), delDelay)
1502 def SetTrigger (self, attrs = None,
id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
1503 """Set a request for a trigger resource with selected attributes."""
1505 req.Set (value = 1, attrs = attrs,
id =
id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
1506 req.thisown = 0
# tell swig to disown the object ([2021-01-03]: '%delobject SetRequestFromObj ()' silently does not work)
1507 self._SetRequestFromObj (req)
1509 def DelRequest (self, reqId = None, t1 = None):
1510 """Delete a request by its ID."""
1511 if t1 == None: self._DelRequest (reqId)
1512 else: self._DelRequest (reqId, TicksAbsOf (t1))
1514 def ReportValue (self, value, state =
rcsValid):
1515 """Report a new value and optionally its state. If '_value == None', 'ReportUnknown()' is called."""
1516 if value == None: self.ReportUnknown ()
1517 else: self.ReportValueState (
CRcValueState (self.Type (), value, state))
1554## @addtogroup resources_subscribe
1584%feature(
"docstring")
CRcEvent "Resource events delivered by a subscriber or to a driver.\n\n"
1585 "Possible event types are:\n"
1588 "
rceRequestChanged: A request has been changed or deleted. The 'ValueState ()'\n"
1589 " attribute indicates the affected request ID (type is
string).\n"
1592 "
rceConnected: The connection to the (remote) resource has\n"
1593 " been established (again).\n"
1595 "
rceNone: Nothing (dummy event: ignore).\n"
1596 "The attribute 'MorePending ()' indicates whether more events are waiting for the\n"
1597 "same subscriber. This can be used for performance optimizations to avoid\n"
1598 "unecessary recomputations."
1606 void Clear () {
Set (); }
1619 void SetResource (
CResource *_resource) { resource = _resource; }
1621 void SetData (
void *_data) { data = _data; }
1627 CResource *Resource () {
return resource; }
1630 void *Data () {
return data; }
1659 %newobject __str__ ();
1660 const char *__str__ () {
CString s; $self->ToStr (&s);
return s.
Disown (); }
1661 %newobject __repr__ ();
1662 const char *__repr__ () {
CString s, s1; s.
SetF (
"(CRcEvent) %s", $self->ToStr (&s1));
return s.
Disown (); }
1744 void SetCbOnEvent (
FRcEventFunc *_cbEvent,
void *_cbEventData = NULL);
1745 void ClearCbOnEvent () { SetCbOnEvent (NULL, NULL); }
1754 bool InSelectSet () {
return inSelectSet; }
1785 void DeleteFirstEventAL ();
1789 bool IsLinkedAL () {
return next || pLastProc == &next; }
1793 static CCond globCond;
1795 volatile bool interrupted;
1811 %newobject __str__ ();
1812 const char *__str__ () {
CString s; $self->ToStr (&s);
return s.
Disown (); }
1813 %newobject __repr__ ();
1814 const char *__repr__ () {
CString s, s1; s.
SetF (
"(CRcEventProcessor) %s", $self->ToStr (&s1));
return s.
Disown (); }
1816 %newobject PollEvent ();
1819 if (!$self->PollEvent (&ev))
return NULL;
1852 virtual const char *
TypeId () {
return "T"; }
1853 virtual const char *
InstId () {
return id.Get (); }
1880## @addtogroup resources_subscribe
1901%feature(
"docstring")
CRcSubscriber "Subscription to any number of resources.\n\n"
1902 "A subscriber monitors any number of resources. The resources can be\n"
1903 "specified by their real URIs or alias names. Wildcards as well as\n"
1904 "presently unkown resources are allowed. Events can be fetched using\n"
1905 "'Select ()' and 'PollEvent'.\n"
1924 const char *Lid () {
return lid.
Get (); }
1925 const char *Gid () {
return gid.
Get (); }
1927 virtual const char *
TypeId () {
return "S"; }
1928 virtual const char *
InstId () {
return Lid (); }
1930 const char *ToStr (
CString *ret);
1932 bool IsEmpty () {
return resourceList == NULL && watchSet.
Entries () == 0; }
1975 void Unsubscribe (
CResource *rc) { DelResource (rc); }
1976 void Unsubscribe (
const char *pattern) {
DelResources (pattern); }
1989 void PrintInfo (FILE *f = stdout,
int verbosity = 1);
1994 friend class CRcServer;
1997 void Lock () { mutex.Lock (); }
1998 void Unlock () { mutex.Unlock (); }
2001 void CheckNewResource (
CResource *resource);
2002 void UnlinkResourceAL (
CResource *resource);
2006 void RegisterAsAgent (
const char *_gid);
2008 bool IsAgent () {
return lid.
Get () == gid.
Get (); }
2015 CResourceLink *resourceList;
2023 %newobject __str__ ();
2024 const char *__str__ () {
CString s; $self->ToStr (&s);
return s.
Disown (); }
2025 %newobject __repr__ ();
2026 const char *__repr__ () {
CString s, s1; s.
SetF (
"(CRcSubscriber) %s", $self->ToStr (&s1));
return s.
Disown (); }
2049## @addtogroup resources_requests
2072%feature(
"docstring")
CRcRequest "Request specifications.\n\n"
2073 "Request objects define the request for a certain value together with some\n"
2074 "additional attributes. The concept of requests is introduced to deal with\n"
2075 "potentially concurrent write accesses to resources. Besides the requested\n"
2076 "value, a request has the following attributes:\n"
2077 " - a unique GID by which it can be later be changed or deleted.\n"
2078 " - a priority (see also: comments on the 'prio*' constants)\n"
2079 " - a start (on) time (optional)\n"
2080 " - an expiration (off) time (optional)\n"
2081 " - a hysteresis to avoid too frequent value changes (optional)"
2089 CRcRequest (
CRcValueState *_value,
const char *_gid = NULL,
int _priority =
rcPrioNone,
TTicks _t0 =
NEVER,
TTicks _t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks _hysteresis =
NEVER) {
Reset ();
Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2091 CRcRequest (
bool _value,
const char *_gid = NULL,
int _priority =
rcPrioNone,
TTicks _t0 =
NEVER,
TTicks _t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks _hysteresis =
NEVER) {
Reset ();
Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2093 CRcRequest (
int _value,
const char *_gid = NULL,
int _priority =
rcPrioNone,
TTicks _t0 =
NEVER,
TTicks _t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks _hysteresis =
NEVER) {
Reset ();
Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2095 CRcRequest (
float _value,
const char *_gid = NULL,
int _priority =
rcPrioNone,
TTicks _t0 =
NEVER,
TTicks _t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks _hysteresis =
NEVER) {
Reset ();
Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2097 CRcRequest (
const char *_value,
const char *_gid = NULL,
int _priority =
rcPrioNone,
TTicks _t0 =
NEVER,
TTicks _t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks _hysteresis =
NEVER) {
Reset ();
Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2099 CRcRequest (
TTicks _value,
const char *_gid = NULL,
int _priority =
rcPrioNone,
TTicks _t0 =
NEVER,
TTicks _t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks _hysteresis =
NEVER) {
Reset ();
Set (_value, _gid, _priority, _t0, _t1, _hysteresis); }
2140 void SetValue (
const char *_value);
2143 void SetGid (
const char *_gid) { gid.Set (_gid); }
2176 ERcType Type () {
return value.Type (); }
2178 int Priority () {
return priority; }
2179 TTicks TimeOn () {
return t0; }
2180 TTicks TimeOff () {
return t1; }
2181 TTicks Repeat () {
return repeat; }
2182 TTicks Hysteresis () {
return hysteresis; }
2260 bool SetSingleAttrFromStr (
const char *str);
2282 %newobject __str__ ();
2283 const char *__str__ () {
CString s; $self->ToStr (&s);
return s.
Disown (); }
2284 %newobject __repr__ ();
2285 const char *__repr__ () {
CString s, s1; s.
SetF (
"(CRcRequest) %s", $self->ToStr (&s1));
return s.
Disown (); }
2287 pass # (Workaround to keep SWIG from scrambling the indentation of the following code.)
2289 ## Versatile setter.
2290 def Set (self, reqDef = None, attrs = None, value = None,
id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
2291 """Set value and/or selected request attributes.\n\
2293 This method allows to set any subset of attributes in a flexible way, either by (named) function arguments\n\
2294 or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
2296 See RcSetRequest() for a detailed explanation of the arguments and examples.\n\
2299 if isinstance (reqDef, str): self.SetFromStr (reqDef)
2300 elif value == None: value = reqDef
2301 if attrs != None: self.SetAttrsFromStr (attrs)
2302 if value != None: self.SetValue (value)
2303 if id != None: self.SetGid (id)
2304 if priority != None: self.SetPriority (priority)
2306 ticks = TicksAbsOf (t0)
2307 if ticks: self.SetTimeOn (ticks)
2308 else: print (
"WARNING: Invalid time specification '" + str(t0) +
"' - ignoring!")
2310 ticks = TicksAbsOf (t1)
2311 if ticks: self.SetTimeOff (ticks)
2312 else: print (
"WARNING: Invalid time specification '" + str(t1) +
"' - ignoring!")
2314 ticks = TicksRelOf (repeat)
2315 if ticks: self.SetRepeat (ticks)
2316 else: print (
"WARNING: Invalid time specification '" + str(repeat) +
"' - ignoring!")
2317 if hysteresis != None: self.SetHysteresis (hysteresis)
2366## @addtogroup resources_drivers
2408#define HOME2L_DRIVER(NAME) \
2409 extern "C" { void Home2lRcDriverFunc_##NAME (ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *); } \
2410 void Home2lRcDriverFunc_##NAME
2478 const char *Lid () {
return lid.
Get (); }
2479 const char *ToStr (
CString *) {
return lid.
Get (); }
2485 CResource *RegisterResource (
const char *rcLid,
const char *rcTypeDef,
void *_data = NULL) {
return CResource::Register (
this, rcLid, rcTypeDef, _data); }
2491 void PrintInfo (FILE *f = stdout);
2493 CResource *GetResource (
const char *rcLid) {
return resourceMap.Get (rcLid); }
2495 int LockResources () { Lock ();
return resourceMap.
Entries (); }
2496 CResource *GetResource (
int n) {
return resourceMap.Get (n); }
2497 void UnlockResources () { Unlock (); }
2502 friend void RcDriversStop ();
2506 virtual void Stop ();
2544 void Lock () { mutex.Lock (); }
2545 void Unlock () { mutex.Unlock (); }
2585 virtual const char *
TypeId () {
return "D"; }
2586 virtual const char *
InstId () {
return Lid (); }
2619## @addtogroup resources_directory
2647 ## Return a list of all known hosts (including our own one as #0).
2649 """Return a list of all known hosts (including our own one as #0)."""
2652 for i in range (num):
2671CRcDriver *RcGetDriver (
const char *lid);
2672const char *RcGetDriverId (
CRcDriver *cur);
2678 ## Return a list of all locally defined drivers.
2680 """Return a list of all locally defined drivers."""
2681 num = RcGetDrivers ()
2683 for i in range (num):
2684 ret += [ RcGetDriverId (RcGetDriver (i)) ]
2705CResource *RcGetHostResource (CRcHost *host,
int n);
2706void RcUnlockHostResources (CRcHost *host);
2714void RcUnlockDriverResources (
CRcDriver *driver);
2720 ## Return all known resources of a remote host.
2721 def RcHostResources (hostName):
2722 """Return all known resources of a host. '/local' is an alias for the local host ID."""
2725 for d in RcDrivers ():
2726 ret += RcDriverResources (d)
2730 for i in range (num):
2731 ret += [ RcGetHostResource (h, i).Uri () ]
2732 RcUnlockHostResources (h)
2735 ## Return all local resources managed by a driver.
2736 def RcDriverResources (driverName):
2737 """Return all local resources managed by a driver."""
2738 d = RcGetDriver (driverName)
2741 for i in range (num):
2742 ret += [ RcGetDriverResource (d, i).Uri () ]
2743 RcUnlockDriverResources (d)
2746 ## Return a complete list of all known resources.
2748 """Return a complete list of all known resources."""
2750 for d in RcDrivers ():
2751 ret += RcDriverResources (d)
2752 for h in RcHosts ():
2753 ret += RcHostResources (h)
2776void RcUnlockSubscribers ();
2807## @addtogroup resources_general
2818void RcInit (
bool enableServer =
false,
bool inBackground =
false);
2843int RcRun (
bool catchSignals =
true);
2864## @name Accessing resources ...
2871%feature(
"docstring")
RcGetResource "Lookup a resource by its URI and return a reference to it."
2872%feature("docstring")
RcGet "Lookup a resource by its URI and return a reference to it (shortcut for '
RcGetResource()')."
2924## @name Subscriptions (from C/C++ API) ...
2925## Low-level operations to directly create and use @ref CRcSubscriber objects.
2926## Most probably, you will not need these functions.
2927## The preferred way in Python is to use the more compfortable decorators and
2928## operations in section "Subscriptions, events and timers (Python API)" below.
2935%feature(
"docstring")
RcNewSubscriber "Create and register a new subscriber
object, optionally subscribe to resources."
2936%feature("docstring")
RcUnsubscribeFromAll "Unsubscribe to all resources managed by the subscriber."
2982## @name Placing requests ...
2983## Details on the request arguments can be found in the
2984## [*C/C++ API documentation*](../home2l-api_c/classCRcRequest.html)
2985## and the [*Home2L Book*](../home2l-book.pdf).
3000static inline void RcSetRequest (
CResource *rc,
CRcValueState *value,
const char *reqGid = NULL,
int priority =
rcPrioNone,
TTicks t0 =
NEVER,
TTicks t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks hysteresis =
NEVER) { rc->
SetRequest (value, reqGid, priority, t0, t1, repeat, hysteresis); }
3014static inline void RcSetRequest (
CResource *rc,
bool valBool,
const char *reqGid = NULL,
int priority =
rcPrioNone,
TTicks t0 =
NEVER,
TTicks t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks hysteresis =
NEVER) { rc->
SetRequest (valBool, reqGid, priority, t0, t1, repeat, hysteresis); }
3017static inline void RcSetRequest (
CResource *rc,
int valInt,
const char *reqGid = NULL,
int priority =
rcPrioNone,
TTicks t0 =
NEVER,
TTicks t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks hysteresis =
NEVER) { rc->
SetRequest (valInt, reqGid, priority, t0, t1, repeat, hysteresis); }
3020static inline void RcSetRequest (
CResource *rc,
float valFloat,
const char *reqGid = NULL,
int priority =
rcPrioNone,
TTicks t0 =
NEVER,
TTicks t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks hysteresis =
NEVER) { rc->
SetRequest (valFloat, reqGid, priority, t0, t1, repeat, hysteresis); }
3023static inline void RcSetRequest (
CResource *rc,
const char *valString,
const char *reqGid = NULL,
int priority =
rcPrioNone,
TTicks t0 =
NEVER,
TTicks t1 =
NEVER,
TTicks repeat =
NEVER,
TTicks hysteresis =
NEVER) { rc->
SetRequest (valString, reqGid, priority, t0, t1, repeat, hysteresis); }
3051%feature(
"docstring")
RcSetRequest "Add or change a request to a resource."
3052%feature("docstring")
RcDelRequest "Delete a request from a resource."
3053%feature("docstring")
RcSetTrigger "Add a trigger request."
3057 def
RcSetRequest (rc, reqDef = None, attrs = None, value = None,
id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
3058 """Set a request to a resource with selected attributes.\n\
3060 The attributes can be set in a flexible way, either by (named) function arguments\n\
3061 or by a textual description as accepted by the Home2L Shell or CRcRequest::SetFromStr().\n\
3063 The parameters have the following meanings:\n\
3065 - reqDef = full definition as a single string '<val> [<attrs>]' or just the value\n\
3066 Note: To avoid ambiguities, values of type string should never be passed by this,\n\
3067 but by the 'value' and 'attrs' arguments instead.\n\
3068 If 'reqDef' is not a string instance, it is used as a value ('val').\n\
3069 - attrs = attribute string (similar to 'reqDef', but without the first field interpreted as value)\n\
3071 - value = value (any type or string)\n\
3072 - id = request ID [default = instance name]\n\
3073 - priority = request priority (0..9) [default = 3 (= rcPrioNormal)]\n\
3076 - repeat = repetition interval\n\
3077 - hysteresis = hysteresis time\n\
3078 - delDelay = deletion delay (if no value is passed and the call is used to delete the request)\n\
3080 Information on the syntax of textual request definition can be found in the Home2L Book and\n\
3081 in the C/C++ API documentation for CRcRequest::SetFromStr(). Arguments representing absolute times\n\
3082 (e.g. 't0', 't1') can have any type and format as accepted by 'TicksAbsOf()'.\n\
3083 Arguments representing relative times (e.g. 'repeat', 'hysteresis', 'delDelay') can have any type\n\
3084 and format as accepted by 'TicksRelOf()'.\n\
3086 If an attribute is set both by means of a string ('reqDef' or 'attrs') or a named parameter,\n\
3087 the named parameter is taken. If no attributes are specified, their defaults as specified in [...]\n\
3090 If the effective value is 'None' (no value is passed), the call will delete the request with\n\
3091 the specified ID passing 'delDelay' as the the 't1' argument of RcDelRequest().\n\
3095 - Request integer value 7 with default attributes:\n\
3096 RcSetRequest (rc, 7);\n\
3097 RcSetRequest (rc, '7');\n\
3098 RcSetRequest (rc, value = '7');\n\
3099 RcSetRequest (rc, reqDef = '7');\n\
3101 - Request integer value 7 with ID '#user' and priority 3:\n\
3102 RcSetRequest (rc, 7, id = 'user', priority = 3);\n\
3103 RcSetRequest (rc, 7, '#user *3');\n\
3104 RcSetRequest (rc, '7 #user *3');\n\
3106 - Delete this request again:\n\
3107 RcSetRequest (rc, value = None, id = 'user');\n\
3108 RcSetRequest (rc, '? #user');\n\
3110 - Delete this request in 5 seconds:\n\
3111 RcSetRequest (rc, value = None, id = 'user', delDelay = '5s');\n\
3113 - Request string value 'Hello *3' with priority 5 and an off time at 6pm today:\n\
3114 RcSetRequest (rc, value = 'Hello *3', attrs = '*5 -18:00');\n\
3115 RcSetRequest (rc, value = 'Hello *3', priority = 5, t1 = '-18:00');\n\
3117 - Set request with user-supplied attributes, some of which must not be changed by user\n\
3118 RcSetRequest (rc, 7, userAttrs, t1 = '-23:00') # t1 overrides an eventual off time in userAttrs\n\
3120 - Set request with user-supplied attributes and defaults\n\
3121 req = CRcRequest (val = 7, t1 = '-23:00') # Set value and default attributes\n\
3122 req->Set (attrs = userAttrs) # userAttrs may override t1\n\
3126 rc.SetRequest (reqDef = reqDef, attrs = attrs, value = value, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis, delDelay = delDelay)
3128 def
RcSetTrigger (rc, attrs = None, id = None, priority = None, t0 = None, t1 = None, repeat = None, hysteresis = None):
3129 """Set a request to a trigger resource with selected attributes."""
3131 rc.SetRequest (attrs = attrs, value = 1, id = id, priority = priority, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
3134 """Delete a request."""
3136 rc.DelRequest (id, t1)
3138 def RcSetDefault (rc, reqDef = None, attrs = None, value = None, t0 = None, t1 = None, repeat = None, hysteresis = None, delDelay = None):
3139 """Set a default request."""
3141 rc.SetRequest (reqDef = reqDef, attrs = attrs, value = value, id =
rcDefaultRequestId, priority =
rcPrioDefault, t0 = t0, t1 = t1, repeat = repeat, hysteresis = hysteresis)
3173## @name Drivers (from C/C++ API) ...
3174## Low-level operations to directly create and use 'CRcDriver' objects.
3175## Most probably, you will not need these functions.
3176## The preferred way in Python is to use the more compfortable decorators and
3177## operations in module "Home2L / Drivers".
3186%feature("docstring") RcRegisterResource "Register a new resource to a driver."
3187%feature("docstring")
RcRegisterSignal "Register a new signal for the built-in 'signal' driver."
3220static inline CResource *RcRegisterResource (
CRcDriver *drv,
const char *rcLid,
const char *rcTypeDef,
void *_data = NULL) {
return CResource::Register (drv, rcLid, rcTypeDef, _data); }
3222CResource *RcRegisterResource (
const char *drvLid,
const char *rcLid,
ERcType _type,
bool _writable,
void *_data = NULL);
3223CResource *RcRegisterResource (
const char *drvLid,
const char *rcLid,
const char *rcTypeDef,
void *_data = NULL);
Class to wrap (POSIX) condition variables.
int Entries() const
Get number of entries.
Class to wrap (POSIX) mutex objects.
Driver for local resources.
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.
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...
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
CRcEventDriver(const char *_lid, ERcState _successState=rcsBusy)
Initialize the driver (does not register).
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
void SetInSelectSet(bool _inSelectSet)
Set whether or not the event processor is contained in the set of upcoming Select() operations.
bool WaitEvent(CRcEvent *ev, TTicks *maxTime=NULL)
Wait for an event and return it at '*ev'.
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
bool PollEvent(CRcEvent *ev)
Check for an event (non-blocking) and return it at '*ev'.
void PutEvent(CRcEvent *ev)
Enqueue/process an event; caller remains owner of 'ev'.
void FlushEvents()
Remove all presently queued events; also waits until a concurrently running OnEvent() invocation retu...
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
virtual bool OnEvent(CRcEvent *ev)
Handle an event asynchronously (may have been called from any thread)
static CRcEventProcessor * Select(TTicks maxTime=-1)
Wait until any of the existing 'CRcEventProcessor' objects has an event available.
void Interrupt()
Request a running WaitEvent() to stop now.
Timer that sends 'rceTimer' events over the event system.
virtual void OnTime()
[T:timer] Virtual function called when the timer triggers.
void Set(void *_data)
Setup timer without (re-)scheduling it.
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
void Set(TTicks _time, TTicks _interval=0, void *_data=NULL)
Setup and (re-)schedule timer (see CTimer::Set() ).
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
Events delivered by a subscriber or to a driver.
const char * ToStr(CString *ret)
Get a readable string.
CRcValueState * ValueState()
Get the value/state attribute of the event. See Set() for further details.
void Set(ERcEventType _type=rceNone, CResource *_resource=NULL, CRcValueState *_valueState=NULL, void *_data=NULL)
Set event attributes.
Request description object.
const char * ToStr(CString *ret, bool precise=true, bool tabular=false, TTicks relativeTimeThreshold=NEVER, const char *skipAttrs=CString::emptyStr)
Return a string in the format accepted by SetFromStr().
const char * Gid()
Requests only have a global ID, no local ID, since they do not "belong" to the initiating host or pro...
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).
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.
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).
void SetRepeat(TTicks _repeat)
Set repetition interval (argument must be != NEVER).
void SetHysteresis(TTicks _hysteresis)
Set hysteresis (argument must be != NEVER).
void Reset()
Clear the value and set default attributes ( NO_VALUE_STATE, NEVER, NULL or equivalent; priority = rc...
CRcRequest()
Default constructor.
bool IsCompatible()
Returns whether the request is compatible with the type of the resource recently passed to Convert().
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.
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.
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).
void SetGid(const char *_gid)
Set GID (argument must be != NULL).
const char * Origin()
Origin of the request. It is automatically set by Reset() to the request creation information in the ...
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).
void Set(CRcValueState *_value=NULL, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks _repeat=NEVER, TTicks _hysteresis=NEVER)
Define a request with all parameters and attributes.
void Set(CRcRequest *req)
Define a request by copying attributes from another. The origin is not copied.
CRcRequest(int _value, const char *_gid=NULL, int _priority=rcPrioNone, TTicks _t0=NEVER, TTicks _t1=NEVER, TTicks repeat=NEVER, TTicks _hysteresis=NEVER)
Construct with value and optional attributes.
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.
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.
Subscriber to follow an arbitrary set of resources.
void Clear()
Remove all resources.
void Unregister()
Clear and unregister the subscriber.
void GetPatternSet(CKeySet *retPatternSet)
Get current pattern set. Patterns from the watch set are followed by a "?".
virtual const char * TypeId()
(optional) Hint for the main event loop: object type
void DelResources(const char *pattern)
Remove resources by pattern. See AddResources() for details on possible patterns.
CResource * AddResources(const char *pattern)
Add new resources by pattern. The pattern is also stored internally to catch possible resources added...
virtual const char * InstId()
(optional) Hint for the main event loop: object instance
static void GetInfoAll(CString *ret, int verbosity=1)
Get info for all subscribers of this instance (see GetInfo() for info on 'verbosity').
void GetInfo(CString *ret, int verbosity=1)
Get Info. 'verbosity == 0': single line, 1: list entries / resources.
bool Register(const char *_lid)
Enable the subscriber, set its LID and GID. Caller remains owner of object. If '_lid' refers to an in...
Typed value tagged with a state and a time stamp.
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.
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'.
bool Equals(const CRcValueState *vs2) const
Strict comparison: state, type and value must match exactly; time stamps are not compared.
bool IsKnown() const
State is either rcsValid or rcsBusy; In other words: the value can be retrieved.
void SetToReportBusyNewVal()
Modify object to auto-report a busy state together with a value. This is to be used in CRcDriver::Dri...
void SetGenericInt(int _val, ERcType _type, ERcState _state=rcsValid)
Set from integer or boolean.
void ToHuman(char *retBuf, int retBufSize)
Output a human-readable string representation for UIs.
void Clear(ERcType _type, ERcState _state=rcsUnknown)
Clear to default value:
TTicks timeStamp
time of last value/state change or trigger
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
void SetGenericFloat(float _val, ERcType _type, ERcState _state=rcsValid)
Set from float.
void SetToReportBusy()
Modify object to auto-report a busy state.
void SetToReportBusyOldVal()
Modify object to auto-report a busy state with no value change. Note: Only for use in CRcDriver::Driv...
bool SetGenericString(const char *_val, ERcType _type, ERcState _state=rcsValid)
Set from string. On syntax error, a warning is emitted, the state is set to rcsUnknown,...
const char * ToStr(CString *ret, bool withType=false, bool withTimeStamp=false, bool precise=false, int stringChars=20) const
Output the object contents as a string according to the synax described for 'SetFromStr'.
bool IsBusy() const
State is rcsBusy, neither rcsValid nor rcsUnknown.
void Clear()
Clear value, set state to 'rcsUnknown', and leave type unchanged.
bool IsValid() const
State is rcsValid, neither rcsBusy nor rcsUnknown.
void GetValueState(CRcValueState *retValueState)
Get the value and state.
void SetRequest(CRcValueState *value, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (generic value, direct parameters). The request attributes are explaind in t...
void ReportState(ERcState _state)
Report state change only, value remains unmodified.
bool IsKnown() const
State is either rcsValid or rcsBusy; In other words: the value can be retrieved.
static CResource * Register(CRcDriver *_rcDriver, const char *_lid, ERcType _type, bool _writable, void *_data=NULL)
Register a new local resource for a driver.
unsigned RegSeq()
The 'regSeq' number is incremented each time the resource is registered or unregistered....
void SetTriggerFromStr(const char *reqDef)
Set trigger request by textual definition.
void SetRequest(CRcRequest *_request)
Add or replace a request (generic version).
void Unsubscribe(CRcSubscriber *subscr)
Unsubscribe to this resource.
int ValidInt(int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid integer value.
void DelRequest(const char *reqGid=NULL, TTicks t1=NEVER)
Delete a request.
bool Is(const char *uri)
Check identity by exact match.
ERcState GetValue(int *retInt, TTicks *retTimeStamp=NULL)
Get a value of type "int" or a type based on it.
int LockLocalSubscribers()
Return number of all active local subscribers for a resource and lock this object....
const char * Lid()
Get the local ID (LID). This is the path relative to a) 'this's host (remote resource) or b) driver (...
bool Is(CResource *rc)
Check identity (for Python & eventual wrapper classes).
ERcState GetValue(CString *retString, TTicks *retTimeStamp=NULL)
Get a value of type "string" or a type based on it.
static CResource * Register(CRcDriver *_rcDriver, const char *_lid, const char *rcTypeDef, void *_data=NULL)
Register a new local resource for a driver based on a textual type description. 'rcTypeDef' is a text...
const char * ValidMutex(CString *ret, const char *defaultVal=CString::emptyStr, TTicks *retTimeStamp=NULL)
Get a valid mutex value.
bool IsValid() const
State is rcsValid, neither rcsBusy nor rcsUnknown.
bool ValidBool(bool defaultVal=false, TTicks *retTimeStamp=NULL)
Get a valid Boolean value. This and the following methods are shortcuts for first obtaining the 'Valu...
void SetUserData(void *_data)
Set user-specified data for this resource.
float ValidUnitFloat(ERcType _type, float defaultVal=0.0, TTicks *retTimeStamp=NULL)
Get a valid unit-type float value.
const char * Uri()
Get the URI (aka global ID / GID).
const char * ValidString(CString *ret, const char *defaultVal=CString::emptyStr, TTicks *retTimeStamp=NULL)
Get a valid string value.
void ReportTrigger()
For triggers, this method must be called.
void Unregister()
Unregister a resource.
void WriteValue(CRcValueState value, int priority=rcPrioNone, const char *reqGid="write")
Write a value by issueing or updating a request with the given global id. The implementation of this ...
void ReadValueState(CRcValueState *retValueState, TTicks maxTime=-1)
Perform a blocking read to obtain an up-to-date value from the driver. Internally,...
void SetRequest(const char *valString, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
int ValidUnitInt(ERcType _type, int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid unit-type integer value.
bool ValueEquals(const CRcValueState *vs2)
Relaxed comparison: type and value must match exactly; state and time stamps are not compared.
void SetDefault(CRcValueState *vs)
Set a default value.
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).
static CResource * Get(const char *uri, bool allowWait=false)
Look up a resource by its URI and return a reference to it.
void SetTrigger(const char *reqGid, int priority=rcPrioNone, TTicks t0=NEVER, TTicks repeat=NEVER)
Set a trigger request (no value needs to be given).
void SetRequest(float valFloat, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
static void GarbageCollection()
Remove all unregistered resources.
ERcState GetValue(float *retFloat, TTicks *retTimeStamp=NULL)
Get a value of type "float" or a type based on it.
CRcRequest * GetRequest(const char *reqGid, bool allowNet=true)
Query a request by its request GID.
void * UserData()
Retrieve user-specified data.
void ReportValueState(const CRcValueState *_valueState)
Report value and state; if different from previous value/state, notify all subscribers....
void SetRequest(TTicks valTime, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
bool IsLike(const char *pattern)
Check identity by pattern.
const char * Gid()
Get the global ID.
bool HasRequests()
Return whether this resource has requests (dynamic, not semi-static).
bool IsBusy() const
State is rcsBusy, neither rcsValid nor rcsUnknown.
void ReportUnknown()
Report an unknown state.
bool Equals(const CRcValueState *vs2)
Strict comparison: state, type and value must match exactly; time stamps are not compared.
void WaitForRegistration()
Wait until registered or a network timeout occured.
void ReportBusy()
Report a busy state (without changing the value).
bool GetRequestSet(CRcRequestSet *ret, bool allowNet=true)
Query all pending requests.
int ValidEnumIdx(ERcType _type, int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid enumeration value index.
void SetRequest(bool valBool, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
TTicks ValidTime(TTicks defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid time value.
int LockLocalRequests()
Return number of active requests for a local resource and lock this object. During the locked state,...
const char * GetInfo(CString *ret, int verbosity=1, bool allowNet=true)
Get textual information on this resource.
float ValidFloat(float defaultVal=0.0, TTicks *retTimeStamp=NULL)
Get a valid float value.
void SetRequest(int valInt, const char *reqGid=NULL, int priority=rcPrioNone, TTicks t0=NEVER, TTicks t1=NEVER, TTicks repeat=NEVER, TTicks hysteresis=NEVER)
Add or replace a request (direct value and parameters).
CResource * Subscribe(CRcSubscriber *subscr)
Subscribe to this resource. The caller remains owner of 'subscr'.
void RedriveValue(bool force=true)
Drive the currently requested value again.
ERcState GetValue(bool *retBool, TTicks *retTimeStamp=NULL)
Get a value of type "Bool" or a type based on it.
ERcState GetValue(TTicks *retTime)
Get a value of type "time".
int ValidTrigger(int defaultVal=0, TTicks *retTimeStamp=NULL)
Get a valid trigger value.
Dynamically allocated string.
static const char *const emptyStr
Use this whenever you need an empty string ("")
char * Disown()
Return current string as a dynamic object and clear 'this'.
void SetF(const char *fmt,...)
Set using printf() formatting.
char * Get() const
Get the C string. Unless explicitely set by 'SetC', this will never return NULL or an invalid pointer...
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).
#define NEVER
Special value that may represent "never" for absolute or monotonic times. Other application-specific ...
#define ASSERT(COND)
Check a condition and abort the application if not true.
#define WARNING(MSG)
Print a warning message to the console.
const char * StringF(class CString *ret, const char *fmt,...)
Return 'ret->Get ()'.
int RcLockHostResources(CRcHost *host)
Query number of resources for a remote host.
CRcHost * RcGetHost(int n)
Get reference to host n, 0 <= n < number of hosts.
static const char * RcLocalHostId()
Get the ID of the local instance.
int RcGetHosts()
Get number of known hosts.
int RcLockSubscribers()
Query the number of existing subscribers and lock the subscriber database.
const char * RcGetHostId(CRcHost *host)
Get textual ID of 'host'.
int RcLockDriverResources(CRcDriver *driver)
Query the number of resources for a local driver.
void FRcDriverFunc(ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *)
Resources driver function.
ERcDriverOperation
Driver operations.
@ rcdOpDriveValue
Drive a value; refers to CRcDriver::DriveValue(). Parameters: CRcDriver *driver, CResource *rc,...
@ rcdOpInit
Initialize driver object(s) of a linked-in driver. Parameter: CRcDriver *drv.
@ rcdOpStop
Stop the driver; refers to CRcDriver::Stop(). Parameter: CRcDriver *drv.
void RcIterate()
Perform pending actions, call TimerIterate() and return.
static void RcGarbageCollection()
(For experts) Remove all presently unregistered resources from memory.
void RcStop()
Stop a loop started by RcRun().
int RcRun(bool catchSignals=true)
Run RcStart(), then RcIterate() in a main event loop until RcStop() is called.
void RcDone()
Shutdown the Resources library.
static CRcSubscriber * RcSubscribe(CRcSubscriber *subscr, CResource *rc)
Subscribe to an additional resource.
static CResource * RcGetResource(const char *uri, bool allowWait=false)
Lookup a resource by its URI and return a reference to it.
void RcBump(CResource *rc=NULL, bool soft=false)
(For experts) Try to reconnect a remote host now.
void RcStart()
Complete the elaboration phase and start active operation. No more drivers and resources may be decla...
void RcInit(bool enableServer=false, bool inBackground=false)
Initialize the Resources library (and start the elaboration phase). This may be followed by driver de...
void RcDelRequest(const char *rcUri, const char *reqGid=NULL, TTicks t1=NEVER)
Delete a request.
static void RcUnsubscribeFromAll(CRcSubscriber *subscr)
Unsubscribe from all resources presently subscribed by 'subscr'. The caller remains owner of 'subscr'...
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...
void RcSetRequestFromStr(const char *rcUri, const char *reqDef)
Set request by textual definition - see CRcRequest::SetFromStr() and the Home2L Book for more informa...
CResource * RcRegisterSignal(const char *name, ERcType type)
Register a new resource for the built-in 'signal' driver.
CRcSubscriber * RcNewSubscriber(const char *subscrLid, CResource *rc=NULL)
Create and register a new subscriber object and optionally subscribe to the given resource.
static CResource * RcGet(const char *uri, bool allowWait=false)
Lookup a resource by its URI and return a reference to it (shortcut for RcGetResource() ).
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)
CDict< CRcRequest > CRcRequestSet
Set of requests (for CResource::GetRequestSet() )
#define rcPrioNone
Undefined priority (special value)
bool FRcEventFunc(class CRcEventProcessor *, CRcEvent *, void *)
Event processor callback function. Example: bool OnEventFunc (CRcEventProcessor *ep,...
@ rceDisconnected
[subscriber] Connection to resource was lost
@ rceValueStateChanged
[subscriber] Value or state has changed
@ rceTimer
[timer] Timer alarm
@ rceNone
None (for dummy events)
@ rceConnected
[subscriber] Connection to resource is (re-)established
@ rceDriveValue
[driver] Drive a new value
@ rceRequestChanged
[subscriber] Request has changed
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')
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.
ERctWindowState
Window state (for 'rctWindowState')
ERctPhoneState
Phone state (for 'rctPhoneState')
static bool RcTypeIsEnumType(ERcType t)
Return whether the type is a enumeration type.
ERcType
Resource major type.
ERctPlayerState
Music player state (for 'rctPlayerState')
const char * RcTypeGetEnumValue(ERcType t, int idx, bool warn=true)
Return the value for 'idx' for an enumeration type. Allowed index vaules range from 0 to N-1,...
const char * RcTypeGetUnit(ERcType t)
Return the unit string; For non-unit types, an empty string is returned.
@ rcsNoReport
Alias to make the 'successState' attribute in CRcEventDriver more intuitive.
@ rcsUnknown
Value is presently unknown (e.g. outdated).
@ rcsValid
Value is valid.
@ rcsBusy
Devices is busy and/or switching to the value indicated by the associate value.
@ rcvUseVacation
User is away temporarily (e.g. for work)
@ rcvUseNight
User is at home and present at day time.
@ rcvUseAway
User is at home, but sleeping (e.g. doors should be locked)
@ rcvWindowOpenOrTilted
(wide) open
@ rcvPhoneRinging
in call, including any 'psDialing' and 'psTransfer...' states (anything where a user is actively usin...
@ rctPercent
[float] Percentage (0.0 .. 100.0)
@ rctMutex
[rctString] resource represents a mutex (not implemented yet)
@ rctUseState
Use/presence state ("day", "night", "away", "vacation")
@ rctWindowState
Window opening state ("closed", "tilted", "open", "openOrTilted")
@ rctPower
[float] Electrical power in Watts
@ rctTrigger
[rctInt] Resource does not carry a value, but can transport events ("triggers"); 'vTriggerCount' coun...
@ rctPhoneState
Phone state ("idle", "ringing", "inCall")
@ rctPlayerState
Music player state ("stop", "pause", "play")
@ rctTemp
[float] Temperature in degree centigrade