POK
/home/jaouen/pok_official/pok/trunk/libpok/arinc653/queueing.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 #include <core/dependencies.h>
00018 
00019 #ifdef POK_NEEDS_ARINC653_QUEUEING
00020 
00021 #include <types.h>
00022 #include <middleware/port.h>
00023 #include <arinc653/types.h>
00024 #include <arinc653/queueing.h>
00025 
00026 void CREATE_QUEUING_PORT (
00027       /*in */ QUEUING_PORT_NAME_TYPE    QUEUING_PORT_NAME,
00028       /*in */ MESSAGE_SIZE_TYPE         MAX_MESSAGE_SIZE,
00029       /*in */ MESSAGE_RANGE_TYPE        MAX_NB_MESSAGE,
00030       /*in */ PORT_DIRECTION_TYPE       PORT_DIRECTION,
00031       /*in */ QUEUING_DISCIPLINE_TYPE   QUEUING_DISCIPLINE,
00032       /*out*/ QUEUING_PORT_ID_TYPE      *QUEUING_PORT_ID,
00033       /*out*/ RETURN_CODE_TYPE          *return_code)
00034 {
00035    pok_ret_t                        core_ret;
00036    pok_port_direction_t             core_direction;
00037    pok_port_queueing_discipline_t   core_discipline;
00038    pok_port_id_t                    core_id;
00039 
00040    switch (QUEUING_DISCIPLINE)
00041    {
00042      case PRIORITY:
00043          core_discipline = POK_PORT_QUEUEING_DISCIPLINE_PRIORITY;
00044          break;
00045 
00046      case FIFO:
00047          core_discipline = POK_PORT_QUEUEING_DISCIPLINE_FIFO;
00048          break;
00049 
00050       default:
00051          *return_code = INVALID_PARAM;
00052          return;
00053    }
00054 
00055    switch (PORT_DIRECTION)
00056    {
00057       case SOURCE:
00058          core_direction = POK_PORT_DIRECTION_OUT;
00059          break;
00060       
00061       case DESTINATION:
00062          core_direction = POK_PORT_DIRECTION_IN;
00063          break;
00064 
00065       default:
00066          *return_code = INVALID_PARAM;
00067          return;
00068    }
00069 
00070    core_ret = pok_port_queueing_create (QUEUING_PORT_NAME, MAX_MESSAGE_SIZE * MAX_NB_MESSAGE, core_direction, core_discipline, &core_id);
00071 
00072    *QUEUING_PORT_ID = core_id;
00073    *return_code = core_ret;
00074 }
00075 
00076 void SEND_QUEUING_MESSAGE (
00077       /*in */ QUEUING_PORT_ID_TYPE      QUEUING_PORT_ID,
00078       /*in */ MESSAGE_ADDR_TYPE         MESSAGE_ADDR,       /* by reference */
00079       /*in */ MESSAGE_SIZE_TYPE         LENGTH,
00080       /*in */ SYSTEM_TIME_TYPE          TIME_OUT,
00081       /*out*/ RETURN_CODE_TYPE          *return_code)
00082 {
00083    pok_ret_t core_ret;
00084 
00085    core_ret = pok_port_queueing_send (QUEUING_PORT_ID, MESSAGE_ADDR, LENGTH, TIME_OUT);
00086 
00087    *return_code = core_ret;
00088 }
00089 
00090 void RECEIVE_QUEUING_MESSAGE (
00091       /*in */ QUEUING_PORT_ID_TYPE      QUEUING_PORT_ID,
00092       /*in */ SYSTEM_TIME_TYPE          TIME_OUT,
00093       /*out*/ MESSAGE_ADDR_TYPE         MESSAGE_ADDR,
00094       /*out*/ MESSAGE_SIZE_TYPE         *LENGTH,
00095       /*out*/ RETURN_CODE_TYPE          *return_code )
00096 {
00097    pok_ret_t core_ret;
00098 
00099    core_ret = pok_port_queueing_receive (QUEUING_PORT_ID, TIME_OUT, *LENGTH, MESSAGE_ADDR, (pok_port_size_t*)LENGTH);
00100 
00101    if(core_ret == POK_ERRNO_EMPTY) core_ret = NOT_AVAILABLE;
00102    *return_code = core_ret;
00103 }
00104 
00105 void GET_QUEUING_PORT_ID (
00106       /*in */ QUEUING_PORT_NAME_TYPE    QUEUING_PORT_NAME,
00107       /*out*/ QUEUING_PORT_ID_TYPE      *QUEUING_PORT_ID,
00108       /*out*/ RETURN_CODE_TYPE          *return_code)
00109 {
00110    pok_ret_t core_ret;
00111 
00112    core_ret = pok_port_queueing_id(QUEUING_PORT_NAME, *QUEUING_PORT_ID);
00113    *return_code = core_ret;
00114 }
00115 
00116 void GET_QUEUING_PORT_STATUS (
00117       /*in */ QUEUING_PORT_ID_TYPE      QUEUING_PORT_ID,
00118       /*out*/ QUEUING_PORT_STATUS_TYPE *QUEUING_PORT_STATUS,
00119       /*out*/ RETURN_CODE_TYPE          *return_code)
00120 {
00121   pok_ret_t core_ret;
00122   pok_port_queueing_status_t status;
00123 
00124    core_ret = pok_port_queueing_id(QUEUING_PORT_ID, &status);
00125    QUEUING_PORT_STATUS->NB_MESSAGE = status.nb_messages;
00126 #warning TBSL : commented to have it compile
00127    //QUEUING_PORT_STATUS->MAX_NB_MESSAGE = status.g;
00128    QUEUING_PORT_STATUS->MAX_MESSAGE_SIZE = status.size;
00129    QUEUING_PORT_STATUS->PORT_DIRECTION = status.direction;
00130    QUEUING_PORT_STATUS->WAITING_PROCESSES = status.waiting_processes;
00131   *return_code = core_ret;
00132 }
00133 
00134 void CLEAR_QUEUING_PORT (
00135       /*in */ QUEUING_PORT_ID_TYPE      QUEUING_PORT_ID,
00136       /*out*/ RETURN_CODE_TYPE          *return_code)
00137 {
00138   (void) QUEUING_PORT_ID;
00139   *return_code = NOT_AVAILABLE;
00140 }
00141 
00142 #endif