src/vapiIOXML.c

Ir para a documentaēćo deste ficheiro.
00001 #include "vapiOptionsXML.h"
00002 #include "vapiIOList.h"
00003 #include "vapiXML.h"
00004 
00005 xmlTextWriter *
00006 vapiIOXMLFileInit ()
00007 {
00008         xmlTextWriter *xmlOutput;
00009         char *filename = "vapiIOconf.vpi";
00010         /*
00011          * Como colocar a string do ficheiro Automatica.
00012          */
00013         xmlOutput = xmlNewTextWriterFilename (filename, 0);
00014 
00015         xmlTextWriterSetIndent (xmlOutput, 1);
00016 
00017         xmlTextWriterStartDocument (xmlOutput, NULL, "ISO-8859-1", NULL);
00018 
00019         xmlTextWriterStartDTD (xmlOutput, BAD_CAST "vapiCommunications", NULL,
00020                                NULL);
00021 
00022         xmlTextWriterWriteDTDElement (xmlOutput,
00023                                       BAD_CAST "vapiCommunications",
00024                                       BAD_CAST "(IOConfigured)*");
00025 
00026         xmlTextWriterWriteDTDElement (xmlOutput,
00027                                       BAD_CAST "IOConfigured",
00028                                       BAD_CAST "(option)*");
00029 
00030         xmlTextWriterWriteDTDAttlist (xmlOutput,
00031                                       BAD_CAST "IOConfigured",
00032                                       BAD_CAST "name NMTOKENS #REQUIRED");
00033 
00034         vapiOptionsXMLOptionsElement (xmlOutput, 0);
00035 
00036         xmlTextWriterEndDTD (xmlOutput);
00037 
00038         xmlTextWriterStartElement (xmlOutput, BAD_CAST "vapiCommunications");
00039 
00040         return xmlOutput;
00041 }
00042 
00043 void
00044 vapiIOConfiguredToXML ()
00045 {
00046         xmlTextWriter *xmlOutput;
00047         int i, ListSize;
00048         vIOConfigured *Item;
00049 
00050         /*
00051          * Criar cabeƧalho do Ficheiro XML.
00052          */
00053 
00054         xmlOutput = vapiIOXMLFileInit ();
00055 
00056         /*
00057          * Ir a cada OperaĆ§Ć£o da Macro.
00058          */
00059 
00060         ListSize = v_list_count_elements (GlobalIOListConfigured);
00061 
00062         if (!ListSize)
00063         {
00064                 return;
00065         }
00066 
00067         for (i = 0; i < ListSize; i++)
00068         {
00069                 Item = v_list_get (GlobalIOListConfigured, i);
00070 
00071                 xmlTextWriterStartElement (xmlOutput,
00072                                            BAD_CAST "IOConfigured");
00073 
00074                 xmlTextWriterWriteAttribute (xmlOutput, BAD_CAST "name",
00075                                              BAD_CAST Item->IO->IOname);
00076 
00077                 /*
00078                  * Get Options.
00079                  */
00080                 vapiOptionsXMLGetOptions (xmlOutput,
00081                                           Item->IO->OptionsSettings,
00082                                           Item->Options, NULL);
00083 
00084 
00085                 xmlTextWriterEndElement (xmlOutput);
00086 
00087         }
00088 
00089 
00090         xmlTextWriterEndDocument (xmlOutput);
00091 
00092         xmlFreeTextWriter (xmlOutput);
00093         v_info ("Guardada Lista de omunicaƧƵes para xml");
00094 
00095 }
00096 
00097 void
00098 vapiIOConfiguredListFromXML ()
00099 {
00100         char *filename = "vapiIOconf.vpi";
00101         xmlTextReader *xmlInput;
00102         vIO *tempIO;
00103         vOptions *tempOptions;
00104         int ret = 1;
00105         xmlInput = xmlReaderForFile (filename, "ISO-8859-1", XML_PARSE_DTDATTR |        /* default DTD attributes */
00106                                      XML_PARSE_NOENT |  /* substitute entities */
00107                                      XML_PARSE_DTDVALID);       /* validate with the DTD */
00108         
00109         if (xmlInput==NULL)
00110         {
00111                 return;
00112         }
00113         
00114         xmlTextReaderRead (xmlInput);
00115         if (!strcmp
00116             ((char *) xmlTextReaderLocalName (xmlInput),
00117              "vapiCommunications "))
00118         {
00119                 v_debug ("nĆ£o Ć© ficheiro de comunicaƧƵes");
00120                 return;
00121         }
00122         v_debug ("nome do tipo de xml detectado: %s",(char *) xmlTextReaderLocalName (xmlInput)); 
00123         
00124         xmlTextReaderRead (xmlInput);
00125         /*
00126          * Entramos nos IO's.
00127          */
00128         if (vapiXMLNextElement (xmlInput) > 0)
00129         {
00130                 if (strcmp
00131                     ((char *) xmlTextReaderLocalName (xmlInput),
00132                      "IOConfigured"))
00133                 {
00134                         v_debug ("nĆ£o tem um io configured, tem: %s", (char *) xmlTextReaderLocalName (xmlInput));
00135                         return;
00136                 }
00137 
00138                 while (ret > 0)
00139                 {
00140                         tempIO = vapiIOListSelect (GlobalIOList,
00141                                                    (char *)
00142                                                    xmlTextReaderGetAttribute
00143                                                    (xmlInput,
00144                                                     BAD_CAST "name"));
00145                         v_debug ("IO name: %s",
00146                                  xmlTextReaderGetAttribute (xmlInput,
00147                                                             BAD_CAST "name"));
00148 
00149                         tempOptions =
00150                                 vapiOptionsInit (tempIO->OptionsSettings);
00151                         
00152                         //vapiXMLNextElement (xmlInput);
00153 
00154                         vapiOptionsXMLSetOptions (xmlInput, tempOptions, NULL);
00155 
00156                         vapiIOListConfiguredAdd (tempIO, tempOptions);
00157 
00158                         ret = vapiXMLNextElement (xmlInput);
00159 
00160                         vapiOptionsCheck (tempIO->OptionsSettings,
00161                                           tempOptions);
00162 
00163                 }
00164 
00165         }
00166 
00167 
00168         v_info ("Carregada a List de ComunicaƧƵes de xml");
00169 }

Gerado em Tue Jul 24 10:34:59 2007 para Vapi por  doxygen 1.5.1