File:  [local] / rpl / src / instructions_a5.c
Revision 1.11: download - view: text, annotated - select for diffs - revision graph
Wed Jul 14 14:19:35 2010 UTC (13 years, 9 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
En route vers la 4.0.18 !

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.0.18
    4:   Copyright (C) 1989-2010 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl.conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'alarm'
   29: ================================================================================
   30:   Entrées : pointeur sur une structure struct_processus
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_alarm(struct_processus *s_etat_processus)
   40: {
   41:     double                      duree;
   42: 
   43:     int                         code_retour;
   44:     int                         erreur;
   45: 
   46:     logical1                    specification_date;
   47: 
   48:     struct_liste_chainee        *l_element_courant;
   49: 
   50:     struct_objet                *s_objet_argument;
   51: 
   52:     struct timeb                st;
   53: 
   54:     struct timespec             attente;
   55: 
   56:     struct timeval              debut_interruption;
   57:     struct timeval              duree_interruption;
   58:     struct timeval              fin_interruption;
   59: 
   60:     struct tm                   *s_time_actuel;
   61:     struct tm                   s_time_alarme;
   62:     struct tm                   s_time_registre;
   63: 
   64:     time_t                      alarme;
   65: 
   66:     unsigned long               nombre_elements;
   67: 
   68:     (*s_etat_processus).erreur_execution = d_ex;
   69: 
   70:     if ((*s_etat_processus).affichage_arguments == 'Y')
   71:     {
   72:         printf("\n  ALARM ");
   73: 
   74:         if ((*s_etat_processus).langue == 'F')
   75:         {
   76:             printf("(suspension du processus jusqu'à un instant spécifié)\n\n");
   77:         }
   78:         else
   79:         {
   80:             printf("(wait until timestamp)\n\n");
   81:         }
   82: 
   83:         printf("    1: %s\n\n", d_LST);
   84: 
   85:         if ((*s_etat_processus).langue == 'F')
   86:         {
   87:             printf("  Utilisation :\n\n");
   88:         }
   89:         else
   90:         {
   91:             printf("  Usage:\n\n");
   92:         }
   93: 
   94:         printf("    { hours minutes } ALARM\n");
   95:         printf("    { hours minutes seconds } ALARM\n");
   96:         printf("    { hours minutes seconds day } ALARM\n");
   97:         printf("    { hours minutes seconds day month } ALARM\n");
   98:         printf("    { hours minutes seconds day month year } ALARM\n");
   99: 
  100:         return;
  101:     }
  102:     else if ((*s_etat_processus).test_instruction == 'Y')
  103:     {
  104:         (*s_etat_processus).nombre_arguments = 1;
  105:         return;
  106:     }
  107: 
  108:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  109:     {
  110:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  111:         {
  112:             return;
  113:         }
  114:     }
  115: 
  116:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  117:             &s_objet_argument) == d_erreur)
  118:     {
  119:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  120:         return;
  121:     }
  122: 
  123:     if ((*s_objet_argument).type == LST)
  124:     {
  125:         l_element_courant = (*s_objet_argument).objet;
  126:         nombre_elements = 0;
  127: 
  128:         while(l_element_courant != NULL)
  129:         {
  130:             if ((*(*l_element_courant).donnee).type != INT)
  131:             {
  132:                 (*s_etat_processus).erreur_execution =
  133:                         d_ex_erreur_type_argument;
  134: 
  135:                 liberation(s_etat_processus, s_objet_argument);
  136:                 return;
  137:             }
  138: 
  139:             l_element_courant = (*l_element_courant).suivant;
  140:             nombre_elements++;
  141:         }
  142: 
  143:         if ((nombre_elements < 2) || (nombre_elements > 6))
  144:         {
  145:             (*s_etat_processus).erreur_execution =
  146:                     d_ex_argument_invalide;
  147: 
  148:             liberation(s_etat_processus, s_objet_argument);
  149:             return;
  150:         }
  151: 
  152:         st.time = time(NULL);
  153:         s_time_actuel = localtime(&(st.time));
  154: 
  155:         l_element_courant = (*s_objet_argument).objet;
  156:         s_time_alarme.tm_hour = (*((integer8 *) (*(*l_element_courant)
  157:                 .donnee).objet));
  158:         l_element_courant = (*l_element_courant).suivant;
  159:         s_time_alarme.tm_min = (*((integer8 *) (*(*l_element_courant)
  160:                 .donnee).objet));
  161:         l_element_courant = (*l_element_courant).suivant;
  162: 
  163:         specification_date = d_faux;
  164: 
  165:         if (l_element_courant != NULL)
  166:         {
  167:             s_time_alarme.tm_sec = (*((integer8 *) (*(*l_element_courant)
  168:                     .donnee).objet));
  169:             l_element_courant = (*l_element_courant).suivant;
  170: 
  171:             if (l_element_courant != NULL)
  172:             {
  173:                 specification_date = d_vrai;
  174: 
  175:                 s_time_alarme.tm_mday = (*((integer8 *) (*(*l_element_courant)
  176:                         .donnee).objet));
  177:                 l_element_courant = (*l_element_courant).suivant;
  178: 
  179:                 if (l_element_courant != NULL)
  180:                 {
  181:                     s_time_alarme.tm_mon = (*((integer8 *)
  182:                             (*(*l_element_courant).donnee).objet)) - 1;
  183:                     l_element_courant = (*l_element_courant).suivant;
  184: 
  185:                     if (l_element_courant != NULL)
  186:                     {
  187:                         s_time_alarme.tm_year = (*((integer8 *)
  188:                                 (*(*l_element_courant).donnee).objet))
  189:                                 - 1900;
  190:                         l_element_courant = (*l_element_courant).suivant;
  191:                     }
  192:                     else
  193:                     {
  194:                         s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  195:                     }
  196:                 }
  197:                 else
  198:                 {
  199:                     s_time_alarme.tm_mon = (*s_time_actuel).tm_mon;
  200:                     s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  201:                 }
  202:             }
  203:             else
  204:             {
  205:                 s_time_alarme.tm_mday = (*s_time_actuel).tm_mday;
  206:                 s_time_alarme.tm_mon = (*s_time_actuel).tm_mon;
  207:                 s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  208:             }
  209:         }
  210:         else
  211:         {
  212:             s_time_alarme.tm_sec = 0;
  213:             s_time_alarme.tm_mday = (*s_time_actuel).tm_mday;
  214:             s_time_alarme.tm_mon = (*s_time_actuel).tm_mon;
  215:             s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  216:         }
  217: 
  218:         s_time_registre = s_time_alarme;
  219:         alarme = mktime(&s_time_alarme);
  220: 
  221:         if ((s_time_alarme.tm_sec != s_time_registre.tm_sec) ||
  222:                 (s_time_alarme.tm_min != s_time_registre.tm_min) ||
  223:                 (s_time_alarme.tm_hour != s_time_registre.tm_hour) ||
  224:                 (s_time_alarme.tm_mday != s_time_registre.tm_mday) ||
  225:                 (s_time_alarme.tm_mon != s_time_registre.tm_mon) ||
  226:                 (s_time_alarme.tm_year != s_time_registre.tm_year))
  227:         {
  228:             (*s_etat_processus).erreur_execution =
  229:                     d_ex_argument_invalide;
  230: 
  231:             liberation(s_etat_processus, s_objet_argument);
  232:             return;
  233:         }
  234: 
  235:         while((duree = difftime(alarme, st.time)) < 0)
  236:         {
  237:             if (specification_date == d_vrai)
  238:             {
  239:                 (*s_etat_processus).erreur_execution =
  240:                         d_ex_argument_invalide;
  241: 
  242:                 liberation(s_etat_processus, s_objet_argument);
  243:                 return;
  244:             }
  245: 
  246:             s_time_alarme.tm_mday++;
  247:             alarme = mktime(&s_time_alarme);
  248:         }
  249: 
  250:         attente.tv_nsec = (long) ((duree - (attente.tv_sec =
  251:                 (long) floor(duree))) * 1000000000);
  252: 
  253:         if ((*s_etat_processus).profilage == d_vrai)
  254:         {
  255:             profilage(s_etat_processus, "Sleep function (ALARM)");
  256: 
  257:             if ((*s_etat_processus).erreur_systeme != d_es)
  258:             {
  259:                 return;
  260:             }
  261:         }
  262: 
  263:         do
  264:         {
  265:             code_retour = nanosleep(&attente, &attente);
  266:             erreur = errno;
  267: 
  268:             if (code_retour == -1)
  269:             {
  270:                 gettimeofday(&debut_interruption, NULL);
  271: 
  272:                 scrutation_injection(s_etat_processus);
  273: 
  274:                 if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
  275:                 {
  276:                     affectation_interruptions_logicielles(s_etat_processus);
  277:                 }
  278: 
  279:                 if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
  280:                 {
  281:                     traitement_interruptions_logicielles(s_etat_processus);
  282:                 }
  283: 
  284:                 gettimeofday(&fin_interruption, NULL);
  285: 
  286:                 if (fin_interruption.tv_usec < debut_interruption.tv_usec)
  287:                 {
  288:                     duree_interruption.tv_usec = (1000000
  289:                             + fin_interruption.tv_usec)
  290:                             - debut_interruption.tv_usec;
  291:                     duree_interruption.tv_sec = fin_interruption.tv_sec
  292:                             - (debut_interruption.tv_sec + 1);
  293:                 }
  294:                 else
  295:                 {
  296:                     duree_interruption.tv_usec = fin_interruption.tv_usec
  297:                             - debut_interruption.tv_usec;
  298:                     duree_interruption.tv_sec = fin_interruption.tv_sec
  299:                             - debut_interruption.tv_sec;
  300:                 }
  301: 
  302:                 if (attente.tv_nsec < (1000 * duree_interruption.tv_usec))
  303:                 {
  304:                     attente.tv_nsec = (1000000000 + attente.tv_nsec)
  305:                             - (1000 * duree_interruption.tv_usec);
  306:                     attente.tv_sec = attente.tv_sec
  307:                             - (duree_interruption.tv_sec + 1);
  308:                 }
  309:                 else
  310:                 {
  311:                     attente.tv_nsec = attente.tv_nsec
  312:                             - (1000 * duree_interruption.tv_usec);
  313:                     attente.tv_sec = attente.tv_sec
  314:                             - duree_interruption.tv_sec;
  315:                 }
  316: 
  317:                 if (attente.tv_sec < 0)
  318:                 {
  319:                     code_retour = 0;
  320:                 }
  321:             }
  322:         } while(((code_retour == -1) && (erreur == EINTR))
  323:                 && ((*s_etat_processus).var_volatile_requete_arret == 0));
  324: 
  325:         if ((*s_etat_processus).profilage == d_vrai)
  326:         {
  327:             profilage(s_etat_processus, NULL);
  328:         }
  329:     }
  330:     else
  331:     {
  332:         liberation(s_etat_processus, s_objet_argument);
  333: 
  334:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  335:         return;
  336:     }
  337: 
  338:     liberation(s_etat_processus, s_objet_argument);
  339: }
  340: 
  341: 
  342: /*
  343: ================================================================================
  344:   Fonction 'atexit'
  345: ================================================================================
  346:   Entrées :
  347: --------------------------------------------------------------------------------
  348:   Sorties :
  349: --------------------------------------------------------------------------------
  350:   Effets de bord : néant
  351: ================================================================================
  352: */
  353: 
  354: void
  355: instruction_atexit(struct_processus *s_etat_processus)
  356: {
  357:     struct_objet        *s_objet_argument;
  358: 
  359:     (*s_etat_processus).erreur_execution = d_ex;
  360: 
  361:     if ((*s_etat_processus).affichage_arguments == 'Y')
  362:     {
  363:         printf("\n  ATEXIT ");
  364: 
  365:         if ((*s_etat_processus).langue == 'F')
  366:         {
  367:             printf("(exécution d'une fonction à la sortie d'une tâche)\n\n");
  368:         }
  369:         else
  370:         {
  371:             printf("(register a function to be called on task exit)\n\n");
  372:         }
  373: 
  374:         printf("    1: %s, %s\n", d_NOM, d_RPN);
  375: 
  376:         return;
  377:     }
  378:     else if ((*s_etat_processus).test_instruction == 'Y')
  379:     {
  380:         (*s_etat_processus).nombre_arguments = 1;
  381:         return;
  382:     }
  383: 
  384:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  385:     {
  386:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  387:         {
  388:             return;
  389:         }
  390:     }
  391: 
  392:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  393:             &s_objet_argument) == d_erreur)
  394:     {
  395:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  396:         return;
  397:     }
  398: 
  399:     if ((*s_objet_argument).type == NOM)
  400:     {
  401:         liberation(s_etat_processus, (*s_etat_processus).at_exit);
  402:         (*s_etat_processus).at_exit = s_objet_argument;
  403:     }
  404:     else if ((*s_objet_argument).type == RPN)
  405:     {
  406:         liberation(s_etat_processus, (*s_etat_processus).at_exit);
  407:         (*s_etat_processus).at_exit = s_objet_argument;
  408:     }
  409:     else
  410:     {
  411:         liberation(s_etat_processus, s_objet_argument);
  412: 
  413:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  414:         return;
  415:     }
  416: 
  417:     return;
  418: }
  419: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>