Index: trunk/zoo-project/zoo-kernel/service.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service.c	(revision 757)
+++ trunk/zoo-project/zoo-kernel/service.c	(revision 790)
@@ -74,8 +74,8 @@
 
 /**
- * Dump a map to a file
+ * Dump a map to a file 
  *
  * @param t the map to dump to file
- * @param file the file to store the map
+ * @param file the file pointer to store the map
  */
 void dumpMapToFile(map* t,FILE* file){
@@ -96,5 +96,8 @@
   while(tmp!=NULL){
     fprintf(stderr,"MAP => [%s] \n",tmp->name);
+    fprintf(stderr," * CONTENT [%s] \n",tmp->name);
     dumpMap(tmp->content);
+    fprintf(stderr," * CHILD [%s] \n",tmp->name);
+    dumpMaps(tmp->child);
     tmp=tmp->next;
   }
@@ -105,13 +108,15 @@
  *
  * @param m the map to dump
- * @param file_path the full path to the file name to store the map
- */
-void dumpMapsToFile(maps* m,char* file_path,int limit){
-  FILE* file=fopen(file_path,"w+");
+ * @param file the the file pointer to store the map
+ */
+void _dumpMapsToFile(maps* m,FILE* file,int limit){
   maps* tmp=m;
   int cnt=0;
   while(tmp!=NULL){
     fprintf(file,"[%s]\n",tmp->name);
-    dumpMapToFile(tmp->content,file);
+    if(tmp->child!=NULL){
+      _dumpMapsToFile(tmp->child,file,limit);
+    }else
+      dumpMapToFile(tmp->content,file);
     fflush(file);
     tmp=tmp->next;
@@ -121,4 +126,17 @@
   }
   fflush(file);
+}
+
+/**
+ * Dump a maps to a file, see _dumpMapsToFile().
+ *
+ * @param m the map to dump
+ * @param file_path the full path to the file name to store the map
+ * @param limit the number limiting the maps to be dumped
+ */
+void dumpMapsToFile(maps* m,char* file_path,int limit){
+  FILE* file=fopen(file_path,"w+");
+  _dumpMapsToFile(m,file,limit);
+  fflush(file);
   fclose(file);
 }
@@ -129,5 +147,5 @@
  * @param name the key to add to the map
  * @param value the corresponding value to add to the map
- * @return the allocated map
+ * @return a pointer to the allocated map 
  */
 map* createMap(const char* name,const char* value){
@@ -136,4 +154,19 @@
   tmp->value=zStrdup(value);
   tmp->next=NULL;
+  return tmp;
+}
+
+/**
+ * Create a new maps with the given name
+ *
+ * @param name of the maps
+ * @return the allocated map
+ */
+maps* createMaps(const char* name){
+  maps* tmp = (maps *) malloc (MAPS_SIZE);
+  tmp->name = zStrdup (name);
+  tmp->content = NULL;
+  tmp->child = NULL;
+  tmp->next = NULL;
   return tmp;
 }
@@ -283,4 +316,8 @@
       freeMap(&_cursor->content);
       free(_cursor->content);
+    }
+    if(_cursor->child!=NULL){
+      freeMaps(&_cursor->child);
+      free(_cursor->child);
     }
     if(_cursor->next!=NULL){
@@ -362,4 +399,8 @@
     if(tmp->format!=NULL)
       free(tmp->format);
+    if(tmp->child!=NULL){
+      freeElements(&tmp->child);
+      free(tmp->child);
+    }
     freeIOType(&tmp->defaults);
     if(tmp->defaults!=NULL)
@@ -593,19 +634,20 @@
 iotype* getIoTypeFromElement(elements* e,char *name, map* values){
   elements* cursor=e;
-  while(cursor!=NULL){
-    if(strcasecmp(cursor->name,name)==0){
-      if(contains(cursor->defaults->content,values)==true)
-	return cursor->defaults;
-      else{
-	iotype* tmp=cursor->supported;
-	while(tmp!=NULL){
-	  if(contains(tmp->content,values)==true)
-	    return tmp;	    
-	  tmp=tmp->next;
+  if(values!=NULL)
+    while(cursor!=NULL){
+      if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
+	if(contains(cursor->defaults->content,values)==true)
+	  return cursor->defaults;
+	else{
+	  iotype* tmp=cursor->supported;
+	  while(tmp!=NULL){
+	    if(contains(tmp->content,values)==true)
+	      return tmp;	    
+	    tmp=tmp->next;
+	  }
 	}
       }
-    }
-    cursor=cursor->next;
-  }
+      cursor=cursor->next;
+    }
   return NULL;
 }
@@ -677,12 +719,13 @@
   maps* res=NULL;
   if(_cursor!=NULL){
-    res=(maps*)malloc(MAPS_SIZE);
-    res->name=zStrdup(_cursor->name);
-    res->content=NULL;
-    res->next=NULL;
+    res=createMaps(_cursor->name);
     map* mc=_cursor->content;
     if(mc!=NULL){
       addMapToMap(&res->content,mc);
       loadMapBinaries(&res->content,mc);
+    }
+    maps* mcs=_cursor->child;
+    if(mcs!=NULL){
+      res->child=dupMaps(&mcs);
     }
     res->next=dupMaps(&_cursor->next);
@@ -709,8 +752,18 @@
 	_cursor=_cursor->next;
       maps* tmp1=getMaps(*mo,tmp->name);
-      if(tmp1==NULL)
+      if(tmp1==NULL){
 	_cursor->next=dupMaps(&tmp);
-      else
+	if(tmp->child!=NULL)
+	  _cursor->next->child=dupMaps(&tmp->child);
+	else
+	  _cursor->next->child=NULL;
+      }
+      else{
 	addMapToMap(&tmp1->content,tmp->content);
+	if(tmp->child!=NULL)
+	  tmp1->child=dupMaps(&tmp->child);
+	else
+	  tmp1->child=NULL;
+      }
       _cursor=*mo;
     }
@@ -872,8 +925,6 @@
       _ztmpm->value=zStrdup(value);
     }else{
-      maps *tmp=(maps*)malloc(MAPS_SIZE);
-      tmp->name=zStrdup(key);
+      maps *tmp=createMaps(key);
       tmp->content=createMap(subkey,value);
-      tmp->next=NULL;
       addMapsToMaps(&_tmpm,tmp);
       freeMaps(&tmp);
@@ -881,12 +932,65 @@
     }
   }else{
-    maps *tmp=(maps*)malloc(MAPS_SIZE);
-    tmp->name=zStrdup(key);
+    maps *tmp=createMaps(key);
     tmp->content=createMap(subkey,value);
-    tmp->next=NULL;
     addMapsToMaps(&m,tmp);
     freeMaps(&tmp);
     free(tmp);
   }
+}
+
+/**
+ * Create an empty elements
+ *
+ * @return a pointer to the allocated elements
+ */
+elements* createEmptyElements(){
+  elements* res=(elements*)malloc(ELEMENTS_SIZE);
+  res->name=NULL;
+  res->content=NULL;
+  res->metadata=NULL;
+  res->format=NULL;
+  res->defaults=NULL;
+  res->supported=NULL;
+  res->child=NULL;
+  res->next=NULL;
+  return res;
+}
+
+/**
+ * Create a named elements
+ *
+ * @param name the elements name
+ * @return a pointer to the allocated elements
+ */
+elements* createElements(char* name){
+  elements* res=(elements*)malloc(ELEMENTS_SIZE);
+  res->name=zStrdup(name);
+  res->content=NULL;
+  res->metadata=NULL;
+  res->format=NULL;
+  res->defaults=NULL;
+  res->supported=NULL;
+  res->child=NULL;
+  res->next=NULL;
+  return res;
+}
+
+/**
+ * Set the name of an elements
+ *
+ * @param name the elements name
+ * @return a pointer to the allocated elements
+ */
+void setElementsName(elements** elem,char* name){
+  elements* res=*elem;
+  res->name=zStrdup(name);
+  res->content=NULL;
+  res->metadata=NULL;
+  res->format=NULL;
+  res->defaults=NULL;
+  res->supported=NULL;
+  res->child=NULL;
+  res->next=NULL;
 }
 
