/[pdpsoft]/trunk/grid-mw-security/ees/src/aos/aos.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/src/aos/aos.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1352 by aramv, Fri Jan 8 17:32:05 2010 UTC revision 1353 by aramv, Sat Jan 9 00:19:12 2010 UTC
# Line 12  void aos_start_threading(){ Line 12  void aos_start_threading(){
12          _is_threading = 1;          _is_threading = 1;
13  }  }
14    
 size_t aos_buffer_size(eef_arg_type argtype){  
   switch (argtype){  
     case TYPE_NONE :  
         return 0;  
     case TYPE_SCHAR :  
         return sizeof(int);  
     case TYPE_UCHAR :  
         return sizeof(unsigned int);  
     case TYPE_SHORT :  
         return sizeof(int);  
     case TYPE_USHORT :  
         return sizeof(unsigned int);  
     case TYPE_INT :  
         return sizeof(int);  
     case TYPE_UINT :  
         return sizeof(unsigned int);  
     case TYPE_LONGINT :  
         return sizeof(long int);  
     case TYPE_ULONGINT :  
         return sizeof(unsigned long int);  
 #ifdef HAVE_LONG_LONG_INT  
     case TYPE_LONGLONGINT :  
         return sizeof(long long int);  
     case TYPE_ULONGLONGINT :  
         return sizeof(unsigned long long int);  
 #endif  
     case TYPE_FLOAT  :  
         return sizeof(double);  
     case TYPE_DOUBLE :  
         return sizeof(double);  
 #ifdef HAVE_LONG_DOUBLE  
     case TYPE_LONGDOUBLE :  
         return sizeof(long double);  
 #endif  
     case TYPE_CHAR :  
         return sizeof(int);  
 #ifdef HAVE_WINT_T  
     case TYPE_WIDE_CHAR :  
         return sizeof(wint_t);  
 #endif  
     case TYPE_STRING :  
         return sizeof(const char*);  
 #ifdef HAVE_WCHAR_T  
     case TYPE_WIDE_STRING :  
         return sizeof(const wchar_t*);  
 #endif  
     case TYPE_POINTER :  
         return sizeof(void*);  
     case TYPE_COUNT_SCHAR_POINTER :  
         return sizeof(signed char*);  
     case TYPE_COUNT_SHORT_POINTER :  
         return sizeof(short *);  
     case TYPE_COUNT_INT_POINTER :  
         return sizeof(int*);  
     case TYPE_COUNT_LONGINT_POINTER :  
         return sizeof(long int*);  
 #ifdef HAVE_LONG_LONG_INT  
     case TYPE_COUNT_LONGLONGINT_POINTER :  
         return sizeof(long long int*);  
 #endif  
     default:  
         return 0;  
   }  
 }  
   
