function.tmplt 6.44 KB
Newer Older
1
2
3
4
5
6
7
8
@@-- The following tags are available in this template:
@@--
@@-- @_Name_@                : The name of the function
@@-- @_Language_@            : The implementation language
@@-- @_List_Of_PIs_@         : List of all Provided Interfaces (just names)
@@-- @_List_Of_RIs_@         : List of all Required Interfaces (just names)
@@-- @_List_Of_Sync_PIs@     : List of synchronous Provided Interfaces
@@-- @_List_Of_Sync_RIs@     : List of synchronous Required Interfaces
9
10
11
12
13
14
15
16
@@-- @_Sync_RIs_Parent_@
@@-- @_List_Of_ASync_PIs@    : Vector tag: list of async Provided Interfaces
@@-- @_ASync_PI_Param_Name_@ :   |_ Corresponding parameter name (or empty string)
@@-- @_ASync_PI_Param_Type_@ :   |_ Corresponding parameter type (or empty string)
@@-- @_List_Of_ASync_RIs@    : Vector tag: list of asynchronous Required Interfaces
@@-- @_ASync_RI_Param_Name_@ :   |_ Corresponding parameter name (or empty string)
@@-- @_ASync_RI_Param_Type_@ :   |_ Corresponding parameter type (or empty string)
@@-- @_Async_RIs_Parent_@    :   |_ Corresponding parent function
17
18
19
20
21
22
23
24
25
26
27
28
@@-- @_ASN1_Modules_@        : List of ASN.1 Modules names
@@-- @_ASN1_Files_@          : List of ASN.1 Files with path
@@-- @_Timers_@              : List of timers (just names)
@@-- @_Has_Context_@         : Flag, True if there are context parameters
@@-- @_CP_Names_@            : List of Context Parameter names
@@-- @_CP_Types_@            : List of Context Parameter types
@@-- @_Provided_Interfaces_@ : From template: Provided interfaces with params
@@-- @_Required_Interfaces_@ : From template: Required interfaces with params
@@-- @_Property_Names_@      : List of User-defined properties (names)
@@-- @_Property_Values_@     : List of User-defined properties (values)
@@-- @_Is_Type_@             : Flag, True if function is a component type
@@-- @_Instance_Of_@         : Optional name of component type
29
30
31
32
33
34
35
36
37
38
/* Body file for GUI @_Name_@
 * Generated by TASTE on @_NOW_@
 * DO NOT EDIT THIS FILE MANUALLY - MODIFY THE KAZOO TEMPLATE IF NECESSARY
*/

#include <unistd.h>
#include <mqueue.h>

#include "queue_manager.h"
#include "@_LOWER:Name_@.h"
Maxime Perrotin's avatar
Maxime Perrotin committed
39
#include "@_Name_@_enums_def.h"
40
41

typedef struct _PI_Messages {
Maxime Perrotin's avatar
Maxime Perrotin committed
42
   T_@_Name_@_PI_list msg_id;
43
44
45
46
47
48
49
50
51
52
   union {
      @@TABLE@@
      @@IF@@ @_ASync_PI_Param_Type_@ /= ""
      asn1Scc@_REPLACE_ALL(-/_):ASync_PI_Param_Type_@ @_LOWER:List_Of_ASync_PIs_@_param;
      @@END_IF@@
      @@END_TABLE@@
   } msg_data;
} PI_Messages;

typedef struct _RI_Messages {
Maxime Perrotin's avatar
Maxime Perrotin committed
53
   T_@_Name_@_RI_list msg_id;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
   union {
      @@TABLE@@
      @@IF@@ @_ASync_RI_Param_Type_@ /= ""
      asn1Scc@_REPLACE_ALL(-/_):ASync_RI_Param_Type_@ @_LOWER:List_Of_ASync_RIs_@_param;
      @@END_IF@@
      @@END_TABLE@@
   } msg_data;
} RI_Messages;

@@IF@@ @_List_Of_PIs'Length_@ > 0
// Queues of messages going from the binary to the user (PIs, or TMs)
static mqd_t @_LOWER:Name_@_PI_queue_id,
             @_LOWER:Name_@_PI_Python_queue_id;
@@END_IF@@

@@IF@@ @_List_Of_PIs'Length_@ > 0
// Queues of messages going from the user to the binary GUI (RIs, or TCs)
static mqd_t @_LOWER:Name_@_RI_queue_id;
@@END_IF@@