@@ -921,4 +1025,8 @@
       ioc++;
     }
+    if(tmp->child!=NULL){
+      fprintf(stderr," > CHILD \n");
+      dumpElements(tmp->child);
+    }
     fprintf(stderr,"------------------\n");
     tmp=tmp->next;
@@ -931,14 +1039,14 @@
  * @param e the elements to dump
  */
-void dumpElementsAsYAML(elements* e){
+void dumpElementsAsYAML(elements* e,int level){
   elements* tmp=e;
   int i;
   while(tmp!=NULL){
-    for(i=0;i<2;i++)
+    for(i=0;i<2+(4*level);i++)
       fprintf(stderr," ");
     fprintf(stderr,"%s:\n",tmp->name);
     map* mcurs=tmp->content;
     while(mcurs!=NULL){
-      for(i=0;i<4;i++)
+      for(i=0;i<4+(4*level);i++)
 	fprintf(stderr," ");
       _dumpMap(mcurs);
@@ -947,9 +1055,9 @@
     mcurs=tmp->metadata;
     if(mcurs!=NULL){
-      for(i=0;i<4;i++)
+      for(i=0;i<4+(4*level);i++)
 	fprintf(stderr," ");
       fprintf(stderr,"MetaData:\n");
       while(mcurs!=NULL){
-	for(i=0;i<6;i++)
+	for(i=0;i<6+(4*level);i++)
 	  fprintf(stderr," ");
 	_dumpMap(mcurs);
@@ -957,16 +1065,22 @@
       }
     }
-    for(i=0;i<4;i++)
+    for(i=0;i<4+(4*level);i++)
       fprintf(stderr," ");
-    fprintf(stderr,"%s:\n",tmp->format);
+    if(tmp->format!=NULL)
+      fprintf(stderr,"%s:\n",tmp->format);
+    else{
+      fprintf(stderr,"Child:\n");
+      if(tmp->child!=NULL)
+	dumpElementsAsYAML(tmp->child,level+1);
+    }
     iotype* tmpio=tmp->defaults;
     int ioc=0;
     while(tmpio!=NULL){
-      for(i=0;i<6;i++)
+      for(i=0;i<6+(4*level);i++)
 	fprintf(stderr," ");
       fprintf(stderr,"default:\n");
       mcurs=tmpio->content;
       while(mcurs!=NULL){
-	for(i=0;i<8;i++)
+	for(i=0;i<8+(4*level);i++)
 	  fprintf(stderr," ");
 	if(strcasecmp(mcurs->name,"range")==0){
@@ -982,10 +1096,10 @@
     ioc=0;
     while(tmpio!=NULL){
-      for(i=0;i<6;i++)
+      for(i=0;i<6+(4*level);i++)
 	fprintf(stderr," ");
       fprintf(stderr,"supported:\n");
       mcurs=tmpio->content;
       while(mcurs!=NULL){
-	for(i=0;i<8;i++)
+	for(i=0;i<8+(4*level);i++)
 	  fprintf(stderr," ");
 	if(strcasecmp(mcurs->name,"range")==0){
@@ -1055,4 +1169,8 @@
     else
       tmp->supported=NULL;
+    if(cursor->child!=NULL)
+      tmp->child=dupElements(cursor->child);
+    else
+      tmp->child=NULL;
     tmp->next=dupElements(cursor->next);
   }
@@ -1075,5 +1193,19 @@
   }
 }
-  
+
+/**
+ * Set the name of a service
+ *
+ * @param name the service name
+ */
+void setServiceName(service** serv,char* name){
+  service* res=*serv;
+  res->name=zStrdup(name);
+  res->content=NULL;
+  res->metadata=NULL;
+  res->inputs=NULL;
+  res->outputs=NULL;
+}
+
 /**
  * Dump a service on stderr
@@ -1126,9 +1258,9 @@
   if(s->inputs!=NULL){
     fprintf(stderr,"\ninputs:\n");
-    dumpElementsAsYAML(s->inputs);
+    dumpElementsAsYAML(s->inputs,0);
   }
   if(s->outputs!=NULL){
     fprintf(stderr,"\noutputs:\n");
-    dumpElementsAsYAML(s->outputs);
+    dumpElementsAsYAML(s->outputs,0);
   }
 }
