]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/event.c
d41e7b697cca6aebfa74c94023a2d59046193d4d
[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  *  AUTHOR: Petr Smolik                 petr.smolik@wo.cz
6  *
7  *  ORTE - OCERA Real-Time Ethernet     http://www.ocera.org/
8  *  --------------------------------------------------------------------
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundtion; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  */ 
21
22 #include "orte.h"
23
24 /*
25  * ORTEEventAdd - add a event into event system (root and application)
26  * @d: pointer to Domain
27  * @otAID: pointer to objectTreeAID or NULL for multicast event
28  * @fncNode: pointer on structure fncNode or NULL
29  * @where: in which timer queue is the event added 
30  *         0-UnicastCommon,1-UnicastSendMetatraffic,2-UnicastSendUserdata
31  * @name: name called function
32  * @lock: pointer on lock or NULL for unprotected agruments
33  * @func: pointer to called function 
34  * @arg1: first function argument 
35  * @when: time when is needed call the function 
36  *
37  */
38 int32_t 
39 eventAdd(ORTEDomain *d,               
40          ObjectEntryAID *objectEntryAID,
41          HTimFncUserNode *fncNode,
42          int where,          
43          const char *name,
44          EVH2 *func,                      
45          pthread_rwlock_t *lock,
46          void *arg1,                       
47          NtpTime *when) { 
48   NtpTime whenExpire,actualTime;
49
50   debug(10,10) ("eventAdd: AID 0x%x %s\n",objectEntryAID->aid,name);
51   actualTime=getActualNtpTime();
52   if (when!=NULL) {
53     NtpTimeAdd(whenExpire,actualTime,*when);
54   } else {
55     whenExpire=actualTime;
56   }
57   if (!fncNode) {
58     fncNode=(HTimFncUserNode*)MALLOC(sizeof(HTimFncUserNode));
59     htimerUnicastCommon_init_detached(fncNode);
60   }
61   fncNode->name=name;
62   fncNode->lock=lock;
63   fncNode->func=func;
64   fncNode->arg1=arg1;
65   switch (where) {
66     case 0:
67       htimerUnicastCommon_set_expire(fncNode,whenExpire);
68       htimerUnicastCommon_add(objectEntryAID,fncNode);
69       htimerUnicastCommon_update_root_timer(&d->objectEntry,objectEntryAID);
70       break;
71     case 1:
72       htimerUnicastSendMetatraffic_set_expire(fncNode,whenExpire);
73       htimerUnicastSendMetatraffic_add(objectEntryAID,fncNode);
74       htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry,objectEntryAID);
75       break;
76     case 2:
77       htimerUnicastSendUserData_set_expire(fncNode,whenExpire);
78       htimerUnicastSendUserData_add(objectEntryAID,fncNode);
79       htimerUnicastSendUserData_update_root_timer(&d->objectEntry,objectEntryAID);
80       break;
81     default:
82       FREE(fncNode);
83       return ORTE_FALSE;
84       break;
85   }
86   debug(10,10) ("eventAdd: finished\n");
87   return ORTE_TRUE;
88 }
89
90 /*
91  * ORTEEventDetach - detach a event from event system (root and application)
92  * @d: pointer to Domain 
93  * @otAID: pointer to objectTreeAID 
94  * @fncNode: pointer on structure fncNode or NULL
95  * @where: from which timer queue is the event detached 
96  *         0-UnicastCommon,1-UnicastSendMetatraffic,2-UnicastSendUserdata
97  *
98  */
99 int32_t 
100 eventDetach(ORTEDomain *d,               
101             ObjectEntryAID *objectEntryAID,
102             HTimFncUserNode  *fncNode,
103             int where) {
104   debug(10,10) ("eventDetach: AID 0x%x\n",objectEntryAID->aid);
105   switch (where) {
106     case 0:
107       htimerUnicastCommon_detach(objectEntryAID,fncNode);
108       htimerUnicastCommon_update_root_timer(&d->objectEntry,objectEntryAID);
109       break;
110     case 1:
111       htimerUnicastSendMetatraffic_detach(objectEntryAID,fncNode);
112       htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry,objectEntryAID);
113       break;
114     case 2:
115       htimerUnicastSendUserData_detach(objectEntryAID,fncNode);
116       htimerUnicastSendUserData_update_root_timer(&d->objectEntry,objectEntryAID);
117       break;
118     default:
119       return ORTE_FALSE;
120       break;
121   }
122   debug(10,10) ("eventDetach: finished\n");
123   return ORTE_TRUE;
124 }