]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/ORTETypeRegister.c
f1397c7f217ee43e7af9cf54224a4ea8cee0181e
[orte.git] / orte / liborte / ORTETypeRegister.c
1 /*
2  *  $Id: ORTETypeRegister.c,v 0.0.0.1   2003/08/21 
3  *
4  *  DEBUG:  section 26                  Type register
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 Foundation; 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_all.h"
23
24 GAVL_CUST_NODE_INT_IMP(ORTEType, TypeEntry, TypeNode, const char *,
25     types, node, typeRegister.typeName, gavl_cmp_str)
26     
27
28 /*****************************************************************************/
29 Boolean
30 ORTETypeRegisterFind(ORTEDomain *d,const char *typeName) {
31   Boolean            result=ORTE_FALSE;
32   
33   if (!d) 
34     return ORTE_FALSE;  //bat handle
35
36   pthread_rwlock_rdlock(&d->typeEntry.lock);    
37   if (ORTEType_find(&d->typeEntry,&typeName)) 
38     result=ORTE_TRUE;
39   pthread_rwlock_unlock(&d->typeEntry.lock);    
40   return result;
41 }
42
43 /*****************************************************************************/
44 int
45 ORTETypeRegisterAdd(ORTEDomain *d,const char *typeName,ORTETypeSerialize ts,
46                     ORTETypeDeserialize ds,ORTETypeGetMaxSize gms,unsigned int ms) {
47   TypeNode           *tn;
48   
49   if (!d) 
50     return ORTE_BAD_HANDLE;       //bat handle
51
52   if (gms) {
53     if (d->domainProp.wireProp.userBytesPerPacket<ms) 
54       return -2;
55   }
56
57   pthread_rwlock_wrlock(&d->typeEntry.lock);    
58   tn=ORTEType_find(&d->typeEntry,&typeName);
59   if (!tn) {
60     tn=(TypeNode*)MALLOC(sizeof(TypeNode));
61     tn->typeRegister.typeName=(char*)MALLOC(strlen(typeName)+1);
62     if (tn->typeRegister.typeName) {
63       memcpy((void*)tn->typeRegister.typeName, 
64              typeName, 
65              strlen(typeName) + 1);
66     }    
67     ORTEType_insert(&d->typeEntry,tn);
68     debug(26,3) ("ORTETypeRegisterAdd: created\n");
69   }
70   tn->typeRegister.serialize=ts;
71   tn->typeRegister.deserialize=ds;
72   tn->typeRegister.getMaxSize=gms;
73   tn->typeRegister.maxSize=ms;
74   pthread_rwlock_unlock(&d->typeEntry.lock);    
75   debug(26,3) ("ORTETypeRegisterAdd: registered type:%s\n",typeName);
76   return ORTE_OK;
77 }
78
79 /*****************************************************************************/
80 int
81 ORTETypeRegisterDestroyAll(ORTEDomain *d) {
82   TypeNode           *tn;
83   
84   if (!d) 
85     return ORTE_BAD_HANDLE;  //bat handle
86
87   pthread_rwlock_wrlock(&d->typeEntry.lock);    
88   while((tn=ORTEType_cut_first(&d->typeEntry))) {
89     FREE((char*)tn->typeRegister.typeName);
90     FREE(tn);
91   }
92   pthread_rwlock_unlock(&d->typeEntry.lock);    
93   return ORTE_OK;
94 }
95
96
97
98
99