N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/shared/configuration.h

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 #ifndef _CONFIGURATION_H_
00036 #define _CONFIGURATION_H_
00037 
00038 #include "source_type.h"
00039 #include "coordinates.h"
00040 #include "avl.h"
00041 #include "expat.h"
00042 
00043 #define MAX_XML_PATH  1024
00044 
00045 class Configuration {
00046         /* for use in xml parsing */
00047         char _xml_path[MAX_XML_PATH];
00048         Sensor_node *_cur_node;
00049         Sensor_device *_cur_sensor;
00050         int _num_sensors;
00051 
00052         static inline void _start_element(void *user_data, 
00053                                                   const char *name, 
00054                                                   const char **attr) {
00055                 Configuration *c = reinterpret_cast<Configuration*>(user_data);
00056                 if (c != NULL)
00057                         c->on_start_element(name, attr);
00058         };
00059         static inline void _end_element(void *user_data, 
00060                                                 const char *name) {
00061                 Configuration *c = reinterpret_cast<Configuration*>(user_data);
00062                 if (c != NULL)
00063                         c->on_end_element(name);
00064         };
00065         static inline void _character_data(void *user_data, 
00066                                                    const char *name, int len) {
00067                 Configuration *c = reinterpret_cast<Configuration*>(user_data);
00068                 if (c != NULL)
00069                         c->on_character_data(name, len);
00070         };
00071         /**************************/
00072 
00073         int modified;
00074 
00075         char name[MAX_NAME];
00076         Coordinates origin;
00077 
00078         unsigned int num_types;
00079         Source_type *types;
00080 
00081         AVL_tree<unsigned long> nodes;
00082         Source_type_tree *sensors;
00083         Source_type_tree *sources;
00084         AVL_tree<unsigned long> obstructions;
00085         Source_type_tree *materials;
00086 
00087  public:
00088         Configuration();
00089         Configuration(char *);
00090         ~Configuration();
00091         void clear();
00092 
00093         Coordinates get_origin() { return origin; };
00094         char *get_name() { return name; };
00095         AVL_tree<unsigned long> *get_nodes() { return &nodes; };
00096         Source_type_tree *get_sources() { return sources; };
00097         int modded() { return modified; };
00098 
00099         void set_origin(Coordinates c) { origin = c; };
00100         void set_name(const char *n, int len) { 
00101                 int size = len > MAX_NAME ? MAX_NAME : len;
00102                 strncpy(name, n, size);
00103         };
00104 
00105         void on_start_element(const char*, const char**);
00106         void on_end_element(const char*);
00107         void on_character_data(const char*, int);
00108 
00109         void add_Source_type(char *name);
00110         int Source_type_index(char *name);
00111         char *index_Source_type(int idx);
00112         AVL_tree<unsigned long> *Source_type_tree_index(Source_type_tree *t,
00113                                                         char *type);
00114 
00115         int open(char *);
00116         int save(char *);
00117 
00118         char *cfg_to_xml();  // must free returned string
00119         int xml_to_cfg(char *string);
00120         int read_file(FILE *file);
00121         int write_file(FILE *file);
00122 };
00123 
00124 
00125 #endif  // _CONFIGURATION_H_


© 2007, Los Alamos National Security, LLC.