]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/event.c
updated email address - petr@smoliku.cz
[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   NtpTime whenExpire,actualTime;
59
60   debug(10,10) ("eventAdd: AID 0x%x %s\n",objectEntryAID->aid,name);
61   actualTime=getActualNtpTime();
62   if (when!=NULL) {
63     NtpTimeAdd(whenExpire,actualTime,*when);
64   } else {
65     whenExpire=actualTime;
66   }
67   if (!fncNode) {
68     fncNode=(HTimFncUserNode*)MALLOC(sizeof(HTimFncUserNode));
69     htimerUnicastCommon_init_detached(fncNode);
70   }
71   fncNode->name=name;
72   fncNode->lock=lock;
73   fncNode->func=func;
74   fncNode->arg1=arg1;
75   switch (where) {
76     case 0:
77       htimerUnicastCommon_set_expire(fncNode,whenExpire);
78       htimerUnicastCommon_add(objectEntryAID,fncNode);
79       htimerUnicastCommon_update_root_timer(&d->objectEntry,objectEntryAID);
80       break;
81     case 1:
82       htimerUnicastSendMetatraffic_set_expire(fncNode,whenExpire);
83       htimerUnicastSendMetatraffic_add(objectEntryAID,fncNode);
84       htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry,objectEntryAID);
85       break;
86     case 2:
87       htimerUnicastSendUserData_set_expire(fncNode,whenExpire);
88       htimerUnicastSendUserData_add(objectEntryAID,fncNode);
89       htimerUnicastSendUserData_update_root_timer(&d->objectEntry,objectEntryAID);
90       break;
91     default:
92       FREE(fncNode);
93       return ORTE_FALSE;
94       break;
95   }
96   debug(10,10) ("eventAdd: finished\n");
97   return ORTE_TRUE;
98 }
99
100 /*
101  * ORTEEventDetach - detach a event from event system (root and application)
102  * @d: pointer to Domain 
103  * @otAID: pointer to objectTreeAID 
104  * @fncNode: pointer on structure fncNode or NULL
105  * @where: from which timer queue is the event detached 
106  *         0-UnicastCommon,1-UnicastSendMetatraffic,2-UnicastSendUserdata
107  *
108  */
109 int32_t 
110 eventDetach(ORTEDomain *d,               
111             ObjectEntryAID *objectEntryAID,
112             HTimFncUserNode  *fncNode,
113             int where) {
114   debug(10,10) ("eventDetach: AID 0x%x\n",objectEntryAID->aid);
115   switch (where) {
116     case 0:
117       htimerUnicastCommon_detach(objectEntryAID,fncNode);
118       htimerUnicastCommon_update_root_timer(&d->objectEntry,objectEntryAID);
119       break;
120     case 1:
121       htimerUnicastSendMetatraffic_detach(objectEntryAID,fncNode);
122       htimerUnicastSendMetatraffic_update_root_timer(&d->objectEntry,objectEntryAID);
123       break;
124     case 2:
125       htimerUnicastSendUserData_detach(objectEntryAID,fncNode);
126       htimerUnicastSendUserData_update_root_timer(&d->objectEntry,objectEntryAID);
127       break;
128     default:
129       return ORTE_FALSE;
130       break;
131   }
132   debug(10,10) ("eventDetach: finished\n");
133   return ORTE_TRUE;
134 }