void @_LOWER:Name_@_startup(void)
{
   unsigned msgsize_max = 8192;
   FILE *f = fopen("/proc/sys/fs/mqueue/msgsize_max", "r");
   fscanf(f, "%d", &msgsize_max);

   if (msgsize_max < sizeof (PI_Messages) || msgsize_max < sizeof (RI_Messages)) {
      printf("[ERROR] The GUI is passing a message which parameter size "
             "exceeds your system limit (which is %d bytes per message).\n"
             "You can extend this limit by running: \n"
             "    echo NUMBER | sudo tee /proc/sys/fs/mqueue/msgsize_max\n"
             " ...  with NUMBER > %ld\n"
             "You can also make it permanent (check TASTE wiki)\n\n",
             msgsize_max,
             sizeof(PI_Messages) > sizeof(RI_Messages) ? sizeof(PI_Messages):sizeof(RI_Messages));
      exit(1);
   }

    char *gui_queue_name = NULL;
Maxime Perrotin's avatar
Maxime Perrotin committed
94
    int  len = snprintf (gui_queue_name, 0, "%d_@_LOWER:Name_@_RI_queue", geteuid());
95
96
    gui_queue_name = (char *) malloc ((size_t) len + 1);
    if (NULL != gui_queue_name) {
Maxime Perrotin's avatar
Maxime Perrotin committed
97
       snprintf (gui_queue_name, len + 1, "%d_@_LOWER:Name_@_RI_queue", geteuid());
98

Maxime Perrotin's avatar
Maxime Perrotin committed
99
       create_exchange_queue(gui_queue_name, 5, sizeof(RI_Messages), &@_LOWER:Name_@_RI_queue_id);
100
101
102
103
104

       free (gui_queue_name);
       gui_queue_name = NULL;
    }

Maxime Perrotin's avatar
Maxime Perrotin committed
105
    len = snprintf (gui_queue_name, 0, "%d_@_LOWER:Name_@_PI_queue", geteuid());
106
107
    gui_queue_name = (char *) malloc ((size_t) len + 1);
    if (NULL != gui_queue_name) {
Maxime Perrotin's avatar
Maxime Perrotin committed
108
       snprintf (gui_queue_name, len + 1, "%d_@_LOWER:Name_@_PI_queue", geteuid());
109

Maxime Perrotin's avatar
Maxime Perrotin committed
110
       create_exchange_queue(gui_queue_name, 10, sizeof(PI_Messages), &@_LOWER:Name_@_PI_queue_id);
111
112
113
114
115

       free (gui_queue_name);
       gui_queue_name = NULL;
    }

Maxime Perrotin's avatar
Maxime Perrotin committed
116
    len = snprintf (gui_queue_name, 0, "%d_@_LOWER:Name_@_PI_Python_queue", geteuid());
117
118
    gui_queue_name = (char *) malloc ((size_t) len + 1);
    if (NULL != gui_queue_name) {
Maxime Perrotin's avatar
Maxime Perrotin committed
119
       snprintf (gui_queue_name, len + 1, "%d_@_LOWER:Name_@_PI_Python_queue", geteuid());
120
121

       /* Extra queue for the TM sent to the Python mappers */
Maxime Perrotin's avatar
Maxime Perrotin committed
122
       create_exchange_queue(gui_queue_name, 10, sizeof (PI_Messages), &@_LOWER:Name_@_PI_Python_queue_id);
123
124
125
126
127
128

       free (gui_queue_name);
       gui_queue_name = NULL;
    }
}

Maxime Perrotin's avatar
Maxime Perrotin committed
129
130
131
132
133
134
//  Function polling the message queue for incoming message from the user
void @_LOWER:Name_@_PI_poll(void)
{
   struct mq_attr msgq_attr;
   char* msgcontent = NULL;

Maxime Perrotin's avatar
Maxime Perrotin committed
135
   T_@_Name_@_RI_list message_received_type;
Maxime Perrotin's avatar
Maxime Perrotin committed
136
137
138
139
140
141
142
143
144
145
146

   if ((msgcontent = (char*)malloc(sizeof(RI_Messages))) == NULL) {
      perror("Error when allocating memory in GUI polling function");
      exit (-1);
   }

   mq_getattr(@_LOWER:Name_@_RI_queue_id, &msgq_attr);

   while (!retrieve_message_from_queue(@_LOWER:Name_@_RI_queue_id,
                                       sizeof(RI_Messages),
                                       msgcontent,
Maxime Perrotin's avatar
Maxime Perrotin committed
147
148
                                       (int *)&message_received_type)) {
      switch(message_received_type) {
Maxime Perrotin's avatar
Maxime Perrotin committed
149
@@TABLE@@
Maxime Perrotin's avatar
Maxime Perrotin committed
150
         case i_@_List_Of_ASync_RIs_@:
Maxime Perrotin's avatar
Maxime Perrotin committed
151
152
153
154
155
156
157
158
159
160
161
            @_LOWER:Name_@_RI_@_LOWER:List_Of_ASync_RIs_@((asn1Scc@_REPLACE_ALL(-/_):ASync_RI_Param_Type_@ *)msgcontent);
            break;
@@END_TABLE@@
       default : break;
      }
   }

   free(msgcontent);
   return;
}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
@@TABLE@@
@_Provided_Interfaces_@

@@END_TABLE@@

@@TABLE@@
void @_LOWER:Name_@_PI_@_Timers_@(void)
{
 // There shoud be no timers in GUI functions
 // However the template may be modified to support them and do specific
 // action upon timer expiration (e.g. periodic check that the GUI queue
 // is still alive).
}
@@END_TABLE@@