Skip to content
Snippets Groups Projects
Contact.c 4.31 KiB
Newer Older
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
#include "Contact.h"


// Header code defined in the model
void __userImplemented__Contact__initt(){
   init_sensor();
}

int __userImplemented__Contact__checkContact(){
   return checkContact();
}

// End of header code defined in the model

#define STATE__START__STATE 0
#define STATE__CHECK_CONTACT 1
#define STATE__choice__0 2
#define STATE__hsP 3
#define STATE__STOP__STATE 4

int Contact__checkContact() {
  traceFunctionCall("Contact", "checkContact", "-");
  return __userImplemented__Contact__checkContact();
}


void Contact__initt() {
  traceFunctionCall("Contact", "initt", "-");
  __userImplemented__Contact__initt();
}


void *mainFunc__Contact(void *arg){
  int contact = 0;
  int hasBeenPushed = 0;
  int tmp = 0;
  
  int __currentState = STATE__START__STATE;
  __attribute__((unused)) request __req0;
  __attribute__((unused))int *__params0[2];
  __attribute__((unused)) request __req1;
  __attribute__((unused))int *__params1[2];
  __attribute__((unused))setOfRequests __list;
  __attribute__((unused))pthread_cond_t __myCond;
  __attribute__((unused))request *__returnRequest;
  
  char * __myname = (char *)arg;
  
  pthread_cond_init(&__myCond, NULL);
  
  fillListOfRequests(&__list, __myname, &__myCond, &__mainMutex);
  //printf("my name = %s\n", __myname);
  
  /* Main loop on states */
  while(__currentState != STATE__STOP__STATE) {
    switch(__currentState) {
      case STATE__START__STATE: 
      traceStateEntering(__myname, "__StartState");
      Contact__initt();
      __currentState = STATE__CHECK_CONTACT;
      break;
      
      case STATE__CHECK_CONTACT: 
      traceStateEntering(__myname, "CHECK_CONTACT");
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
      makeNewRequest(&__req0, 2662, RECEIVE_SYNC_REQUEST, 0, 0, 0, 0, __params0);
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
      __req0.syncChannel = &__Controller_ready_to_receive_cont__Contact_ready_to_receive;
      addRequestToList(&__list, &__req0);
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
      makeNewRequest(&__req1, 2684, IMMEDIATE, 0, 0, 0, 0, __params1);
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
      addRequestToList(&__list, &__req1);
      if (nbOfRequests(&__list) == 0) {
        debug2Msg(__myname, "No possible request");
        __currentState = STATE__STOP__STATE;
        break;
      }
      __returnRequest = executeListOfRequests(&__list);
      clearListOfRequests(&__list);
      traceRequest(__myname, __returnRequest);
       if (__returnRequest == &__req0) {
        contact = Contact__checkContact();
        traceVariableModification("Contact", "contact", contact,0);
        __params0[0] = &contact;
        __params0[1] = &hasBeenPushed;
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
        makeNewRequest(&__req0, 2663, SEND_SYNC_REQUEST, 0, 0, 0, 2, __params0);
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
        __req0.syncChannel = &__Controller_receiveContact__Contact_sendContact;
        __returnRequest = executeOneRequest(&__list, &__req0);
        clearListOfRequests(&__list);
        traceRequest(__myname, __returnRequest);
        hasBeenPushed = 0;
        traceVariableModification("Contact", "hasBeenPushed", hasBeenPushed,0);
        __currentState = STATE__CHECK_CONTACT;
        
      }
      else  if (__returnRequest == &__req1) {
        tmp = Contact__checkContact();
        traceVariableModification("Contact", "tmp", tmp,0);
        __currentState = STATE__choice__0;
        
      }
      break;
      
      case STATE__choice__0: 
      traceStateEntering(__myname, "choice__0");
      if (!(tmp == 1)) {
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
        makeNewRequest(&__req0, 2668, IMMEDIATE, 0, 0, 0, 0, __params0);
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
        addRequestToList(&__list, &__req0);
      }
      if (tmp == 1) {
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
        makeNewRequest(&__req1, 2669, IMMEDIATE, 0, 0, 0, 0, __params1);
Abbe AHMED-KHALIFA's avatar
Abbe AHMED-KHALIFA committed
        addRequestToList(&__list, &__req1);
      }
      if (nbOfRequests(&__list) == 0) {
        debug2Msg(__myname, "No possible request");
        __currentState = STATE__STOP__STATE;
        break;
      }
      __returnRequest = executeListOfRequests(&__list);
      clearListOfRequests(&__list);
      traceRequest(__myname, __returnRequest);
       if (__returnRequest == &__req0) {
        __currentState = STATE__CHECK_CONTACT;
        
      }
      else  if (__returnRequest == &__req1) {
        __currentState = STATE__hsP;
        
      }
      break;
      
      case STATE__hsP: 
      traceStateEntering(__myname, "hsP");
      hasBeenPushed = 1;
      traceVariableModification("Contact", "hasBeenPushed", hasBeenPushed,0);
      __currentState = STATE__CHECK_CONTACT;
      break;
      
    }
  }
  //printf("Exiting = %s\n", __myname);
  return NULL;
}