[f8fb072] | 1 | // ******************************************************************************************************** |
---|
| 2 | // Servicio: ogAdmAgent |
---|
| 3 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla |
---|
| 4 | // Fecha Creación: Marzo-2010 |
---|
| 5 | // Fecha Última modificación: Marzo-2010 |
---|
| 6 | // Nombre del fichero: ogAdmAgent.cpp |
---|
| 7 | // Descripción: Este fichero implementa el servicio agente del sistema. Revisa a intervalos |
---|
| 8 | // regulares la base de datos para comprobar si existen acciones programadas. |
---|
| 9 | // ******************************************************************************************************** |
---|
| 10 | #include "ogAdmAgent.h" |
---|
| 11 | #include "ogAdmLib.c" |
---|
| 12 | //________________________________________________________________________________________________________ |
---|
| 13 | // Función: tomaConfiguracion |
---|
| 14 | // |
---|
| 15 | // Descripción: |
---|
| 16 | // Lee el fichero de configuración del servicio |
---|
| 17 | // Parámetros: |
---|
| 18 | // filecfg : Ruta completa al fichero de configuración |
---|
| 19 | // Devuelve: |
---|
| 20 | // TRUE: Si el proceso es correcto |
---|
| 21 | // FALSE: En caso de ocurrir algún error |
---|
| 22 | //________________________________________________________________________________________________________ |
---|
| 23 | BOOLEAN tomaConfiguracion(char* filecfg) |
---|
| 24 | { |
---|
| 25 | char modulo[] = "tomaConfiguracion()"; |
---|
| 26 | |
---|
| 27 | if (filecfg == NULL || strlen(filecfg) == 0) { |
---|
| 28 | errorLog(modulo, 1, FALSE); // Fichero de configuración del servicio vacío |
---|
| 29 | return (FALSE); |
---|
| 30 | } |
---|
| 31 | FILE *fcfg; |
---|
| 32 | long lSize; |
---|
| 33 | char * buffer, *lineas[MAXPRM], *dualparametro[2]; |
---|
| 34 | int i, numlin, resul; |
---|
| 35 | |
---|
| 36 | fcfg = fopen(filecfg, "rt"); |
---|
| 37 | if (fcfg == NULL) { |
---|
| 38 | errorLog(modulo, 2, FALSE); // No existe fichero de configuración del servicio |
---|
| 39 | return (FALSE); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | fseek(fcfg, 0, SEEK_END); |
---|
| 43 | lSize = ftell(fcfg); // Obtiene tamaño del fichero. |
---|
| 44 | rewind(fcfg); |
---|
| 45 | buffer = (char*) reservaMemoria(lSize + 1); // Toma memoria para el buffer de lectura. |
---|
| 46 | if (buffer == NULL) { // No hay memoria suficiente para el buffer |
---|
| 47 | errorLog(modulo, 3, FALSE); |
---|
| 48 | return (FALSE); |
---|
| 49 | } |
---|
| 50 | fread(buffer, 1, lSize, fcfg); // Lee contenido del fichero |
---|
| 51 | buffer[lSize] = (char) NULL; |
---|
| 52 | fclose(fcfg); |
---|
| 53 | |
---|
| 54 | servidoradm[0] = (char) NULL; //inicializar variables globales |
---|
| 55 | puerto[0] = (char) NULL; |
---|
| 56 | usuario[0] = (char) NULL; |
---|
| 57 | pasguor[0] = (char) NULL; |
---|
| 58 | datasource[0] = (char) NULL; |
---|
| 59 | catalog[0] = (char) NULL; |
---|
| 60 | |
---|
| 61 | numlin = splitCadena(lineas, buffer, '\n'); |
---|
| 62 | for (i = 0; i < numlin; i++) { |
---|
| 63 | splitCadena(dualparametro, lineas[i], '='); |
---|
| 64 | resul = strcmp(StrToUpper(dualparametro[0]), "SERVIDORADM"); |
---|
| 65 | if (resul == 0) |
---|
| 66 | strcpy(servidoradm, dualparametro[1]); |
---|
| 67 | resul = strcmp(StrToUpper(dualparametro[0]), "PUERTO"); |
---|
| 68 | if (resul == 0) |
---|
| 69 | strcpy(puerto, dualparametro[1]); |
---|
| 70 | resul = strcmp(StrToUpper(dualparametro[0]), "USUARIO"); |
---|
| 71 | if (resul == 0) |
---|
| 72 | strcpy(usuario, dualparametro[1]); |
---|
| 73 | resul = strcmp(StrToUpper(dualparametro[0]), "PASSWORD"); |
---|
| 74 | if (resul == 0) |
---|
| 75 | strcpy(pasguor, dualparametro[1]); |
---|
| 76 | resul = strcmp(StrToUpper(dualparametro[0]), "DATASOURCE"); |
---|
| 77 | if (resul == 0) |
---|
| 78 | strcpy(datasource, dualparametro[1]); |
---|
| 79 | resul = strcmp(StrToUpper(dualparametro[0]), "CATALOG"); |
---|
| 80 | if (resul == 0) |
---|
| 81 | strcpy(catalog, dualparametro[1]); |
---|
| 82 | } |
---|
| 83 | if (servidoradm[0] == (char) NULL) { |
---|
| 84 | errorLog(modulo, 4, FALSE); // Falta parámetro SERVIDORADM |
---|
| 85 | return (FALSE); |
---|
| 86 | } |
---|
| 87 | if (puerto[0] == (char) NULL) { |
---|
| 88 | errorLog(modulo, 5, FALSE); // Falta parámetro PUERTO |
---|
| 89 | return (FALSE); |
---|
| 90 | } |
---|
| 91 | if (usuario[0] == (char) NULL) { |
---|
| 92 | errorLog(modulo, 6, FALSE); // Falta parámetro USUARIO |
---|
| 93 | return (FALSE); |
---|
| 94 | } |
---|
| 95 | if (pasguor[0] == (char) NULL) { |
---|
| 96 | errorLog(modulo, 7, FALSE); // Falta parámetro PASSWORD |
---|
| 97 | return (FALSE); |
---|
| 98 | } |
---|
| 99 | if (datasource[0] == (char) NULL) { |
---|
| 100 | errorLog(modulo, 8, FALSE); // Falta parámetro DATASOURCE |
---|
| 101 | return (FALSE); |
---|
| 102 | } |
---|
| 103 | if (catalog[0] == (char) NULL) { |
---|
| 104 | errorLog(modulo, 9, FALSE); // Falta parámetro CATALOG |
---|
| 105 | return (FALSE); |
---|
| 106 | } |
---|
| 107 | return (TRUE); |
---|
| 108 | } |
---|
| 109 | // ________________________________________________________________________________________________________ |
---|
| 110 | // |
---|
| 111 | // Función: diadelaSemana |
---|
| 112 | // |
---|
| 113 | // Descripción: |
---|
| 114 | // Calcula el número del día de la semana que corresponde a una fecha |
---|
| 115 | // Parámetros: |
---|
| 116 | // - dia: Un día |
---|
| 117 | // - mes: Un mes |
---|
| 118 | // - anno: Un año |
---|
| 119 | // Devuelve: |
---|
| 120 | // El número del día de la semana: 1=Lunes, 2=martes ... 6=sábado 7=domingo |
---|
| 121 | // ________________________________________________________________________________________________________ |
---|
| 122 | |
---|
| 123 | int diadelaSemana(WORD dia,WORD mes,WORD anno) |
---|
| 124 | { |
---|
| 125 | int i,cont,dias_anuales; |
---|
| 126 | int desplazamiento_dias=6; |
---|
| 127 | int orddiasem; |
---|
| 128 | |
---|
| 129 | cont =0; |
---|
| 130 | for (i=1900;i<anno;i++){ |
---|
| 131 | if (bisiesto(i)) dias_anuales=366; else dias_anuales=365; |
---|
| 132 | cont+=dias_anuales; |
---|
| 133 | } |
---|
| 134 | for (i=1;i<mes;i++){ |
---|
| 135 | if (i!=2) |
---|
| 136 | cont+=dias_meses[i]; |
---|
| 137 | else{ |
---|
| 138 | if (bisiesto(anno)) |
---|
| 139 | cont+=29; |
---|
| 140 | else |
---|
| 141 | cont+=28; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | cont+=dia+desplazamiento_dias; |
---|
| 145 | orddiasem=(cont%7); |
---|
| 146 | if(orddiasem==0) orddiasem=7; |
---|
| 147 | return(orddiasem); |
---|
| 148 | } |
---|
| 149 | // ________________________________________________________________________________________________________ |
---|
| 150 | // |
---|
| 151 | // Función: bisiesto |
---|
| 152 | // |
---|
| 153 | // Descripción: |
---|
| 154 | // Calcula si un año es bisiesto o no lo es |
---|
| 155 | // Parámetros: |
---|
| 156 | // - anno: Un año |
---|
| 157 | // Devuelve: |
---|
| 158 | // TRUE si el año es bisiesto |
---|
| 159 | // FALSE si no es bisiesto |
---|
| 160 | // ________________________________________________________________________________________________________ |
---|
| 161 | |
---|
| 162 | BOOLEAN bisiesto(WORD anno){ |
---|
| 163 | return(anno%4==0); |
---|
| 164 | } |
---|
| 165 | // ________________________________________________________________________________________________________ |
---|
| 166 | // |
---|
| 167 | // Función: semanadelMes |
---|
| 168 | // |
---|
| 169 | // Descripción: |
---|
| 170 | // Calcula el número de semana perteneciente a un día del mes |
---|
| 171 | // Parámetros: |
---|
| 172 | // - ordiasem_1: Orden semanal (1,2...) del primer dia del mes que se pasa como parámetro |
---|
| 173 | // - diames: El mes concreto |
---|
| 174 | // Devuelve: |
---|
| 175 | // El número del día de la semana: 1=Lunes, 2=martes ... 6=sábado 7=domingo , de ese mes |
---|
| 176 | // ________________________________________________________________________________________________________ |
---|
| 177 | |
---|
| 178 | int semanadelMes(int ordiasem_1,int diames) |
---|
| 179 | { |
---|
| 180 | int nwdia,resto,cociente; |
---|
| 181 | |
---|
| 182 | nwdia=diames+ordiasem_1-1; |
---|
| 183 | cociente=nwdia/7; |
---|
| 184 | resto=nwdia%7; |
---|
| 185 | if(resto>0) cociente++; |
---|
| 186 | return(cociente); |
---|
| 187 | } |
---|
| 188 | // ________________________________________________________________________________________________________ |
---|
| 189 | // |
---|
| 190 | // Función: buscaAccion |
---|
| 191 | // |
---|
| 192 | // Descripción: |
---|
| 193 | // Busca en la base de datos, acciones programadas |
---|
| 194 | // Parámetros: |
---|
| 195 | // - db: Objeto base de datos (operativo) |
---|
| 196 | // - dia : Día actual del mes |
---|
| 197 | // - mes : mes en curso |
---|
| 198 | // - anno : Año en curso |
---|
| 199 | // - hora : Hora actual |
---|
| 200 | // - minutos : Minutos actuales |
---|
| 201 | // - diasemana : Dia de la semana 1=lunes,2=martes ... ( 0 Domingo) |
---|
| 202 | // Devuelve: |
---|
| 203 | // TRUE: Si el proceso es correcto |
---|
| 204 | // FALSE: En caso de ocurrir algún error |
---|
| 205 | // ________________________________________________________________________________________________________ |
---|
| 206 | |
---|
| 207 | BOOLEAN buscaAccion(Database db,WORD dia,WORD mes,WORD anno,WORD hora,WORD minutos,WORD diasemana) |
---|
| 208 | { |
---|
| 209 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 210 | Table tbl; |
---|
| 211 | BYTE swampm,bitsemana; |
---|
| 212 | int ordsem,ordulsem,ordiasem_1,maxdias; |
---|
| 213 | int sesionprog; |
---|
| 214 | char modulo[] = "buscaAccion()"; |
---|
| 215 | |
---|
| 216 | /* Año de comienzo */ |
---|
| 217 | anno=anno-ANNOREF; // |
---|
| 218 | /* Preparación hora */ |
---|
| 219 | if(hora>11){ |
---|
| 220 | hora-=12; |
---|
| 221 | swampm=1; // Es P.M. |
---|
| 222 | } |
---|
| 223 | else |
---|
| 224 | swampm=0; // Es am |
---|
| 225 | /* Preparación semana */ |
---|
| 226 | if(diasemana==0) diasemana=7; // El domingo |
---|
| 227 | |
---|
| 228 | // Cuestión semanas |
---|
| 229 | ordiasem_1=diadelaSemana(1,mes,anno+2009); |
---|
| 230 | ordsem=semanadelMes(ordiasem_1,dia); // Calcula el número de la semana |
---|
| 231 | if (mes!=2) // Toma el último día de ese mes |
---|
| 232 | maxdias=dias_meses[mes]; |
---|
| 233 | else{ |
---|
| 234 | if (bisiesto(anno+ANNOREF)) |
---|
| 235 | maxdias=29; |
---|
| 236 | else |
---|
| 237 | maxdias=28; |
---|
| 238 | } |
---|
| 239 | ordulsem=semanadelMes(ordiasem_1,maxdias); // Calcula el número de la última semana |
---|
| 240 | bitsemana=HEX_semanas[ordsem]; |
---|
| 241 | if(ordsem==ordulsem) // Si es la última semana del mes |
---|
| 242 | bitsemana|=HEX_semanas[6]; |
---|
| 243 | |
---|
| 244 | sprintf(sqlstr,"SELECT DISTINCT idprogramacion,tipoaccion,identificador,sesion,idcentro,"\ |
---|
| 245 | "tareas.descripcion as descritarea"\ |
---|
| 246 | " FROM programaciones"\ |
---|
| 247 | " LEFT OUTER JOIN tareas ON tareas.idtarea=programaciones.identificador"\ |
---|
| 248 | " WHERE suspendida=0 "\ |
---|
| 249 | " AND (annos & %d <> 0) "\ |
---|
| 250 | " AND (meses & %d<>0) "\ |
---|
| 251 | " AND ((diario & %d<>0) OR (dias & %d<>0) OR (semanas & %d<>0))"\ |
---|
| 252 | " AND (horas & %d<>0) AND ampm=%d AND minutos=%d",\ |
---|
| 253 | HEX_annos[anno],\ |
---|
| 254 | HEX_meses[mes],\ |
---|
| 255 | HEX_dias[dia],\ |
---|
| 256 | HEX_diasemana[diasemana],\ |
---|
| 257 | bitsemana,\ |
---|
| 258 | HEX_horas[hora],\ |
---|
| 259 | swampm,minutos); |
---|
| 260 | |
---|
| 261 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 262 | errorLog(modulo, 21, FALSE); |
---|
| 263 | db.GetErrorErrStr(msglog); |
---|
| 264 | errorInfo(modulo, msglog); |
---|
| 265 | return (FALSE); |
---|
| 266 | } |
---|
| 267 | if(tbl.ISEOF()){ |
---|
| 268 | return(TRUE); // No hay acciones programadas |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | while(!tbl.ISEOF()){ |
---|
| 272 | if(!tbl.Get("idprogramacion",idprogramacion)){ |
---|
| 273 | tbl.GetErrorErrStr(msglog); |
---|
| 274 | errorInfo(modulo, msglog); |
---|
| 275 | return (FALSE); |
---|
| 276 | } |
---|
| 277 | if(!tbl.Get("tipoaccion",tipoaccion)){ |
---|
| 278 | tbl.GetErrorErrStr(msglog); |
---|
| 279 | errorInfo(modulo, msglog); |
---|
| 280 | return (FALSE); |
---|
| 281 | } |
---|
| 282 | if(!tbl.Get("identificador",idtipoaccion)){ |
---|
| 283 | tbl.GetErrorErrStr(msglog); |
---|
| 284 | errorInfo(modulo, msglog); |
---|
| 285 | return (FALSE); |
---|
| 286 | } |
---|
| 287 | if(!tbl.Get("sesion",sesionprog)){ |
---|
| 288 | tbl.GetErrorErrStr(msglog); |
---|
| 289 | errorInfo(modulo, msglog); |
---|
| 290 | return (FALSE); |
---|
| 291 | } |
---|
| 292 | if(!tbl.Get("idcentro",idcentro)){ |
---|
| 293 | tbl.GetErrorErrStr(msglog); |
---|
| 294 | errorInfo(modulo, msglog); |
---|
| 295 | return (FALSE); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | if(tipoaccion==EJECUCION_COMANDO){ // Es una programación de un comando |
---|
| 299 | return(ejecutarComando(db,idprogramacion,sesionprog)); |
---|
| 300 | } |
---|
| 301 | else{ |
---|
| 302 | |
---|
| 303 | if(tipoaccion==EJECUCION_TAREA){ |
---|
| 304 | if(!tbl.Get("descritarea",descriaccion)){ |
---|
| 305 | tbl.GetErrorErrStr(msglog); |
---|
| 306 | errorInfo(modulo, msglog); |
---|
| 307 | return (FALSE); |
---|
| 308 | } |
---|
| 309 | return(ejecutarTarea(db,idprogramacion,idtipoaccion)); |
---|
| 310 | } |
---|
| 311 | else{ |
---|
| 312 | if(tipoaccion==EJECUCION_RESERVA){ |
---|
| 313 | EjecutarReserva(idtipoaccion,db); // Es una programación de un trabajo |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | tbl.MoveNext(); |
---|
| 318 | } |
---|
| 319 | return(TRUE); |
---|
| 320 | } |
---|
| 321 | // ________________________________________________________________________________________________________ |
---|
| 322 | // |
---|
| 323 | // Función: ejecutarComando |
---|
| 324 | // |
---|
| 325 | // Descripción: |
---|
| 326 | // Ejecuta un comando programado |
---|
| 327 | // Parámetros: |
---|
| 328 | // - db: Objeto base de datos (operativo) |
---|
| 329 | // - idcomando: Identificador del comando |
---|
| 330 | // - sesion: Sesión correspondiente al comando cuando se grabó en la tabla acciones |
---|
| 331 | // Devuelve: |
---|
| 332 | // TRUE: Si el proceso es correcto |
---|
| 333 | // FALSE: En caso de ocurrir algún error |
---|
| 334 | // ________________________________________________________________________________________________________ |
---|
| 335 | |
---|
| 336 | BOOLEAN ejecutarComando(Database db,int idprogramacion,int sesion ) |
---|
| 337 | { |
---|
| 338 | struct tm* st; |
---|
| 339 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 340 | char fechahorareg[24]; |
---|
| 341 | char modulo[] = "ejecutarComando()"; |
---|
| 342 | |
---|
| 343 | st = tomaHora(); |
---|
| 344 | sprintf(fechahorareg,"%d/%d/%d %d:%d:%d", st->tm_year + 1900, st->tm_mon + 1, |
---|
| 345 | st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec); |
---|
| 346 | |
---|
| 347 | sprintf(sqlstr,"UPDATE acciones SET estado=%d,idprogramacion=%d,fechahorareg='%s'"\ |
---|
| 348 | " WHERE sesion=%d", ACCION_INICIADA,idprogramacion,fechahorareg,sesion); |
---|
| 349 | |
---|
| 350 | if (!db.Execute(sqlstr)) { // Error al recuperar los datos |
---|
| 351 | errorLog(modulo, 21, FALSE); |
---|
| 352 | db.GetErrorErrStr(msglog); |
---|
| 353 | errorInfo(modulo, msglog); |
---|
| 354 | return (FALSE); |
---|
| 355 | } |
---|
| 356 | return(enviaPeticion(idprogramacion)); |
---|
| 357 | } |
---|
| 358 | // ________________________________________________________________________________________________________ |
---|
| 359 | // |
---|
| 360 | // Función: ejecutarProcedimiento |
---|
| 361 | // |
---|
| 362 | // Descripción: |
---|
| 363 | // Ejecuta un procedimiento programado |
---|
| 364 | // Parámetros: |
---|
| 365 | // - db: Objeto base de datos (operativo) |
---|
| 366 | // - idprocedimiento: Identificador del procedimiento |
---|
| 367 | // - ambito: Ámbito de aplicación |
---|
| 368 | // - idambito: Identificador del ámbito |
---|
| 369 | // - restrambito: cadena con los identificadores de los ordenadores a los que se aplica la acción |
---|
| 370 | // Devuelve: |
---|
| 371 | // TRUE: Si el proceso es correcto |
---|
| 372 | // FALSE: En caso de ocurrir algún error |
---|
| 373 | // ________________________________________________________________________________________________________ |
---|
| 374 | |
---|
| 375 | BOOLEAN ejecutarProcedimiento(Database db,int idprocedimiento,int ambito,int idambito,char* restrambito) |
---|
| 376 | { |
---|
| 377 | char msglog[LONSTD], sqlstr[LONSQL],*parametros; |
---|
| 378 | Table tbl; |
---|
| 379 | int procedimientoid,idcomando,lonprm; |
---|
| 380 | char modulo[] = "ejecutarProcedimiento()"; |
---|
| 381 | |
---|
| 382 | sprintf(sqlstr,"SELECT idcomando,procedimientoid,parametros,length(parametros) as lonprm"\ |
---|
| 383 | " FROM procedimientos_acciones"\ |
---|
| 384 | " WHERE idprocedimiento=%d ORDER BY orden",idprocedimiento); |
---|
| 385 | |
---|
| 386 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 387 | errorLog(modulo, 21, FALSE); |
---|
| 388 | db.GetErrorErrStr(msglog); |
---|
| 389 | errorInfo(modulo, msglog); |
---|
| 390 | return (FALSE); |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | if(tbl.ISEOF()){ |
---|
| 394 | return(TRUE); // No exustde tarea |
---|
| 395 | } |
---|
| 396 | while(!tbl.ISEOF()){ |
---|
| 397 | if(!tbl.Get("procedimientoid",procedimientoid)){ |
---|
| 398 | tbl.GetErrorErrStr(msglog); |
---|
| 399 | errorInfo(modulo, msglog); |
---|
| 400 | return (FALSE); |
---|
| 401 | } |
---|
| 402 | if(procedimientoid>0){ // Procedimiento recursivo |
---|
| 403 | if(!ejecutarProcedimiento(db,procedimientoid,ambito,idambito,restrambito)){ |
---|
| 404 | return(false); |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | else{ |
---|
| 408 | if(!tbl.Get("lonprm",lonprm)){ |
---|
| 409 | tbl.GetErrorErrStr(msglog); |
---|
| 410 | errorInfo(modulo, msglog); |
---|
| 411 | return (FALSE); |
---|
| 412 | } |
---|
| 413 | parametros = reservaMemoria(lonprm+1); // Reserva para almacenar los parametros del procedimiento |
---|
| 414 | if (parametros == NULL) { |
---|
| 415 | errorLog(modulo, 3, FALSE); |
---|
| 416 | return (FALSE); |
---|
| 417 | } |
---|
| 418 | if(!tbl.Get("parametros",parametros)){ |
---|
| 419 | tbl.GetErrorErrStr(msglog); |
---|
| 420 | errorInfo(modulo, msglog); |
---|
| 421 | liberaMemoria(parametros); |
---|
| 422 | return (FALSE); |
---|
| 423 | } |
---|
| 424 | if(!tbl.Get("idcomando",idcomando)){ |
---|
| 425 | tbl.GetErrorErrStr(msglog); |
---|
| 426 | errorInfo(modulo, msglog); |
---|
| 427 | return (FALSE); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | if(!insertaComando(db,idcomando,parametros,idprocedimiento,ambito,idambito,restrambito)) { |
---|
| 431 | |
---|
| 432 | liberaMemoria(parametros); |
---|
| 433 | return(false); |
---|
| 434 | } |
---|
| 435 | liberaMemoria(parametros); |
---|
| 436 | } |
---|
| 437 | tbl.MoveNext(); |
---|
| 438 | } |
---|
| 439 | return(TRUE); |
---|
| 440 | } |
---|
| 441 | // ________________________________________________________________________________________________________ |
---|
| 442 | // |
---|
| 443 | // Función: ejecutarTarea |
---|
| 444 | // |
---|
| 445 | // Descripción: |
---|
| 446 | // Ejecuta una tarea programada |
---|
| 447 | // Parámetros: |
---|
| 448 | // - db: Objeto base de datos (operativo) |
---|
| 449 | // - idtarea: Identificador de la tarea |
---|
| 450 | // - idprogramacion: Identificador de la programación |
---|
| 451 | // Devuelve: |
---|
| 452 | // TRUE: Si el proceso es correcto |
---|
| 453 | // FALSE: En caso de ocurrir algún error |
---|
| 454 | // ________________________________________________________________________________________________________ |
---|
| 455 | |
---|
| 456 | BOOLEAN ejecutarTarea(Database db, int idprogramacion, int idtarea) |
---|
| 457 | { |
---|
| 458 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 459 | Table tbl; |
---|
| 460 | int tareaid,ambito,idambito,idprocedimiento,lonrestrambito; |
---|
| 461 | char* restrambito; |
---|
| 462 | char modulo[] = "ejecutarTarea()"; |
---|
| 463 | |
---|
| 464 | sprintf(sqlstr,"SELECT tareas_acciones.orden,tareas_acciones.idprocedimiento,tareas_acciones.tareaid,"\ |
---|
| 465 | " tareas.ambito,tareas.idambito,tareas.restrambito,length(tareas.restrambito) as lonrestrambito"\ |
---|
| 466 | " FROM tareas"\ |
---|
| 467 | " INNER JOIN tareas_acciones ON tareas_acciones.idtarea=tareas.idtarea"\ |
---|
| 468 | " WHERE tareas_acciones.idtarea=%d ORDER BY tareas_acciones.orden",idtarea); |
---|
| 469 | |
---|
| 470 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 471 | errorLog(modulo, 21, FALSE); |
---|
| 472 | db.GetErrorErrStr(msglog); |
---|
| 473 | errorInfo(modulo, msglog); |
---|
| 474 | return (FALSE); |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | if(tbl.ISEOF()){ |
---|
| 478 | return(TRUE); // No existe tarea |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | while(!tbl.ISEOF()){ |
---|
| 482 | if(!tbl.Get("tareaid",tareaid)){ |
---|
| 483 | tbl.GetErrorErrStr(msglog); |
---|
| 484 | errorInfo(modulo, msglog); |
---|
| 485 | return (FALSE); |
---|
| 486 | } |
---|
| 487 | if(tareaid>0){ // Tarea recursiva |
---|
| 488 | if(!ejecutarTarea(db,idprogramacion,tareaid)){ |
---|
| 489 | return(false); |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | else{ |
---|
| 493 | if(!tbl.Get("ambito",ambito)){ |
---|
| 494 | tbl.GetErrorErrStr(msglog); |
---|
| 495 | errorInfo(modulo, msglog); |
---|
| 496 | return (FALSE); |
---|
| 497 | } |
---|
| 498 | if(!tbl.Get("idambito",idambito)){ |
---|
| 499 | tbl.GetErrorErrStr(msglog); |
---|
| 500 | errorInfo(modulo, msglog); |
---|
| 501 | return (FALSE); |
---|
| 502 | } |
---|
| 503 | if(!tbl.Get("lonrestrambito",lonrestrambito)){ |
---|
| 504 | tbl.GetErrorErrStr(msglog); |
---|
| 505 | errorInfo(modulo, msglog); |
---|
| 506 | return (FALSE); |
---|
| 507 | } |
---|
| 508 | restrambito = reservaMemoria(lonrestrambito+1); |
---|
| 509 | if (restrambito == NULL) { |
---|
| 510 | errorLog(modulo, 3, FALSE); |
---|
| 511 | return (FALSE); |
---|
| 512 | } |
---|
| 513 | if(!tbl.Get("restrambito",restrambito)){ |
---|
| 514 | tbl.GetErrorErrStr(msglog); |
---|
| 515 | errorInfo(modulo, msglog); |
---|
| 516 | liberaMemoria(restrambito); |
---|
| 517 | return (FALSE); |
---|
| 518 | } |
---|
| 519 | liberaMemoria(restrambito); |
---|
| 520 | RecopilaIpesMacs(db,ambito,idambito,restrambito); // Recopila Ipes del ámbito |
---|
| 521 | if(!tbl.Get("idprocedimiento",idprocedimiento)){ |
---|
| 522 | tbl.GetErrorErrStr(msglog); |
---|
| 523 | errorInfo(modulo, msglog); |
---|
| 524 | return (FALSE); |
---|
| 525 | } |
---|
| 526 | sesion=time(NULL); |
---|
| 527 | |
---|
| 528 | if(!ejecutarProcedimiento(db,idprocedimiento,ambito,idambito,restrambito)) |
---|
| 529 | return(FALSE); |
---|
| 530 | } |
---|
| 531 | tbl.MoveNext(); |
---|
| 532 | } |
---|
| 533 | return(enviaPeticion(idprogramacion)); |
---|
| 534 | } |
---|
| 535 | // ________________________________________________________________________________________________________ |
---|
| 536 | // |
---|
| 537 | // Función: ejecutarTarea |
---|
| 538 | // |
---|
| 539 | // Descripción: |
---|
| 540 | // Registra un procedimiento para un ambito concreto |
---|
| 541 | // Parámetros: |
---|
| 542 | // - db: Objeto base de datos (operativo) |
---|
| 543 | // - idcomando: Identificador del comando |
---|
| 544 | // - idprocedimiento: Identificador del procedimiento |
---|
| 545 | // - ambito: Ámbito de aplicación |
---|
| 546 | // - idambito: Identificador del ámbito |
---|
| 547 | // - restrambito: cadena con los identificadores de los ordenadores a los que se aplica la acción |
---|
| 548 | // Devuelve: |
---|
| 549 | // TRUE: Si el proceso es correcto |
---|
| 550 | // FALSE: En caso de ocurrir algún error |
---|
| 551 | //________________________________________________________________________________________________________ |
---|
| 552 | BOOLEAN insertaComando(Database db,int idcomando,char*parametros,int idprocedimiento,int ambito,int idambito,char*restrambito) |
---|
| 553 | { |
---|
| 554 | char msglog[LONSTD], sqlstr[LONSQL]; |
---|
| 555 | struct tm* st; |
---|
| 556 | char *auxID[MAXIMOS_CLIENTES],*auxIP[MAXIMOS_CLIENTES]; |
---|
| 557 | char fechahorareg[24]; |
---|
| 558 | int i; |
---|
| 559 | char modulo[] = "insertaComando()"; |
---|
| 560 | |
---|
| 561 | if(concli==0) return(TRUE); // No hay ordenadores en el ámbito |
---|
| 562 | |
---|
| 563 | st = tomaHora(); |
---|
| 564 | sprintf(fechahorareg,"%d/%d/%d %d:%d:%d", st->tm_year + 1900, st->tm_mon + 1, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec); |
---|
| 565 | |
---|
| 566 | splitCadena(auxID,cadenaid,','); |
---|
| 567 | splitCadena(auxIP,cadenaip,';'); |
---|
| 568 | |
---|
| 569 | for (i=0;i<concli;i++){ |
---|
| 570 | sprintf(sqlstr,"INSERT INTO acciones (idordenador,tipoaccion,idtipoaccion,descriaccion,ip,"\ |
---|
| 571 | "sesion,idcomando,parametros,fechahorareg,estado,resultado,ambito,idambito,"\ |
---|
| 572 | "restrambito,idprocedimiento,idcentro,idprogramacion)"\ |
---|
| 573 | " VALUES (%s,%d,%d,'%s','%s',%d,%d,'%s','%s',%d,%d,%d,%d,'%s',%d,%d,%d)",\ |
---|
| 574 | auxID[i],tipoaccion,idtipoaccion,descriaccion,auxIP[i],sesion,idcomando,parametros,fechahorareg,\ |
---|
| 575 | ACCION_INICIADA,ACCION_SINRESULTADO,ambito,idambito,restrambito,idprocedimiento,idcentro,idprogramacion); |
---|
| 576 | if (!db.Execute(sqlstr)) { // Error al recuperar los datos |
---|
| 577 | errorLog(modulo, 21, FALSE); |
---|
| 578 | db.GetErrorErrStr(msglog); |
---|
| 579 | errorInfo(modulo, msglog); |
---|
| 580 | return (FALSE); |
---|
| 581 | } |
---|
| 582 | } |
---|
| 583 | return(TRUE); |
---|
| 584 | } |
---|
| 585 | // _____________________________________________________________________________________________________________ |
---|
| 586 | // Función: EjecutarReserva |
---|
| 587 | // |
---|
| 588 | // Descripción: |
---|
| 589 | // Registra una acción (Tarea) y la envía para su ejecución |
---|
| 590 | // Parámetros: |
---|
| 591 | // - idreserva : Identificador de la reserva |
---|
| 592 | // - db: una conexion ADO operativa |
---|
| 593 | // - parametros: Parámetros de la acción |
---|
| 594 | // _____________________________________________________________________________________________________________ |
---|
| 595 | BOOLEAN EjecutarReserva(int idreserva,Database db ) |
---|
| 596 | { |
---|
| 597 | |
---|
| 598 | |
---|
| 599 | return(true); |
---|
| 600 | } |
---|
| 601 | // _____________________________________________________________________________________________________________ |
---|
| 602 | // Función: enviaPeticion |
---|
| 603 | // |
---|
| 604 | // Descripción: |
---|
| 605 | // Hace una petición al servidor para que actualice los ordenadores implicados en la programación |
---|
| 606 | // Parámetros: |
---|
| 607 | // - idprogramacion: Identificador de la programación |
---|
| 608 | // _____________________________________________________________________________________________________________ |
---|
| 609 | BOOLEAN enviaPeticion(int idprogramacion) |
---|
| 610 | { |
---|
| 611 | int lon; |
---|
| 612 | TRAMA *ptrTrama; |
---|
| 613 | SOCKET socket_c; |
---|
| 614 | char modulo[] = "enviaPeticion()"; |
---|
| 615 | |
---|
| 616 | /* Envio de comandos a clientes */ |
---|
| 617 | ptrTrama=(TRAMA *)reservaMemoria(sizeof(TRAMA)); |
---|
| 618 | if (ptrTrama == NULL) { // No hay memoria suficiente para el bufer de las tramas |
---|
| 619 | errorLog(modulo, 3, FALSE); |
---|
| 620 | return(FALSE); |
---|
| 621 | } |
---|
| 622 | initParametros(ptrTrama,0); |
---|
| 623 | lon=sprintf(ptrTrama->parametros,"nfn=envioProgramacion\r"); // Nombre de la función a ejecutar en el servidor |
---|
| 624 | lon+=sprintf(ptrTrama->parametros+lon,"idp=%d\r",idprogramacion); // Configuración de los Sistemas Operativos del cliente |
---|
| 625 | |
---|
| 626 | if(!enviaMensaje(&socket_c,ptrTrama,MSG_PETICION)){ |
---|
| 627 | errorLog(modulo,91,FALSE); |
---|
| 628 | liberaMemoria(ptrTrama); |
---|
| 629 | return(FALSE); |
---|
| 630 | } |
---|
| 631 | liberaMemoria(ptrTrama); |
---|
| 632 | return(TRUE); |
---|
| 633 | } |
---|
| 634 | // _____________________________________________________________________________________________________________ |
---|
| 635 | // |
---|
| 636 | // Función: RecopilaIpesMacs |
---|
| 637 | // |
---|
| 638 | // Descripción : |
---|
| 639 | // Recopila las IPes, las Macs y los identificadores de ordenadores de un ámbito determinado |
---|
| 640 | // |
---|
| 641 | // Especificaciones: |
---|
| 642 | // Esta Función recibe tres parámatros: |
---|
| 643 | // db : Un objeto Base de datos totalmente operativo |
---|
| 644 | // ambito: Tipo de ámbito |
---|
| 645 | // idambito: Identificador del ámbito |
---|
| 646 | // Devuelve: |
---|
| 647 | // Todas los identificadores de ordenadores , las ipes y las macs de los ordenadores que componen el ámbito |
---|
| 648 | // Para ellos habrá que tener declarada tres variables globales : |
---|
| 649 | // cadenaid,cadenaip y cadenamac |
---|
| 650 | // _____________________________________________________________________________________________________________ |
---|
| 651 | |
---|
| 652 | BOOLEAN RecopilaIpesMacs(Database db,int ambito,int idambito,char *restrambito) |
---|
| 653 | { |
---|
| 654 | char sqlstr[LONSQL]; |
---|
| 655 | |
---|
| 656 | concli=0; |
---|
| 657 | /* Reserva memoria al meno para caracter nulo */ |
---|
| 658 | cadenaid=(char*) reservaMemoria(1); |
---|
| 659 | cadenaip=(char*) reservaMemoria(1); |
---|
| 660 | cadenamac=(char*) reservaMemoria(1); |
---|
| 661 | |
---|
| 662 | switch(ambito){ |
---|
| 663 | case AMBITO_CENTROS : |
---|
| 664 | sprintf(sqlstr,"SELECT idcentro FROM centros WHERE idcentro=%d",idambito); |
---|
| 665 | RecorreCentro(db,sqlstr); |
---|
| 666 | break; |
---|
| 667 | case AMBITO_GRUPOSAULAS : |
---|
| 668 | sprintf(sqlstr,"SELECT idgrupo FROM grupos WHERE idgrupo=%d AND tipo=%d",idambito,AMBITO_GRUPOSAULAS); |
---|
| 669 | RecorreGruposAulas(db,sqlstr); |
---|
| 670 | break; |
---|
| 671 | case AMBITO_AULAS : |
---|
| 672 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE idaula=%d",idambito); |
---|
| 673 | RecorreAulas(db,sqlstr); |
---|
| 674 | break; |
---|
| 675 | case AMBITO_GRUPOSORDENADORES : |
---|
| 676 | sprintf(sqlstr,"SELECT idgrupo FROM gruposordenadores WHERE idgrupo=%d",idambito); |
---|
| 677 | RecorreGruposOrdenadores(db,sqlstr); |
---|
| 678 | break; |
---|
| 679 | case AMBITO_ORDENADORES : |
---|
| 680 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE idordenador=%d",idambito); |
---|
| 681 | RecorreOrdenadores(db,sqlstr); |
---|
| 682 | break; |
---|
| 683 | default: // Se trata de un conjunto aleatorio de ordenadores |
---|
| 684 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE idordenador IN (%s)",restrambito); |
---|
| 685 | RecorreOrdenadores(db,sqlstr); |
---|
| 686 | |
---|
| 687 | } |
---|
| 688 | return (TRUE); |
---|
| 689 | } |
---|
| 690 | //________________________________________________________________________________________________________ |
---|
| 691 | |
---|
| 692 | BOOLEAN RecorreCentro(Database db, char* sqlstr) |
---|
| 693 | { |
---|
| 694 | char msglog[LONSTD]; |
---|
| 695 | Table tbl; |
---|
| 696 | int idcentro; |
---|
| 697 | char modulo[] = "RecorreCentro()"; |
---|
| 698 | |
---|
| 699 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 700 | errorLog(modulo, 21, FALSE); |
---|
| 701 | db.GetErrorErrStr(msglog); |
---|
| 702 | errorInfo(modulo, msglog); |
---|
| 703 | return (FALSE); |
---|
| 704 | } |
---|
| 705 | if(!tbl.ISEOF()){ |
---|
| 706 | if(!tbl.Get("idcentro",idcentro)){ |
---|
| 707 | tbl.GetErrorErrStr(msglog); |
---|
| 708 | errorInfo(modulo, msglog); |
---|
| 709 | return (FALSE); |
---|
| 710 | } |
---|
| 711 | sprintf(sqlstr,"SELECT idgrupo FROM grupos WHERE idcentro=%d AND grupoid=0 AND tipo=%d",idcentro,AMBITO_GRUPOSAULAS); |
---|
| 712 | RecorreGruposAulas(db,sqlstr); |
---|
| 713 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE idcentro=%d AND grupoid=0",idcentro); |
---|
| 714 | RecorreAulas(db,sqlstr); |
---|
| 715 | } |
---|
| 716 | return (TRUE); |
---|
| 717 | } |
---|
| 718 | //________________________________________________________________________________________________________ |
---|
| 719 | |
---|
| 720 | BOOLEAN RecorreGruposAulas(Database db, char* sqlstr) |
---|
| 721 | { |
---|
| 722 | char msglog[LONSTD]; |
---|
| 723 | Table tbl; |
---|
| 724 | int idgrupo; |
---|
| 725 | char modulo[] = "RecorreGruposAulas()"; |
---|
| 726 | |
---|
| 727 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 728 | errorLog(modulo, 21, FALSE); |
---|
| 729 | db.GetErrorErrStr(msglog); |
---|
| 730 | errorInfo(modulo, msglog); |
---|
| 731 | return (FALSE); |
---|
| 732 | } |
---|
| 733 | while(!tbl.ISEOF()){ |
---|
| 734 | if(!tbl.Get("idgrupo",idgrupo)){ |
---|
| 735 | tbl.GetErrorErrStr(msglog); |
---|
| 736 | errorInfo(modulo, msglog); |
---|
| 737 | return (FALSE); |
---|
| 738 | } |
---|
| 739 | sprintf(sqlstr,"SELECT idgrupo FROM grupos WHERE grupoid=%d AND tipo=%d",idgrupo,AMBITO_GRUPOSAULAS); |
---|
| 740 | RecorreGruposAulas(db,sqlstr); |
---|
| 741 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE grupoid=%d",idgrupo); |
---|
| 742 | RecorreAulas(db,sqlstr); |
---|
| 743 | tbl.MoveNext(); |
---|
| 744 | } |
---|
| 745 | return (TRUE); |
---|
| 746 | } |
---|
| 747 | //________________________________________________________________________________________________________ |
---|
| 748 | |
---|
| 749 | BOOLEAN RecorreAulas(Database db, char* sqlstr) |
---|
| 750 | { |
---|
| 751 | char msglog[LONSTD]; |
---|
| 752 | Table tbl; |
---|
| 753 | int idaula; |
---|
| 754 | char modulo[] = "RecorreAulas()"; |
---|
| 755 | |
---|
| 756 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 757 | errorLog(modulo, 21, FALSE); |
---|
| 758 | db.GetErrorErrStr(msglog); |
---|
| 759 | errorInfo(modulo, msglog); |
---|
| 760 | return (FALSE); |
---|
| 761 | } |
---|
| 762 | while(!tbl.ISEOF()){ |
---|
| 763 | if(!tbl.Get("idaula",idaula)){ |
---|
| 764 | tbl.GetErrorErrStr(msglog); |
---|
| 765 | errorInfo(modulo, msglog); |
---|
| 766 | return (FALSE); |
---|
| 767 | } |
---|
| 768 | sprintf(sqlstr,"SELECT idgrupo FROM gruposordenadores WHERE idaula=%d AND grupoid=0",idaula); |
---|
| 769 | RecorreGruposOrdenadores(db,sqlstr); |
---|
| 770 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE idaula=%d AND grupoid=0",idaula); |
---|
| 771 | RecorreOrdenadores(db,sqlstr); |
---|
| 772 | tbl.MoveNext(); |
---|
| 773 | } |
---|
| 774 | return (TRUE); |
---|
| 775 | } |
---|
| 776 | //________________________________________________________________________________________________________ |
---|
| 777 | |
---|
| 778 | BOOLEAN RecorreGruposOrdenadores(Database db, char* sqlstr) |
---|
| 779 | { |
---|
| 780 | char msglog[LONSTD]; |
---|
| 781 | Table tbl; |
---|
| 782 | int idgrupo; |
---|
| 783 | char modulo[] = "RecorreGruposOrdenadores()"; |
---|
| 784 | |
---|
| 785 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 786 | errorLog(modulo, 21, FALSE); |
---|
| 787 | db.GetErrorErrStr(msglog); |
---|
| 788 | errorInfo(modulo, msglog); |
---|
| 789 | return (FALSE); |
---|
| 790 | } |
---|
| 791 | while(!tbl.ISEOF()){ |
---|
| 792 | if(!tbl.Get("idgrupo",idgrupo)){ |
---|
| 793 | tbl.GetErrorErrStr(msglog); |
---|
| 794 | errorInfo(modulo, msglog); |
---|
| 795 | return (FALSE); |
---|
| 796 | } |
---|
| 797 | sprintf(sqlstr,"SELECT idgrupo FROM gruposordenadores WHERE grupoid=%d",idgrupo); |
---|
| 798 | RecorreGruposOrdenadores(db,sqlstr); |
---|
| 799 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE grupoid=%d",idgrupo); |
---|
| 800 | RecorreOrdenadores(db,sqlstr); |
---|
| 801 | tbl.MoveNext(); |
---|
| 802 | } |
---|
| 803 | return (TRUE); |
---|
| 804 | } |
---|
| 805 | //________________________________________________________________________________________________________ |
---|
| 806 | |
---|
| 807 | BOOLEAN RecorreOrdenadores(Database db, char* sqlstr) |
---|
| 808 | { |
---|
| 809 | char msglog[LONSTD]; |
---|
| 810 | Table tbl; |
---|
| 811 | int idordenador,o,p,m,lon; |
---|
| 812 | char ido[16],ip[LONIP],mac[LONMAC]; |
---|
| 813 | char modulo[] = "RecorreOrdenadores()"; |
---|
| 814 | |
---|
| 815 | if (!db.Execute(sqlstr, tbl)) { // Error al leer |
---|
| 816 | errorLog(modulo, 21, FALSE); |
---|
| 817 | db.GetErrorErrStr(msglog); |
---|
| 818 | errorInfo(modulo, msglog); |
---|
| 819 | return (FALSE); |
---|
| 820 | } |
---|
| 821 | o=p=m=0; |
---|
| 822 | while(!tbl.ISEOF()){ |
---|
| 823 | if(!tbl.Get("idordenador",idordenador)){ |
---|
| 824 | tbl.GetErrorErrStr(msglog); |
---|
| 825 | errorInfo(modulo, msglog); |
---|
| 826 | return (FALSE); |
---|
| 827 | } |
---|
| 828 | if(!tbl.Get("ip",ip)){ |
---|
| 829 | tbl.GetErrorErrStr(msglog); |
---|
| 830 | errorInfo(modulo, msglog); |
---|
| 831 | return (FALSE); |
---|
| 832 | } |
---|
| 833 | if(!tbl.Get("mac",mac)){ |
---|
| 834 | tbl.GetErrorErrStr(msglog); |
---|
| 835 | errorInfo(modulo, msglog); |
---|
| 836 | return (FALSE); |
---|
| 837 | } |
---|
| 838 | sprintf(ido,"%d",idordenador); |
---|
| 839 | lon=strlen(ido); |
---|
| 840 | if(lon>16) lon=16; |
---|
| 841 | cadenaid=(char*) ampliaMemoria(cadenaid,o+lon+1); |
---|
| 842 | memcpy(&cadenaid[o],ido,lon); |
---|
| 843 | o+=lon; |
---|
| 844 | cadenaid[o++]=','; |
---|
| 845 | |
---|
| 846 | lon=strlen(ip); |
---|
| 847 | if(lon>16) lon=LONIP; |
---|
| 848 | cadenaip=(char*) ampliaMemoria(cadenaip,p+lon+1); |
---|
| 849 | memcpy(&cadenaip[p],ip,lon); |
---|
| 850 | p+=lon; |
---|
| 851 | cadenaip[p++]=';'; |
---|
| 852 | |
---|
| 853 | lon=strlen(mac); |
---|
| 854 | if(lon>16) lon=LONMAC; |
---|
| 855 | cadenamac=(char*) ampliaMemoria(cadenamac,m+lon+1); |
---|
| 856 | memcpy(&cadenamac[m],mac,lon); |
---|
| 857 | m+=lon; |
---|
| 858 | cadenamac[m++]=';'; |
---|
| 859 | |
---|
| 860 | concli++; |
---|
| 861 | tbl.MoveNext(); |
---|
| 862 | } |
---|
| 863 | if(o>0) o--; |
---|
| 864 | if(p>0) p--; |
---|
| 865 | if(m>0) m--; |
---|
| 866 | cadenaid[o]='\0'; |
---|
| 867 | cadenaip[p]='\0'; |
---|
| 868 | cadenamac[m]='\0'; |
---|
| 869 | |
---|
| 870 | return (TRUE); |
---|
| 871 | } |
---|
| 872 | // ******************************************************************************************************** |
---|
| 873 | // PROGRAMA PRINCIPAL (SERVICIO) |
---|
| 874 | // ******************************************************************************************************** |
---|
| 875 | int main(int argc, char *argv[]) |
---|
| 876 | { |
---|
| 877 | int pseg; |
---|
| 878 | char msglog[LONSTD]; |
---|
| 879 | struct tm* st; |
---|
| 880 | Database db; |
---|
| 881 | char modulo[] = "main()"; |
---|
| 882 | |
---|
| 883 | /* Validación de parámetros de ejecución y lectura del fichero de configuración del servicio */ |
---|
| 884 | |
---|
| 885 | if (!validacionParametros(argc, argv, 5)) // Valida parámetros de ejecución |
---|
| 886 | exit(EXIT_FAILURE); |
---|
| 887 | |
---|
| 888 | if (!tomaConfiguracion(szPathFileCfg)) { // Toma parametros de configuracion |
---|
| 889 | exit(EXIT_FAILURE); |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | /* Bucle principal del servicio */ |
---|
| 893 | |
---|
| 894 | while (TRUE){ |
---|
| 895 | st = tomaHora(); |
---|
| 896 | pseg=65-st->tm_sec; // Calcula segundos de inactividad de la hebra |
---|
| 897 | sleep(pseg); |
---|
| 898 | |
---|
| 899 | // Toma la hora |
---|
| 900 | st = tomaHora(); |
---|
| 901 | |
---|
| 902 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion |
---|
| 903 | errorLog(modulo, 20, FALSE); |
---|
| 904 | db.GetErrorErrStr(msglog); |
---|
| 905 | errorInfo(modulo, msglog); |
---|
| 906 | exit(EXIT_FAILURE); |
---|
| 907 | } |
---|
| 908 | buscaAccion(db,st->tm_mday,st->tm_mon+1,st->tm_year+1900,st->tm_hour,st->tm_min,st->tm_wday ); |
---|
| 909 | db.Close(); // Cierra conexión |
---|
| 910 | } |
---|
| 911 | exit(EXIT_SUCCESS); |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | |
---|