2 * $Id: events.c,v 0.0.0.1 2003/09/19
4 * DEBUG: section 10 Event system based on htimerNtp
6 * -------------------------------------------------------------------
8 * Open Real-Time Ethernet
10 * Copyright (C) 2001-2006
11 * Department of Control Engineering FEE CTU Prague, Czech Republic
12 * http://dce.felk.cvut.cz
13 * http://www.ocera.org
15 * Author: Petr Smolik petr@smoliku.cz
17 * Project Responsible: Zdenek Hanzalek
18 * --------------------------------------------------------------------
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundtion; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
35 * ORTEEventAdd - add a event into event system (root and application)
36 * @d: pointer to Domain
37 * @otAID: pointer to objectTreeAID or NULL for multicast event
38 * @fncNode: pointer on structure fncNode or NULL
39 * @where: in which timer queue is the event added
40 * 0-UnicastCommon,1-UnicastSendMetatraffic,2-UnicastSendUserdata
41 * @name: name called function
42 * @lock: pointer on lock or NULL for unprotected agruments
43 * @func: pointer to called function
44 * @arg1: first function argument
45 * @when: time when is needed call the function
49 eventAdd(ORTEDomain *d,
50 ObjectEntryAID *objectEntryAID,
51 HTimFncUserNode *fncNode,
55 pthread_rwlock_t *lock,
59 NtpTime whenExpire, actualTime;
61 debug(10, 10) ("eventAdd: AID 0x%x %s\n", objectEntryAID->aid, name);
62 actualTime = getActualNtpTime();
64 NtpTimeAdd(whenExpire, actualTime, *when);
66 whenExpire = actualTime;
69 fncNode = (HTimFncUserNode *)MALLOC(sizeof(HTimFncUserNode));
70 htimerUnicastCommon_init_detached(fncNode);
78 htimerUnicastCommon_set_expire(fncNode, whenExpire);
79 htimerUnicastCommon_add(objectEntryAID, fncNode);
80 htimerUnicastCommon_update_root_timer(&d->objectEntry, objectEntryAID);
83 htimerUnicastSendMetatraffic_set_expire(fncNode, whenExpire);
84 htimerUnicastSendMetatraffic_add(objectEntryAID, fncNode);
85 htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry, objectEntryAID);
88 htimerUnicastSendUserData_set_expire(fncNode, whenExpire);
89 htimerUnicastSendUserData_add(objectEntryAID, fncNode);
90 htimerUnicastSendUserData_update_root_timer(&d->objectEntry, objectEntryAID);
97 debug(10, 10) ("eventAdd: finished\n");
102 * ORTEEventDetach - detach a event from event system (root and application)
103 * @d: pointer to Domain
104 * @otAID: pointer to objectTreeAID
105 * @fncNode: pointer on structure fncNode or NULL
106 * @where: from which timer queue is the event detached
107 * 0-UnicastCommon,1-UnicastSendMetatraffic,2-UnicastSendUserdata
111 eventDetach(ORTEDomain *d,
112 ObjectEntryAID *objectEntryAID,
113 HTimFncUserNode *fncNode,
116 debug(10, 10) ("eventDetach: AID 0x%x\n", objectEntryAID->aid);
119 htimerUnicastCommon_detach(objectEntryAID, fncNode);
120 htimerUnicastCommon_update_root_timer(&d->objectEntry, objectEntryAID);
123 htimerUnicastSendMetatraffic_detach(objectEntryAID, fncNode);
124 htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry, objectEntryAID);
127 htimerUnicastSendUserData_detach(objectEntryAID, fncNode);
128 htimerUnicastSendUserData_update_root_timer(&d->objectEntry, objectEntryAID);
134 debug(10, 10) ("eventDetach: finished\n");