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/Vaike/linux/system-addons/networking/mesh_analysis.c

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 #include <stdlib.h>
00036 #include <string.h>
00037 #include <dlfcn.h>
00038 #include <errno.h>
00039 #include <sys/time.h>
00040 
00041 #include "mesh_analysis.h"
00042 
00043 
00044 int add_analysis(self_t *self, char *name, int id, char *path,
00045                  char *ctl_size_fctn, char *analysis_fctn)
00046 {
00047   analysis_t *anly = malloc(sizeof(analysis_t));
00048 
00049   anly->sensor = self;
00050   strncpy(anly->name, name, ANLY_NAMELEN);
00051   anly->unique_id = id;
00052 
00053   if ((anly->lib_handle = dlopen(path, RTLD_LAZY)) == NULL) {
00054     syslog(LOG_ERR, "add_analysis: %s", dlerror());
00055     free(anly);
00056     return -1;
00057   }
00058 
00059   anly->mesh_analysis = dlsym(anly->lib_handle, analysis_fctn);
00060   if ((errstr = dlerror()) != NULL) {
00061     syslog(LOG_ERR, "add_analysis (analysis fctn): %s", errstr);
00062     dlclose(anly->lib_handle);
00063     free(anly);
00064     return -1;
00065   }
00066 
00067   if (self->last_a != NULL)
00068     self->last_a->next = anly;
00069 
00070   if (self->analyses == NULL) {
00071     self->analyses = anly;
00072     self->last_a = anly;
00073   }
00074   self->last_a = anly;
00075 
00076   return 0;
00077 }
00078 
00079 
00080 int delete_analysis(self_t *self, char *string)
00081 {
00082   analysis_t *prev = NULL, *iter = self->analyses;
00083   while (iter != NULL) {
00084     if (strcasecmp(string, iter->name) == 0) {
00085       if (prev == NULL)
00086         self->analyses = iter->next;
00087       else
00088         prev->next = iter->next;
00089       dlclose(iter->lib_handle);
00090       free(iter);
00091       return 0;
00092     }
00093     prev = iter;
00094     iter = iter->next;
00095   }
00096   return -1;
00097 }
00098 
00099 
00100 analysis_t *analysis_by_string(self_t *self, char *string)
00101 {
00102   analysis_t *iter = self->analyses;
00103   while (iter != NULL) {
00104     if (strcasecmp(string, iter->name) == 0)
00105       return iter;
00106     iter = iter->next;
00107   }
00108   return NULL;
00109 }
00110 
00111 
00112 analysis_t *analysis_by_id(self_t *self, int id)
00113 {
00114  analysis_t *iter = self->analyses;
00115   while (iter != NULL) {
00116     if (id == iter->unique_id)
00117       return iter;
00118     iter = iter->next;
00119   }
00120   return NULL;
00121 }
00122 
00123 
00124 int analyze(self_t *self, struct msghdr *mh)
00125 {
00126   analysis_t *iter = self->analyses;
00127   while (iter != NULL) {
00128     iter->mesh_analysis(mh);
00129   }
00130 }


© 2007, Los Alamos National Security, LLC.