Commit d273d32b authored by Damien Lucas's avatar Damien Lucas

Code cleaning in order of the release:

. added header before each function
. wrapped all the lines to 79 with \
. added some comments
parent 85a76423
(snmp 7):
Prévenir le serveur d'un linkup/linkdown lors d'un catch snmp-trap
(snmp 8):
Gérer la fin du walk, notamment pour libérer la struct SNMP_req
(snmp 9):
Trouver un moyen de n'avoir rien de spécifique au model du switch dans
le code (fichier de conf, modules, ...)
......
......@@ -4,8 +4,8 @@
%{
#include <arpa/inet.h> /* types.h */
#include <string.h> /* strdup, strncmp */
#include <arpa/inet.h> /* types.h */
#include <string.h> /* strdup, strncmp */
#include "../types.h"
#include "../logger.h"
......@@ -138,8 +138,8 @@ nchannels{BL}{INT} {
cfg->chan_map=malloc(ul1*sizeof(struct CFG_CHANNEL));
if (cfg->chan_map==NULL)
{
VS_log(LOGERROR,CFG,"Unable to allocate memory to create the channels "\
" table");
VS_log(LOGERROR,CFG,"Unable to allocate memory to create the"\
"channels table");
return VS_R_MEMORY;
}
do
......@@ -250,8 +250,8 @@ channel{BL}{INT}{BL}vlan{BL}{INT}{BL}protection{BL}{INT} {
}
if ((VS_PROTECTION_LEVEL)ui1>=VS_PL_NUMBER)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels "\
"range from 0 to %lu",filename,line_num,\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: protection levels"\
" range from 0 to %lu",filename,line_num,\
(unsigned long)VS_PL_NUMBER-1);
return VS_R_PARSE;
}
......@@ -264,8 +264,8 @@ channel{BL}{INT}{BL}vlan{BL}{INT}{BL}protection{BL}{INT} {
cfg->chan_map[ul1].raw_data=malloc((CFG_yyleng+1)*sizeof(char));
if (cfg->chan_map[ul1].raw_data==NULL)
{
VS_log(LOGERROR,CFG,"Unable to allocate memory to store raw data for "\
"channel %lu",ul1);
VS_log(LOGERROR,CFG,"Unable to allocate memory to store raw data"\
" for channel %lu",ul1);
return VS_R_MEMORY;
}
memcpy(cfg->chan_map[ul1].raw_data,CFG_yytext,\
......@@ -362,7 +362,7 @@ switch{BL}type{BL}{NONBLANK}+ {
}
else
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : unknown switch "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: unknown switch "\
"type",filename,line_num);
return VS_R_PARSE;
}
......@@ -375,8 +375,8 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+sizeof("default")/sizeof(char)-1," %u",&ui1);
if (ui1>=VS_PL_NUMBER)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels "\
"range from 0 to %lu",filename,line_num,\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: protection levels"\
" range from 0 to %lu",filename,line_num,\
(unsigned long)VS_PL_NUMBER-1);
return VS_R_PARSE;
}
......@@ -400,13 +400,13 @@ switch{BL}type{BL}{NONBLANK}+ {
if (ui1>VS_UNIT_MAX || ui1<1)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : Switch unit "\
"range from 1 to %lu",filename,line_num,\
"range from 1 to %lu",filename,line_num,\
(unsigned long)VS_UNIT_MAX);
return VS_R_PARSE;
}
(*st)->unit=(VS_UNIT)ui1;
VS_log(LOGINFO,CFG,"Switch type %s on unit %u",\
CFG_SWITCH_TYPE_NAME(**st),ui1);
CFG_SWITCH_TYPE_NAME(**st),ui1);
}
......@@ -414,22 +414,22 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
return VS_R_PARSE;
}
sscanf(CFG_yytext+sizeof("port")/sizeof(char)-1, " %lu %u", &ul1,
sscanf(CFG_yytext+sizeof("port")/sizeof(char)-1, " %lu %u", &ul1,\
&ui1);
if (!ul1 || (VS_PORT)ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid port "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid port "\
"number", filename, line_num);
return VS_R_PARSE;
}
if ((VS_PROTECTION_LEVEL)ui1>=VS_PL_NUMBER)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : protection "
"levels range from 0 to %u", filename, line_num,
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : protection "\
"levels range from 0 to %u", filename, line_num,\
(unsigned int)VS_PL_NUMBER-1);
return VS_R_PARSE;
}
......@@ -441,7 +441,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
}
{
......@@ -454,7 +454,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid"\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -469,7 +469,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
}
{
......@@ -482,7 +482,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -497,7 +497,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
}
{
......@@ -510,7 +510,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -525,7 +525,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
}
{
......@@ -538,7 +538,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -554,13 +554,13 @@ switch{BL}type{BL}{NONBLANK}+ {
for (ul1=1;(VS_PORT)ul1<=(*st)->nports;ul1++)
if ((*st)->ports[ul1].protection==VS_PL_UNSPECIFIED)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : switch type %s "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: switch type %s "\
"has not been completely specified",filename,\
line_num,CFG_SWITCH_TYPE_NAME(**st));
return VS_R_PARSE;
}
VS_log(LOGDEBUG,CFG,"Switch type %s defined with the %lu following ports "\
":",CFG_SWITCH_TYPE_NAME(**st),\
VS_log(LOGDEBUG,CFG,"Switch type %s defined with the %lu following"\
"ports :",CFG_SWITCH_TYPE_NAME(**st),\
(unsigned long)(*st)->nports);
for (ul1=1;(VS_PORT)ul1<=(*st)->nports;ul1++)
VS_log(LOGDEBUG,CFG," Port %lu :\tprotection %lu \tflags %lu",ul1,\
......@@ -598,8 +598,8 @@ switch{BL}type{BL}{NONBLANK}+ {
*s=malloc(sizeof(struct CFG_SWITCH));
if(*s==NULL)
{
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a new "\
"switch in the database");
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a "\
"new switch in the database");
return VS_R_MEMORY;
}
......@@ -615,8 +615,8 @@ switch{BL}type{BL}{NONBLANK}+ {
/* UGLY, but we don't wanna waste memory nor cpu, do we ? */
if (ports==NULL)
{
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a new switch "\
"in the database");
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a "\
"new switch in the database");
return VS_R_MEMORY;
}
ports--;
......@@ -663,7 +663,7 @@ switch{BL}type{BL}{NONBLANK}+ {
}
if ((VS_PROTECTION_LEVEL)ui1>=VS_PL_NUMBER)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels"\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: protection levels"\
"range from 0 to %u",filename,line_num,\
(unsigned int)ui1);
ports++;
......@@ -692,7 +692,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
}
{
......@@ -705,7 +705,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -723,7 +723,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
"unknown yet", filename, line_num);
}
{
......@@ -736,7 +736,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -754,8 +754,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of"\
"ports unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -767,7 +767,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -785,8 +785,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of"\
"ports unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -798,7 +798,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -816,8 +816,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of"\
"ports unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -829,7 +829,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -847,8 +847,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of"\
"ports unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -860,7 +860,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -878,8 +878,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
" unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -891,7 +891,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -909,8 +909,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
" unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -922,7 +922,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -940,8 +940,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet", filename, line_num);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u: number of ports"\
" unknown yet", filename, line_num);
}
{
unsigned int i;
......@@ -953,7 +953,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "\
"port number", filename, line_num);
return VS_R_PARSE;
}
......@@ -971,7 +971,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if ((*s)->community==NULL)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : community string "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: community string "\
"unspecified",filename,line_num);
ports++;
free(ports);
......@@ -1003,8 +1003,8 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!eof_expected)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : unexpected end of "\
"file",filename,line_num);
VS_log(LOGERROR,CFG,"Parse error in %s on line %u: unexpected end of"\
" file",filename,line_num);
if (ports+1!=NULL)
free(ports+1);
return VS_R_PARSE;
......
#include <stdlib.h> /* free, malloc */
#include <pthread.h> /* pthread_mutex_lock */
#include <semaphore.h> /* sem_wait */
#include <arpa/inet.h> /* ip.h */
#include <ucd-snmp/asn1.h> /* snmp_switch.h */
#include <ucd-snmp/snmp_impl.h> /* snmp_switch.h */
#include <ucd-snmp/snmp_api.h> /* snmp_switch.h */
#include <stdlib.h> /* free, malloc */
#include <pthread.h> /* pthread_mutex_lock */
#include <semaphore.h> /* sem_wait */
#include <arpa/inet.h> /* ip.h */
#include <ucd-snmp/asn1.h> /* snmp_switch.h */
#include <ucd-snmp/snmp_impl.h> /* snmp_switch.h */
#include <ucd-snmp/snmp_api.h> /* snmp_switch.h */
#include "../types.h"
#include "../logger.h"
#include "../snmp/snmp_switch.h" /* struct SNMP_switch */
#include "../snmp/snmp_switch.h" /* struct SNMP_switch */
#include "db.h"
/******************************************************************************
/*****************************************************************************
* DB_M_push_req
******************************************************************************
*****************************************************************************
* inserts a request in a machine's fifo. request->next won't be set to NULL.
* wakes the thread up if it can process. this function is called by the
* database engine
******************************************************************************/
*****************************************************************************/
static inline void DB_M_push_req(struct DB_machines_elt * machine,\
struct DB_M_request * request)
{
......@@ -38,13 +38,13 @@ static inline void DB_M_push_req(struct DB_machines_elt * machine,\
}
}
/******************************************************************************
/*****************************************************************************
* DB_S_push_req
******************************************************************************
* inserts a request in a port's fifo. request->next won't be set to NULL. wakes
* the thread up if it can process. this function is called by the database
* engine
******************************************************************************/
*****************************************************************************
* inserts a request in a port's fifo. request->next won't be set to NULL.
* wakes the thread up if it can process. this function is called by the
* database engine
*****************************************************************************/
static inline void DB_S_push_req(struct DB_port * port,\
struct DB_S_request * request)
{
......@@ -64,13 +64,13 @@ static inline void DB_S_push_req(struct DB_port * port,\
}
}
/******************************************************************************
/*****************************************************************************
* DB_M_pop_req
******************************************************************************
*****************************************************************************
* removes a request from a machine's fifo and executes the following one if
* there is a one. Note there must be something in the fifo.
* This function is called by clients of the database engine
******************************************************************************/
*****************************************************************************/
static inline void DB_M_pop_req(struct DB_machines_elt * machine)
{
struct DB_M_request * z;
......@@ -86,13 +86,13 @@ static inline void DB_M_pop_req(struct DB_machines_elt * machine)
free(z);
}
/******************************************************************************
/*****************************************************************************
* DB_S_pop_req
******************************************************************************
*****************************************************************************
* removes a request from a port's fifo and executes the following one if there
* is a one. Note there must be something in the fifo.
* This function is called by clients of the database engine
******************************************************************************/
*****************************************************************************/
static inline void DB_S_pop_req(struct DB_port * port)
{
struct DB_S_request * z;
......@@ -108,13 +108,13 @@ static inline void DB_S_pop_req(struct DB_port * port)
free(z);
}
/******************************************************************************
/*****************************************************************************
* DB_M_insert
******************************************************************************
*****************************************************************************
* inserts a machine in the machines table. this function is called by the
* database engine when executing a request
* this function never fails, so req->ret_value is set to 0
******************************************************************************/
*****************************************************************************/
static void DB_M_insert(struct DB_db * db, struct DB_M_request * req)
{
unsigned int i;
......@@ -126,13 +126,13 @@ static void DB_M_insert(struct DB_db * db, struct DB_M_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_S_insert
******************************************************************************
*****************************************************************************
* inserts a switch in the switchs table. this function is called by the
* database engine when executing a request
* this function never fails, so req->ret_value is set to 0
******************************************************************************/
*****************************************************************************/
static void DB_S_insert(struct DB_db * db,struct DB_S_request * req)
{
unsigned int i;
......@@ -145,14 +145,14 @@ static void DB_S_insert(struct DB_db * db,struct DB_S_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_M_lock
******************************************************************************
*****************************************************************************
* takes the lock on a machine in the table. this function is called by the
* database engine when executing a request
* req->ret_value will be set to VS_R_ABSENT if the machine does not exist, and
* to 0 otherwise
******************************************************************************/
* req->ret_value will be set to VS_R_ABSENT if the machine does not exist,
* and to 0 otherwise
*****************************************************************************/
static void DB_M_lock(struct DB_db * db, struct DB_M_request * req)
{
struct DB_machines_elt * z;
......@@ -172,14 +172,14 @@ static void DB_M_lock(struct DB_db * db, struct DB_M_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_S_port_lock
******************************************************************************
*****************************************************************************
* takes the lock on a port in the table. this function is called by the
* database engine when executing a request
* req->ret_value will be set to VS_R_ABSENT if the switch does not exist, and
* to 0 otherwise
******************************************************************************/
*****************************************************************************/
static void DB_S_port_lock(struct DB_db * db,struct DB_S_request * req)
{
struct DB_switchs_elt * z;
......@@ -201,14 +201,14 @@ static void DB_S_port_lock(struct DB_db * db,struct DB_S_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_S_lock
******************************************************************************
*****************************************************************************
* takes the lock on all the ports of a switch in the table. this function is
* called by the database engine when executing a request
* req->ret_value will be set to VS_R_ABSENT if the switch does not exist, and
* to 0 otherwise
******************************************************************************/
*****************************************************************************/
static void DB_S_lock(struct DB_db * db, struct DB_S_request * req)
{
unsigned int i;
......@@ -233,13 +233,13 @@ static void DB_S_lock(struct DB_db * db, struct DB_S_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_M_unlock
******************************************************************************
*****************************************************************************
* releases the lock on a machine in the table. this function is called by the
* database engine when executing a request
* as this function always succeeds, req->ret_value is set to 0
******************************************************************************/
*****************************************************************************/
static void DB_M_unlock(struct DB_db * db,struct DB_M_request * req)
{
DB_M_pop_req(req->argument.glop);
......@@ -247,13 +247,13 @@ static void DB_M_unlock(struct DB_db * db,struct DB_M_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_S_port_unlock
******************************************************************************
* releases the lock on a switch's port in the table. this function is called by
* the database engine when executing a request
*****************************************************************************
* releases the lock on a switch's port in the table. this function is called
* by the database engine when executing a request
* as this function always succeeds, req->ret_value is set to 0
******************************************************************************/
*****************************************************************************/
static void DB_S_port_unlock(struct DB_db * db,struct DB_S_request * req)
{
DB_S_pop_req(req->argument.glip);
......@@ -262,14 +262,14 @@ static void DB_S_port_unlock(struct DB_db * db,struct DB_S_request * req)
sem_post(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_M_delete
******************************************************************************
*****************************************************************************
* removes a machine from the machines table. this function is called by the
* database engine when executing a request
* req->ret_value will be set to VS_R_ABSENT if the machine is not found, and to
* 0 otherwise
******************************************************************************/
* req->ret_value will be set to VS_R_ABSENT if the machine is not found, and
* to 0 otherwise
*****************************************************************************/
static void DB_M_delete(struct DB_db * db,struct DB_M_request * req)
{
unsigned int zob;
......@@ -314,12 +314,12 @@ static void DB_M_delete(struct DB_db * db,struct DB_M_request * req)
}
}
/******************************************************************************
/*****************************************************************************
* DB_M_req
******************************************************************************
* inserts a request on the machines table in the fifo. this function is called
* by clients of the database engine
******************************************************************************/
*****************************************************************************
* inserts a request on the machines table in the fifo. this function is
* called by clients of the database engine
*****************************************************************************/
static void DB_M_req(struct DB_db * db, struct DB_M_request * req,
void (* func)(struct DB_db * db, struct DB_M_request *),
union DB_M_union argument)
......@@ -340,12 +340,12 @@ static void DB_M_req(struct DB_db * db, struct DB_M_request * req,
sem_destroy(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_S_req
******************************************************************************
*****************************************************************************
* inserts a request on the switchs table in the fifo. this function is called
* by clients of the database engine
******************************************************************************/
*****************************************************************************/
static void DB_S_req(struct DB_db *db, struct DB_S_request *req,
void (* func)(struct DB_db * db, struct DB_S_request *),
union DB_S_union argument)
......@@ -371,11 +371,12 @@ static void DB_S_req(struct DB_db *db, struct DB_S_request *req,
sem_destroy(&req->semaphore);
}
/******************************************************************************
/*****************************************************************************
* DB_machines_loop
******************************************************************************
* the database loop for machines, always running, called by the database engine
******************************************************************************/
*****************************************************************************
* the database loop for machines, always running, called by the database
* engine
*****************************************************************************/
static void * DB_machines_loop(struct DB_db * db)
{
struct DB_M_request * z;
......@@ -410,11 +411,12 @@ static void * DB_machines_loop(struct DB_db * db)
return NULL;
}
/******************************************************************************
/*****************************************************************************
* DB_switchs_loop
******************************************************************************
* the database loop for switchs, always running, called by the database engine
******************************************************************************/
*****************************************************************************
* the database loop for switchs, always running, called by the database
* engine
*****************************************************************************/
static void * DB_switchs_loop(struct DB_db * db)
{
struct DB_S_request * z;
......@@ -440,12 +442,12 @@ static void * DB_switchs_loop(struct DB_db * db)
return NULL;
}
/******************************************************************************
/*****************************************************************************
* DB_cancel
******************************************************************************
*****************************************************************************
* the function whose role is to cancel the database engine when its
* initialization has failed
******************************************************************************/
*****************************************************************************/
static void DB_cancel(struct DB_db * db)
{
db->runlevel=DB_CANCEL;
......@@ -457,16 +459,18 @@ static void DB_cancel(struct DB_db * db)
VS_log(LOGERROR,DB,"Unable to spawn the database engine");
}
/******************************************************************************/
/* user functions */
/******************************************************************************/
/******************************************************************************
/*****************************************************************************/
/* user functions */
/*****************************************************************************/
/*****************************************************************************
* DB_start
******************************************************************************
*****************************************************************************
* starts the database engine *
* returns VS_R_PTHREAD in case of problemes, 0 otherwise
******************************************************************************/
*****************************************************************************/
ERR_CODE DB_start(struct DB_db * db)
{
unsigned int i;
......@@ -504,12 +508,12 @@ ERR_CODE DB_start(struct DB_db * db)
return 0;
}
/******************************************************************************
/*****************************************************************************
* DB_machines_insert
******************************************************************************
*****************************************************************************
* inserts a new machine in the database *
* returns VS_R_MEMORY in case of problems, and 0 otherwise
******************************************************************************/
*****************************************************************************/
ERR_CODE DB_machines_insert(struct DB_db * db, VS_MachineId mac,
VS_SwitchId switch_ip, VS_PORT port,
VS_CHANNEL channel)
......@@ -535,12 +539,12 @@ ERR_CODE DB_machines_insert(struct DB_db * db, VS_MachineId mac,
return VS_R_MEMORY;
}