po_hi_transport.c 4.42 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
 * For more informations, please visit http://ocarina.enst.fr
 *
 * Copyright (C) 2007-2008, GET-Telecom Paris.
9
 * Copyright (C) 2010, European Space Agency.
10
11
12
13
14
15
 */

#include <po_hi_config.h>
#include <po_hi_types.h>
#include <po_hi_debug.h>
#include <po_hi_transport.h>
16
#include <drivers/po_hi_driver_sockets.h>
17
18
19
#include <po_hi_giop.h>
#include <po_hi_messages.h>
#include <po_hi_returns.h>
julien.delange's avatar
julien.delange committed
20
#include <po_hi_gqueue.h>
21
22

#include <deployment.h>
julien.delange's avatar
julien.delange committed
23
24
#include <marshallers.h>
#include <types.h>
25
26
27
28
29
30
31
32
#include <activity.h>
#include <request.h>

/*
 * The following arrays are declared in the generated header
 * deployment.h.
 */

julien.delange's avatar
julien.delange committed
33
extern __po_hi_node_t  entity_table[__PO_HI_NB_ENTITIES];
34

julien.delange's avatar
julien.delange committed
35
36
37
extern __po_hi_entity_t       __po_hi_port_global_to_entity[__PO_HI_NB_PORTS];
extern __po_hi_local_port_t   __po_hi_port_global_to_local[__PO_HI_NB_PORTS];
extern __po_hi_request_t*     __po_hi_gqueues_most_recent_values[__PO_HI_NB_TASKS];
38
39
extern char*                  __po_hi_port_global_model_names[__PO_HI_NB_PORTS];
extern char*                  __po_hi_port_global_names[__PO_HI_NB_PORTS];
40
extern __po_hi_uint8_t        __po_hi_deployment_endiannesses[__PO_HI_NB_NODES];
41

julien.delange's avatar
julien.delange committed
42
int __po_hi_transport_send_default (__po_hi_task_id id, __po_hi_port_t port)
43
{
44
45
46
47
48
   __po_hi_msg_t         msg;
   __po_hi_request_t*    request;
   __po_hi_uint8_t       ndest;
   __po_hi_uint8_t       i;
   __po_hi_local_port_t  local_port;
49
50
   __po_hi_port_t        destination_port; 
   __po_hi_entity_t      destination_entity;
51

52
#if defined (__PO_HI_NEED_DRIVER_SOCKETS) && (__PO_HI_NB_NODES > 1)
53
54
55
   int error;
#endif

56
   local_port  = __po_hi_get_local_port_from_global_port (port);
57
   request     = __po_hi_gqueue_get_most_recent_value (id, local_port);
58
59
60

   if (request->port == -1)
   {
61
#ifdef __PO_HI_DEBUG
62
      __DEBUGMSG ("Send output task %d, port %d : no value to send\n", id, port);
63
64
#endif
      return __PO_HI_SUCCESS;
65
   }
julien.delange's avatar
julien.delange committed
66

67
   ndest          = __po_hi_gqueue_get_destinations_number (id, local_port);
julien.delange's avatar
julien.delange committed
68
69

#ifdef __PO_HI_DEBUG
70
   __DEBUGMSG ("Send value, emitter task %d, emitter port %d, emitter entity %d, destination ports :\n", id,  port, __po_hi_port_global_to_entity[port]);
julien.delange's avatar
julien.delange committed
71
#endif
72
   for (i=0 ; i < __po_hi_gqueue_get_destinations_number (id, local_port) ; i++)
73
   {
74
75
      destination_port     = __po_hi_gqueue_get_destination (id, local_port, i);
      destination_entity   = __po_hi_get_entity_from_global_port (destination_port);
julien.delange's avatar
julien.delange committed
76
#ifdef __PO_HI_DEBUG
77
      __DEBUGMSG ("\t%d (entity=%d)", 
78
79
            destination_port,
            destination_entity);
80
#endif
julien.delange's avatar
julien.delange committed
81
      __po_hi_msg_reallocate (&msg);
82

83
      request->port = destination_port;
84

85
      if (__po_hi_transport_get_node_from_entity (__po_hi_get_entity_from_global_port (port)) ==
86
          __po_hi_transport_get_node_from_entity (__po_hi_get_entity_from_global_port (destination_port)))
87
      {
88
            __DEBUGMSG (" [deliver locally]\n");
89
90
91
92
            __po_hi_main_deliver (request);
      }
#if defined (__PO_HI_NEED_DRIVER_SOCKETS) && (__PO_HI_NB_NODES > 1)
      else
93
      {
94
         __DEBUGMSG (" [deliver using network sockets]");
95
96
97
         __po_hi_marshall_request (request, &msg);

         error =__po_hi_driver_sockets_send (__po_hi_port_global_to_entity[port],
98
                                             __po_hi_port_global_to_entity[destination_port],
99
100
101
102
103
                                             &msg);
         if (error != __PO_HI_SUCCESS) 
         {
            return error;
         }
104
105
106
107
      }
#endif
   }
   request->port = __PO_HI_GQUEUE_INVALID_PORT;
julien.delange's avatar
julien.delange committed
108
109

#ifdef __PO_HI_DEBUG
110
   __DEBUGMSG ("\n");
111
#endif
julien.delange's avatar
julien.delange committed
112

113
   return __PO_HI_SUCCESS;
julien.delange's avatar
julien.delange committed
114
115
}

116
__po_hi_node_t __po_hi_transport_get_node_from_entity (const __po_hi_entity_t entity)
julien.delange's avatar
julien.delange committed
117
118
{
   return entity_table[entity];
119
}
120
121
122
123
124

__po_hi_entity_t __po_hi_get_entity_from_global_port (const __po_hi_port_t port)
{
    return __po_hi_port_global_to_entity[port];
}
125

126
char* __po_hi_get_port_name (const __po_hi_port_t port)
127
128
129
130
131
{
      return (__po_hi_port_global_names[port]);
}


132
char* __po_hi_get_port_model_name (const __po_hi_port_t port)
133
134
135
136
{
      return (__po_hi_port_global_model_names[port]);
}

137
138
139
140
__po_hi_local_port_t __po_hi_get_local_port_from_global_port (const __po_hi_port_t global_port)
{
   return (__po_hi_port_global_to_local[global_port]);
}
141
142
143
144
145

__po_hi_uint8_t __po_hi_get_endianness (const __po_hi_node_t node)
{
   return __po_hi_deployment_endiannesses[node];
}