15  aos_storage_t * aos_get_storage(){  aos_storage_t * aos_get_storage(){
16    pid_t             tid;    pid_t             tid;
17    aos_storage_t  *  storage;    aos_storage_t  *  storage;
# Line 92  aos_storage_t * aos_get_storage(){ Line 27  aos_storage_t * aos_get_storage(){
27    if(!(storage = pthread_getspecific(_aos_key))) {    if(!(storage = pthread_getspecific(_aos_key))) {
28      if((storage = calloc(1, sizeof(aos_storage_t)))){      if((storage = calloc(1, sizeof(aos_storage_t)))){
29        if((storage->list_contexts = calloc(1, sizeof(aos_context_t)))){        if((storage->list_contexts = calloc(1, sizeof(aos_context_t)))){
30            pthread_setspecific(_aos_key, storage);
31            printf("Created new TLS at %p\n", storage);
32        }        }
       pthread_setspecific(_aos_key, storage);  
33      }      }
     printf("Created new TLS at %p\n", storage);  
34    } else {    } else {
35      printf("Found existing TLS at %p\n", storage);      printf("Found existing TLS at %p\n", storage);
36    }    }
37    return storage;    return storage;
38  }  }
39    
40  /* base functions */  EES_RC aos_free_storage(aos_storage_t* storage){
41      aos_context_t   *context        = NULL, *next_context    = NULL;
42  EES_RC aos_set(const char *label, void *value, eef_arg_type type, size_t arg_bufsize, aos_attribute_t * parent, aos_attribute_t * child){    aos_attribute_t *attribute      = NULL, *next_attribute  = NULL;
43    aos_argument_t *  args_new  = NULL;    int             attribute_count = 0;
   aos_attribute_t*  attr_new  = NULL;  
   aos_argument_t *  last_node = NULL;  
   aos_storage_t  *  storage   = aos_get_storage();  
   size_t            buf_size  = arg_bufsize;  
   
         if(!aos_is_initialized()){  
                 eef_log(LOG_ERR, "AOS is not yet initialized. Aborting.");  
                 return EES_FAILURE;  
         }  
44    
45    if(!(aos_get_value_by_label(label) == NULL)){    if(!storage){
                 eef_log(LOG_ERR, "Block with label %s already exists.", label);  
46      return EES_FAILURE;      return EES_FAILURE;
47    }    }
48    
49    /* allocate an extra argument in the list */    printf("Cleaning aos storage at %p\n", storage);
50    if((attr_new = calloc(1, (sizeof(aos_attribute_t)))) == NULL){    if(storage == _global_storage){
51                  eef_log(LOG_ERR, "Failed to allocate a new argument on the list. %s", strerror(errno));      printf("This is the GLOBAL storage\n");
     return EES_FAILURE;  
   } else {  
     /*eef_log(LOG_DEBUG, "Malloc succeeded. Argument lists is now %lu elements.\n", (unsigned long) (*args_size));*/  
52    }    }
53    
54    if(buf_size == 0) {    context = storage->list_contexts;
     attr_new->data = value;  
     attr_new->needs_free = 0;  
     /*eef_log(LOG_DEBUG, "1 pointer allocated at %p. No need to free!\n", args_new->data);*/  
   } else {  
     attr_new->data = calloc(1, buf_size);  
     /*eef_log(LOG_DEBUG, "Storing bytes:%i\n", buf_size);*/  
     memcpy(attr_new->data, value, buf_size);  
     attr_new->needs_free = 1;  
     /*eef_log(LOG_DEBUG, "%i bytes allocated at %p. (index %lu) Remember to free it!\n", buf_size, args_new->data, (unsigned long) (*args_size));*/  
   }  
   
   /*attr_new->type           = type;*/  
   /*attr_new->id             = label;*/  
         attr_new->parent         = parent;  
         attr_new->child          = child;  
   attr_new->next           = NULL;  
   attr_new->setting_plugin = get_running_plugin();  
   
   /*last_node = aos_get_last_node();*/  
   /*if(last_node != NULL){*/  
   /*(last_node)->next = attr_new;*/  
   /*} else {*/  
   /*storage->list_attributes = attr_new;*/  
   /*}*/  
55    
56          return EES_SUCCESS;    while(context){
57        next_context = context->next;
58        printf("Checking context at %p\n", context);
59        attribute = context->list_attributes;
60        while(attribute){
61          next_attribute = attribute->next;
62          /* free here */
63          printf("Checking attribute at %p\n", attribute);
64          if(attribute->needs_free){
65            eef_log(LOG_DEBUG, "Freeing arg %i at %p\n",attribute_count, attribute);
66            free(attribute->data);
67            free(attribute);
68          } else {
69            eef_log(LOG_DEBUG, "Not freeing arg %i at %p\n",attribute_count, attribute);
70          }
71          attribute = next_attribute;
72          attribute_count++;
73        }
74        /* free here */
75        printf("Freeing context at %p\n", context);
76        free(context);
77        context = next_context;
78      }
79      free(storage);
80      return EES_SUCCESS;
81  }  }
82    
83    /* base functions */
84    
85  aos_context_t * createContext(aos_context_class_t context_class){  aos_context_t * createContext(aos_context_class_t context_class){
86    aos_context_t * context;    aos_context_t * context;
87    if((context = calloc(1, sizeof(aos_context_t)))){    if((context = calloc(1, sizeof(aos_context_t)))){
# Line 239  aos_attribute_t* getNextAttribute(aos_co Line 163  aos_attribute_t* getNextAttribute(aos_co
163    return context->last_attribute;    return context->last_attribute;
164  }  }
165    
   
 EES_RC aos_delete_attribute_by_label(const char* label){  
   aos_attribute_t * current_attr  = NULL;  
   aos_attribute_t * previous_attr = NULL;  
   aos_storage_t   * storage       = aos_get_storage();  
   
   if(label == NULL){  
     return EES_FAILURE;  
   }  
   
   /*for(current_attr = storage->list_attributes; current_attr != NULL; previous_attr = current_attr, current_attr = current_attr->next){*/  
   /*if(strncmp(current_attr->id, label, strlen(label)) == 0){*/  
   /*if(current_attr->setting_plugin != get_running_plugin()){*/  
   /*eef_log(LOG_ERR, "Argument %s is not owned by running plugin %s", current_attr->id, get_running_plugin()->name);*/  
   /*return EES_FAILURE;*/  
   /*}*/  
   /*if(previous_attr == NULL){*/  
   /**//* head node deleted. linking start of list to next node */  
   /*storage->list_arguments = current_attr->next;*/  
   /*} else {*/  
   /**//* link previous to deletee's next */  
   /*previous_attr->next = current_attr->next;*/  
   /*}*/  
   /*break;*/  
   /*}*/  
   /*}*/  
   
   if(current_attr){  
     /*eef_log(LOG_ERR, "Deleting attr:%s", label);*/  
     free(current_attr->data);  
     free(current_attr);  
     current_attr = NULL;  
     return EES_SUCCESS;  
   } else {  
     return EES_FAILURE;  
   }  
   
 }  
   
166  EES_RC destroyAttribute(aos_context_t* context, aos_attribute_t* attribute){  EES_RC destroyAttribute(aos_context_t* context, aos_attribute_t* attribute){
167    aos_attribute_t *last_attribute = NULL, *current_attribute = NULL;    aos_attribute_t *last_attribute = NULL, *current_attribute = NULL;
168    for(current_attribute = context->list_attributes; current_attribute != NULL; last_attribute = current_attribute, current_attribute = current_attribute->next){    for(current_attribute = context->list_attributes; current_attribute != NULL; last_attribute = current_attribute, current_attribute = current_attribute->next){
# Line 350  int getAttributeValueAsInt(aos_attribute Line 235  int getAttributeValueAsInt(aos_attribute
235    return (int) (attribute->data);    return (int) (attribute->data);
236  }  }
237    
238  aos_attribute_t * aos_get_last_node(void){  /* needs more work */
239    aos_attribute_t * current_attr = NULL;  EES_RC aos_delete_attribute_by_label(const char* label){
240    aos_storage_t   * storage   = aos_get_storage();    aos_attribute_t * current_attr  = NULL;
241    unsigned int i;    aos_attribute_t * previous_attr = NULL;
242    return current_attr;    aos_storage_t   * storage       = aos_get_storage();
243    
244      if(label == NULL){
245        return EES_FAILURE;
246      }
247    
248      /*for(current_attr = storage->list_attributes; current_attr != NULL; previous_attr = current_attr, current_attr = current_attr->next){*/
249      /*if(strncmp(current_attr->id, label, strlen(label)) == 0){*/
250      /*if(current_attr->setting_plugin != get_running_plugin()){*/
251      /*eef_log(LOG_ERR, "Argument %s is not owned by running plugin %s", current_attr->id, get_running_plugin()->name);*/
252      /*return EES_FAILURE;*/
253      /*}*/
254      /*if(previous_attr == NULL){*/
255      /**//* head node deleted. linking start of list to next node */
256      /*storage->list_arguments = current_attr->next;*/
257      /*} else {*/
258      /**//* link previous to deletee's next */
259      /*previous_attr->next = current_attr->next;*/
260      /*}*/
261      /*break;*/
262      /*}*/
263      /*}*/
264    
265      if(current_attr){
266        /*eef_log(LOG_ERR, "Deleting attr:%s", label);*/
267        free(current_attr->data);
268        free(current_attr);
269        current_attr = NULL;
270        return EES_SUCCESS;
271      } else {
272        return EES_FAILURE;
273      }
274    
275  }  }
276    
277  void* aos_get_value_by_label(const char *label){  void* aos_get_value_by_label(const char *label){
# Line 393  aos_attribute_t * aos_get_attribute_by_l Line 310  aos_attribute_t * aos_get_attribute_by_l
310    return NULL;    return NULL;
311  }  }
312    
 EES_RC aos_free_storage(aos_storage_t* storage){  
   aos_context_t   *context        = NULL, *next_context    = NULL;  
   aos_attribute_t *attribute      = NULL, *next_attribute  = NULL;  
   int             attribute_count = 0;  
   
   if(!storage){  
     return EES_FAILURE;  
   }  
   
   printf("Cleaning aos storage at %p\n", storage);  
   if(storage == _global_storage){  
     printf("This is the GLOBAL storage\n");  
   }  
   
   context = storage->list_contexts;  
   
   while(context){  
     next_context = context->next;  
     printf("Checking context at %p\n", context);  
     attribute = context->list_attributes;  
     while(attribute){  
       next_attribute = attribute->next;  
       /* free here */  
       printf("Checking attribute at %p\n", attribute);  
       if(attribute->needs_free){  
         eef_log(LOG_DEBUG, "Freeing arg %i at %p\n",attribute_count, attribute);  
         free(attribute->data);  
         free(attribute);  
       } else {  
         eef_log(LOG_DEBUG, "Not freeing arg %i at %p\n",attribute_count, attribute);  
       }  
       attribute = next_attribute;  
       attribute_count++;  
     }  
     /* free here */  
     free(context);  
     printf("Freeing context at %p\n", context);  
     context = next_context;  
   }  
   free(storage);  
   return EES_SUCCESS;  
 }  
   
313  /* initializer & terminator */  /* initializer & terminator */
314    
315  EES_RC AOS_Init (void){  EES_RC AOS_Init (void){
# Line 456  EES_RC AOS_Init (void){ Line 330  EES_RC AOS_Init (void){
330  }  }
331    
332  void aos_make_key(void){  void aos_make_key(void){
333    pthread_key_create(&_aos_key, NULL);    pthread_key_create(&_aos_key, aos_free_key);
334  }  }
335    
336  void aos_free_key(aos_storage_t* storage){  void aos_free_key(aos_storage_t* storage){
337    /*aos_free_storage(storage);*/    aos_free_storage(storage);
338  }  }
339    
340  EES_RC AOS_Clean(void){  EES_RC AOS_Clean(void){
# Line 470  EES_RC AOS_Clean(void){ Line 344  EES_RC AOS_Clean(void){
344    if(!_is_threading){    if(!_is_threading){
345      return EES_FAILURE;      return EES_FAILURE;
346    }    }
347    aos_free_storage(aos_get_storage());    /*aos_free_storage(aos_get_storage());*/
348    printf("Freed storage for thread %i\n", tid);    printf("Freed storage for thread %i\n", tid);
349    return EES_SUCCESS;    return EES_SUCCESS;
350  }  }
# Line 484  EES_RC AOS_Term (void){ Line 358  EES_RC AOS_Term (void){
358    return EES_SUCCESS;    return EES_SUCCESS;
359  }  }
360    
 EES_RC aos_dump_argslists (void){  
   eef_log(LOG_ERR, "Dumping AOS\n");  
   aos_dump_argslist();  
   return EES_SUCCESS;  
 }  
   
361  EES_RC aos_dump_argslist (void) {  EES_RC aos_dump_argslist (void) {
362    unsigned int i;    unsigned int i;
363    aos_context_t  * context;    aos_context_t  * context;

Legend:
Removed from v.1352  
changed lines
  Added in v.1353

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28