]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/objectEntry.c
ed66452518ab5a444fff721e805dc8f19d2e7717
[orte.git] / orte / liborte / objectEntry.c
1     /*
2  *  $Id: objectEntry.c,v 0.0.0.1   2003/09/10
3  *
4  *  DEBUG:  section 8                   Functions with database of objects
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 Foundation; 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 // Implementation of GAVL functions
36 GAVL_CUST_NODE_INT_IMP(ObjectEntryHID, ObjectEntry, ObjectEntryHID, HostId,
37     objRoot, hidNode, hid, gavl_cmp_int)
38 GAVL_CUST_NODE_INT_IMP(ObjectEntryAID, ObjectEntryHID, ObjectEntryAID, AppId,
39     aidRoot, aidNode, aid, gavl_cmp_int)
40 GAVL_CUST_NODE_INT_IMP(ObjectEntryOID, ObjectEntryAID, ObjectEntryOID, ObjectId,
41     oidRoot, oidNode, oid, gavl_cmp_int)
42   
43 /*****************************************************************************/
44 void
45 objectEntryRefreshApp(ORTEDomain *d,ObjectEntryOID *objectEntryOID) {
46   if (!objectEntryOID) return;
47   if ((objectEntryOID->oid!=OID_APP) ||
48       (objectEntryOID->guid.aid==AID_UNKNOWN) ||
49       (!gavl_cmp_guid(&objectEntryOID->guid,&d->guid))) return;
50   eventDetach(d,
51           objectEntryOID->objectEntryAID,
52           &objectEntryOID->expirationPurgeTimer,
53           0);
54   eventAdd(d,
55           objectEntryOID->objectEntryAID,
56           &objectEntryOID->expirationPurgeTimer,
57           0,
58           "ExpirationTimer",
59           objectEntryExpirationTimer,
60           NULL,
61           objectEntryOID,
62           &((AppParams*)objectEntryOID->attributes)->expirationTime);
63   debug(8,3) ("refreshed: 0x%x-0x%x\n",
64               objectEntryOID->objectEntryHID->hid,
65               objectEntryOID->objectEntryAID->aid);
66 }
67
68 /*****************************************************************************/
69 ObjectEntryOID *
70 objectEntryFind(ORTEDomain *d,GUID_RTPS *guid) {
71   ObjectEntryHID *objectEntryHID;
72   ObjectEntryAID *objectEntryAID;
73
74   objectEntryHID=ObjectEntryHID_find(&d->objectEntry,&guid->hid);
75   if (objectEntryHID==NULL) return NULL;
76   objectEntryAID=ObjectEntryAID_find(objectEntryHID,&guid->aid);
77   if (objectEntryAID==NULL) return NULL;
78   return ObjectEntryOID_find(objectEntryAID,&guid->oid);
79 }
80
81 /*
82  * objectEntryAdd - Add a object to structure objectEntry
83  * @objectEntry: pointer to root structure 
84  * @guid: pointer to guid of object (hid,aid,oid)
85  *
86  * Return pointer to objectEntryOID
87  */
88 ObjectEntryOID *
89 objectEntryAdd(ORTEDomain *d,GUID_RTPS *guid,void *params) {
90   ObjectEntryHID *objectEntryHID;
91   ObjectEntryAID *objectEntryAID;
92   ObjectEntryOID *objectEntryOID;
93
94   debug(8,10) ("objectEntry: start\n");
95   objectEntryHID=ObjectEntryHID_find(&d->objectEntry,&guid->hid);
96   //not exists Host -> create 
97   if (objectEntryHID==NULL) {
98     objectEntryHID=(ObjectEntryHID*)MALLOC(sizeof(ObjectEntryHID));
99     //initialization items of structure objectEntryHID
100     ObjectEntryAID_init_root_field(objectEntryHID);
101     objectEntryHID->hid=guid->hid;
102     //insert
103     ObjectEntryHID_insert(&d->objectEntry,objectEntryHID);
104     debug(8,5) ("objectEntry: Host  : %#10.8x created\n",guid->hid);
105   }
106   objectEntryAID=ObjectEntryAID_find(objectEntryHID,&guid->aid);
107   //not exists Application -> create 
108   if (objectEntryAID==NULL) {
109     objectEntryAID=(ObjectEntryAID*)MALLOC(sizeof(ObjectEntryAID));
110     objectEntryAID->aobject=NULL;
111     //init items of structure objectEntryAID
112     objectEntryAID->aid=guid->aid;
113     ObjectEntryOID_init_root_field(objectEntryAID);
114     //init structure htimUnicast
115     htimerUnicastCommon_init_queue(objectEntryAID);
116     ul_htim_queue_init_detached(&objectEntryAID->htimUnicast.commonNode.htim);
117     htimerUnicastSendMetatraffic_init_queue(objectEntryAID);
118     ul_htim_queue_init_detached(&objectEntryAID->htimUnicast.sendMetatrafficNode.htim);
119     htimerUnicastSendUserData_init_queue(objectEntryAID);
120     ul_htim_queue_init_detached(&objectEntryAID->htimUnicast.sendUserDataNode.htim);
121     //insert
122     ObjectEntryAID_insert(objectEntryHID,objectEntryAID);
123     debug(8,5) ("objectEntry: App   : %#10.8x created\n",guid->aid);
124   }
125   objectEntryOID=ObjectEntryOID_find(objectEntryAID,&guid->oid);
126   //not exists Object -> create 
127   if (objectEntryOID==NULL) {
128     objectEntryOID=(ObjectEntryOID*)MALLOC(sizeof(ObjectEntryOID));
129     //initialization items of structure objectEntryOID
130     objectEntryOID->guid=*guid;
131     objectEntryOID->oid=guid->oid;
132     objectEntryOID->objectEntryAID=objectEntryAID;
133     objectEntryOID->objectEntryHID=objectEntryHID;
134     objectEntryOID->attributes=params;
135     ul_htim_queue_init_detached(&objectEntryOID->expirationPurgeTimer.htim);
136     ul_htim_queue_init_detached(&objectEntryOID->sendCallBackDelayTimer.htim);
137     ObjectEntryMulticast_init_head(objectEntryOID);
138     objectEntryOID->multicastPort=0;
139     if (guid->oid==OID_APP) {
140       objectEntryAID->aobject=objectEntryOID;
141       debug(8,5) ("objectEntry: Object: %#10.8x connected to AID\n",guid->oid);
142     }
143     //insert
144     ObjectEntryOID_insert(objectEntryAID,objectEntryOID);
145     debug(8,5) ("objectEntry: Object: %#10.8x created\n",guid->oid);
146   }
147   debug(8,10) ("objectEntry: finished\n");
148   return objectEntryOID;
149 }
150
151 /*
152  * objectEntryDelete - Delete a object from structure objectEntry
153  * @objectEntry: pointer to root structure 
154  * @obejctEntryOID: pointer to the deleted objectEntryOID
155  *
156  * return 0-no obj. was deleted, 1-OID was deleted,2-OID,AID was deleted,
157  *        3-OID,AID,HID was deleted
158  */
159 int
160 objectEntryDelete(ORTEDomain *d,ObjectEntryOID *objectEntryOID,Boolean destroy) {
161   ObjectEntryHID *objectEntryHID;
162   ObjectEntryAID *objectEntryAID;
163   int            result=0;
164
165   debug(8,10) ("objectEntryDelete: start\n");
166   if (!objectEntryOID) return result;
167   objectEntryHID=objectEntryOID->objectEntryHID;
168   objectEntryAID=objectEntryOID->objectEntryAID;
169   //Destroy object on level OID
170   eventDetach(d,
171           objectEntryOID->objectEntryAID,
172           &objectEntryOID->expirationPurgeTimer,
173           0);
174   eventDetach(d,
175           objectEntryOID->objectEntryAID,
176           &objectEntryOID->sendCallBackDelayTimer,
177           0);
178   FREE(objectEntryOID->attributes);
179   if (objectEntryAID->aobject==objectEntryOID) {
180     objectEntryAID->aobject=NULL;
181     debug(8,5) ("objectEntry: Object: %#10.8x deleted from AID\n",objectEntryOID->oid);
182   }
183   if (destroy) {
184     ObjectEntryOID_delete(objectEntryAID,objectEntryOID);
185     FREE(objectEntryOID);
186   }
187   debug(8,5) ("objectEntry: Object: %#10.8x deleted\n",objectEntryOID->oid);
188   result=1;
189   //Destroy object on level AID
190   if (ObjectEntryOID_is_empty(objectEntryAID)) {
191     debug(8,5) ("objectEntry: App   : %#10.8x deleted\n",objectEntryAID->aid);
192     if (destroy) {
193       ObjectEntryAID_delete(objectEntryHID,objectEntryAID);
194       FREE(objectEntryAID);
195     }
196     result=2;
197   }
198   //Destroy object on level HID
199   if (ObjectEntryAID_is_empty(objectEntryHID)) {
200     debug(8,5) ("objectEntry: Host  : %#10.8x deleted\n",objectEntryHID->hid);
201     if (destroy) {
202       ObjectEntryHID_delete(&d->objectEntry,objectEntryHID);
203       FREE(objectEntryHID);
204     }
205     result=3;
206   }
207   debug(8,10) ("objectEntryDelete: finished\n");
208   return result;
209 }
210
211 /*
212  * objectEntryDeleteAll - Delete all structure objectEntry
213  * @objectEntry: pointer to root structure
214  *
215  */
216 void
217 objectEntryDeleteAll(ORTEDomain *d,ObjectEntry *objectEntry) {
218   ObjectEntryHID *objectEntryHID;
219   ObjectEntryAID *objectEntryAID;
220   ObjectEntryOID *objectEntryOID;
221
222   while((objectEntryHID=ObjectEntryHID_cut_first(objectEntry))) {
223     while((objectEntryAID=ObjectEntryAID_cut_first(objectEntryHID))) {
224       while((objectEntryOID=ObjectEntryOID_cut_first(objectEntryAID))) {
225         objectEntryDelete(d,objectEntryOID,ORTE_FALSE);
226         FREE(objectEntryOID);
227       }
228       FREE(objectEntryAID);
229     }
230     FREE(objectEntryHID);
231   }
232 }
233
234 /*
235  * ObjectEntryDump - Dump a objectEntry structure on stdio
236  * @objectEntry: pointer to root structure
237  *
238  */
239 void
240 objectEntryDump(ObjectEntry *objectEntry) {
241   ObjectEntryHID *objectEntryHID;
242   ObjectEntryAID *objectEntryAID;
243   ObjectEntryOID *objectEntryOID;
244
245   gavl_cust_for_each(ObjectEntryHID,objectEntry,objectEntryHID) {
246     debug(8,5) ("hid:%x\n",objectEntryHID->hid);
247     gavl_cust_for_each(ObjectEntryAID,objectEntryHID,objectEntryAID) {
248       debug(8,5) ("  aid:%x\n",objectEntryAID->aid);
249       gavl_cust_for_each(ObjectEntryOID,objectEntryAID,objectEntryOID) {
250         debug(8,5) ("    oid:%x\n",objectEntryOID->oid,objectEntryOID);
251       }
252     }
253   }
254 }
255