]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/event.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / liborte / event.c
1 /*
2  *  $Id: events.c,v 0.0.0.1             2003/09/19
3  *
4  *  DEBUG:  section 10                  Event system based on htimerNtp
5  *
6  *  -------------------------------------------------------------------
7  *                                ORTE
8  *                      Open Real-Time Ethernet
9  *
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
14  *
15  *  Author:              Petr Smolik    petr@smoliku.cz
16  *  Advisor:             Pavel Pisa
17  *  Project Responsible: Zdenek Hanzalek
18  *  --------------------------------------------------------------------
19  *
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.
24  *
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.
29  *
30  */
31
32 #include "orte_all.h"
33
34 /*
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
46  *
47  */
48 int32_t
49 eventAdd(ORTEDomain *d,
50          ObjectEntryAID *objectEntryAID,
51          HTimFncUserNode *fncNode,
52          int where,
53          const char *name,
54          EVH2 *func,
55          pthread_rwlock_t *lock,
56          void *arg1,
57          NtpTime *when)
58 {
59   NtpTime whenExpire, actualTime;
60
61   debug(10, 10) ("eventAdd: AID 0x%x %s\n", objectEntryAID->aid, name);
62   actualTime = getActualNtpTime();
63   if (when != NULL) {
64     NtpTimeAdd(whenExpire, actualTime, *when);
65   } else {
66     whenExpire = actualTime;
67   }
68   if (!fncNode) {
69     fncNode = (HTimFncUserNode *)MALLOC(sizeof(HTimFncUserNode));
70     htimerUnicastCommon_init_detached(fncNode);
71   }
72   fncNode->name = name;
73   fncNode->lock = lock;
74   fncNode->func = func;
75   fncNode->arg1 = arg1;
76   switch (where) {
77     case 0:
78       htimerUnicastCommon_set_expire(fncNode, whenExpire);
79       htimerUnicastCommon_add(objectEntryAID, fncNode);
80       htimerUnicastCommon_update_root_timer(&d->objectEntry, objectEntryAID);
81       break;
82     case 1:
83       htimerUnicastSendMetatraffic_set_expire(fncNode, whenExpire);
84       htimerUnicastSendMetatraffic_add(objectEntryAID, fncNode);
85       htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry, objectEntryAID);
86       break;
87     case 2:
88       htimerUnicastSendUserData_set_expire(fncNode, whenExpire);
89       htimerUnicastSendUserData_add(objectEntryAID, fncNode);
90       htimerUnicastSendUserData_update_root_timer(&d->objectEntry, objectEntryAID);
91       break;
92     default:
93       FREE(fncNode);
94       return ORTE_FALSE;
95       break;
96   }
97   debug(10, 10) ("eventAdd: finished\n");
98   return ORTE_TRUE;
99 }
100
101 /*
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
108  *
109  */
110 int32_t
111 eventDetach(ORTEDomain *d,
112             ObjectEntryAID *objectEntryAID,
113             HTimFncUserNode  *fncNode,
114             int where)
115 {
116   debug(10, 10) ("eventDetach: AID 0x%x\n", objectEntryAID->aid);
117   switch (where) {
118     case 0:
119       htimerUnicastCommon_detach(objectEntryAID, fncNode);
120       htimerUnicastCommon_update_root_timer(&d->objectEntry, objectEntryAID);
121       break;
122     case 1:
123       htimerUnicastSendMetatraffic_detach(objectEntryAID, fncNode);
124       htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry, objectEntryAID);
125       break;
126     case 2:
127       htimerUnicastSendUserData_detach(objectEntryAID, fncNode);
128       htimerUnicastSendUserData_update_root_timer(&d->objectEntry, objectEntryAID);
129       break;
130     default:
131       return ORTE_FALSE;
132       break;
133   }
134   debug(10, 10) ("eventDetach: finished\n");
135   return ORTE_TRUE;
136 }