function.tmplt 5.41 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* 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"
#include "@_LOWER:Name_@_enums_def.h"

typedef struct _PI_Messages {
   T_@_LOWER:Name_@_PI_list msg_id;
   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 {
   T_@_LOWER:Name_@_RI_list msg_id;
   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;
    int  len = snprintf (gui_queue_name, 0, "%d_ground_RI_queue", geteuid());
    gui_queue_name = (char *) malloc ((size_t) len + 1);
    if (NULL != gui_queue_name) {
       snprintf (gui_queue_name, len + 1, "%d_ground_RI_queue", geteuid());

       create_exchange_queue(gui_queue_name, 5, sizeof(RI_Messages), &ground_RI_queue_id);

       free (gui_queue_name);
       gui_queue_name = NULL;
    }

    len = snprintf (gui_queue_name, 0, "%d_ground_PI_queue", geteuid());
    gui_queue_name = (char *) malloc ((size_t) len + 1);
    if (NULL != gui_queue_name) {
       snprintf (gui_queue_name, len + 1, "%d_ground_PI_queue", geteuid());

       create_exchange_queue(gui_queue_name, 10, sizeof(PI_Messages), &ground_PI_queue_id);

       free (gui_queue_name);
       gui_queue_name = NULL;
    }

    len = snprintf (gui_queue_name, 0, "%d_ground_PI_Python_queue", geteuid());
    gui_queue_name = (char *) malloc ((size_t) len + 1);
    if (NULL != gui_queue_name) {
       snprintf (gui_queue_name, len + 1, "%d_ground_PI_Python_queue", geteuid());

       /* Extra queue for the TM sent to the Python mappers */
       create_exchange_queue(gui_queue_name, 10, sizeof (PI_Messages), &ground_PI_Python_queue_id);

       free (gui_queue_name);
       gui_queue_name = NULL;
    }
}

@@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@@