/*****************************************************************************
 * File:       CARPIO_bridge.c
 *
 * Description:
 *
 * External Entity: 'PIO_1'  (CARPIO)
 ****************************************************************************/


#include "e_mechs.h"
#include "e_events.h"
#include "A_objects.h"
#include "A_CAR_object.h"
#include "A_CAR_events.h"
#include "A_SP_object.h"
#include "A_SP_events.h"

#include "CARPIO_bridge.h"

/* Dummy up instance handle for event generation.  */
static Escher_InstanceHandle_t self = &self;
/*****************************************************************************
 * Bridge:  current_position
 ****************************************************************************/
int
CARPIO_current_position(
    const int ee_car_id )
{
  int result = 0;

  /* Replace the following instructions with your specific code.  */
  {
  A_CAR_s * v2;  /* car */

  /* SELECT ANY car FROM INSTANCES OF CAR
     WHERE SELECTED.carousel_ID == PARAM.car_id */
  v2 = (A_CAR_s *)0;
  { /* Begin selection scope */
    A_CAR_s * w1;
    Escher_Iterator_s iter3_CAR;
    Escher_IteratorReset( &iter3_CAR, pG_A_CAR_extent );
    while ( (w1 = (A_CAR_s *)Escher_IteratorNext( &iter3_CAR )) != 0 )
    {
      if ( w1->m_carousel_ID == ee_car_id )
      {
        v2 = w1;
        break;
      }
    }
  } /* End selection scope */

  return v2->m_destination;

  }
  
  return result;
}

/*****************************************************************************
 * Bridge:  carousel_spin
 ****************************************************************************/
void
CARPIO_carousel_spin(
    const int ee_car_id,
    const int ee_destination )
{

  /* Replace the following instructions with your implementation code.  */
  {
  A_CAR_s * v5;  /* car */

  /* SELECT ANY car FROM INSTANCES OF CAR
     WHERE SELECTED.carousel_ID == PARAM.car_id */
  v5 = (A_CAR_s *)0;
  { /* Begin selection scope */
    A_CAR_s * w4;
    Escher_Iterator_s iter6_CAR;
    Escher_IteratorReset( &iter6_CAR, pG_A_CAR_extent );
    while ( (w4 = (A_CAR_s *)Escher_IteratorNext( &iter6_CAR )) != 0 )
    {
      if ( w4->m_carousel_ID == ee_car_id )
      {
        v5 = w4;
        break;
      }
    }
  } /* End selection scope */

  /* GENERATE CAR2:'there'() TO car */
  {
    A_CAR_Event2_s * event7 = (A_CAR_Event2_s *) Escher_NewOoaEvent( (void *) v5, &A_CAR_Event2_sc );
    SetEventSendingInstance( event7, self );
    Escher_SendEvent( (OoaEvent_t *)event7 );
  }

  }

}