intertask_interface.h 6.87 KB
Newer Older
Cedric Roux's avatar
 
Cedric Roux committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*******************************************************************************

  Eurecom OpenAirInterface
  Copyright(c) 1999 - 2012 Eurecom

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information
  Openair Admin: openair_admin@eurecom.fr
  Openair Tech : openair_tech@eurecom.fr
  Forums       : http://forums.eurecom.fr/openairinterface
  Address      : EURECOM, Campus SophiaTech, 450 Route des Chappes
                 06410 Biot FRANCE

*******************************************************************************/

/** @defgroup _intertask_interface_impl_ Intertask Interface Mechanisms
 * Implementation
 * @ingroup _ref_implementation_
 * @{
 */

37
38
39
40
#if defined(ENABLE_EVENT_FD)
# include <sys/epoll.h>
#endif

Cedric Roux's avatar
 
Cedric Roux committed
41
42
43
44
45
46
47
#ifndef INTERTASK_INTERFACE_H_
#define INTERTASK_INTERFACE_H_

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

48
#include "intertask_interface_conf.h"
Cedric Roux's avatar
 
Cedric Roux committed
49
50
#include "intertask_interface_types.h"

51
52
53
54
#define ITTI_MSG_NAME(mSGpTR)               itti_get_message_name((mSGpTR)->header.messageId)
#define ITTI_MSG_ORIGIN_NAME(mSGpTR)        itti_get_task_name((mSGpTR)->header.originTaskId)
#define ITTI_MSG_DESTINATION_NAME(mSGpTR)   itti_get_task_name((mSGpTR)->header.destinationTaskId)
#define ITTI_MSG_INSTANCE(mSGpTR)           (mSGpTR)->header.instance
55

Cedric Roux's avatar
 
Cedric Roux committed
56
57
58
59
/* Make the message number platform specific */
typedef unsigned long message_number_t;
#define MESSAGE_NUMBER_SIZE (sizeof(unsigned long))

60
typedef enum message_priorities_e {
Cedric Roux's avatar
 
Cedric Roux committed
61
62
63
64
65
66
67
    MESSAGE_PRIORITY_MAX       = 100,
    MESSAGE_PRIORITY_MAX_LEAST = 85,
    MESSAGE_PRIORITY_MED_PLUS  = 70,
    MESSAGE_PRIORITY_MED       = 55,
    MESSAGE_PRIORITY_MED_LEAST = 40,
    MESSAGE_PRIORITY_MIN_PLUS  = 25,
    MESSAGE_PRIORITY_MIN       = 10,
68
} message_priorities_t;
Cedric Roux's avatar
 
Cedric Roux committed
69
70
71

typedef struct message_info_s {
    task_id_t id;
72
    message_priorities_t priority;
Cedric Roux's avatar
 
Cedric Roux committed
73
74
75
    /* Message payload size */
    MessageHeaderSize size;
    /* Printable name */
76
    const char * const name;
Cedric Roux's avatar
 
Cedric Roux committed
77
78
} message_info_t;

79
typedef enum task_priorities_e {
Cedric Roux's avatar
 
Cedric Roux committed
80
81
82
83
84
85
86
    TASK_PRIORITY_MAX       = 100,
    TASK_PRIORITY_MAX_LEAST = 85,
    TASK_PRIORITY_MED_PLUS  = 70,
    TASK_PRIORITY_MED       = 55,
    TASK_PRIORITY_MED_LEAST = 40,
    TASK_PRIORITY_MIN_PLUS  = 25,
    TASK_PRIORITY_MIN       = 10,
87
} task_priorities_t;
Cedric Roux's avatar
 
Cedric Roux committed
88

89
90
typedef struct task_info_s {
    thread_id_t thread;
91
92
    task_priorities_t priority;
    unsigned int queue_size;
93
94
95
96
    /* Printable name */
    const char * const name;
} task_info_t;

97
98
99
100
101
102
103
/** \brief Update the itti LTE time reference for messages
 \param current reference frame
 \param current reference slot
 @returns < 0 on failure, 0 otherwise
 **/
void itti_update_lte_time(uint32_t frame, uint8_t slot);

Cedric Roux's avatar
 
Cedric Roux committed
104
105
106
107
/** \brief Send a broadcast message to every task
 \param message_p Pointer to the message to send
 @returns < 0 on failure, 0 otherwise
 **/
108
int itti_send_broadcast_message(MessageDef *message_p);
Cedric Roux's avatar
 
Cedric Roux committed
109
110
111
112
113
114
115

/** \brief Send a message to a task (could be itself)
 \param task_id Task ID
 \param instance Instance of the task used for virtualization
 \param message Pointer to the message to send
 @returns -1 on failure, 0 otherwise
 **/
116
int itti_send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message);
Cedric Roux's avatar
 
Cedric Roux committed
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#if defined(ENABLE_EVENT_FD)
/** \brief Add a new fd to monitor.
 * NOTE: it is up to the user to read data associated with the fd
 *  \param task_id Task ID of the receiving task
 *  \param fd The file descriptor to monitor
 **/
void itti_subscribe_event_fd(task_id_t task_id, int fd);

/** \brief Remove a fd from the list of fd to monitor
 *  \param task_id Task ID of the task
 *  \param fd The file descriptor to remove
 **/
void itti_unsubscribe_event_fd(task_id_t task_id, int fd);

/** \brief Return the list of events excluding the fd associated with itti
 *  \param task_id Task ID of the task
 *  \param events events list
 *  @returns number of events to handle
 **/
int itti_get_events(task_id_t task_id, struct epoll_event **events);
#endif

Cedric Roux's avatar
 
Cedric Roux committed
140
141
142
143
144
/** \brief Retrieves a message in the queue associated to task_id.
 * If the queue is empty, the thread is blocked till a new message arrives.
 \param task_id Task ID of the receiving task
 \param received_msg Pointer to the allocated message
 **/
145
void itti_receive_msg(task_id_t task_id, MessageDef **received_msg);
Cedric Roux's avatar
 
Cedric Roux committed
146

147
/** \brief Try to retrieves a message in the queue associated to task_id.
Cedric Roux's avatar
 
Cedric Roux committed
148
149
150
 \param task_id Task ID of the receiving task
 \param received_msg Pointer to the allocated message
 **/
151
void itti_poll_msg(task_id_t task_id, MessageDef **received_msg);
Cedric Roux's avatar
 
Cedric Roux committed
152
153
154
155
156
157
158

/** \brief Start thread associated to the task
 * \param task_id task to start
 * \param start_routine entry point for the task
 * \param args_p Optional argument to pass to the start routine
 * @returns -1 on failure, 0 otherwise
 **/
159
int itti_create_task(task_id_t task_id,
Cedric Roux's avatar
Cedric Roux committed
160
161
                     void *(*start_routine) (void *),
                     void *args_p);
Cedric Roux's avatar
 
Cedric Roux committed
162
163
164
165

/** \brief Mark the task as in ready state
 * \param task_id task to mark as ready
 **/
166
167
void itti_mark_task_ready(task_id_t task_id);

168
169
170
171
/** \brief Exit the current task.
 **/
void itti_exit_task(void);

172
173
174
175
/** \brief Indicate that the task is completed and initiate termination of all tasks.
 * \param task_id task that is completed
 **/
void itti_terminate_tasks(task_id_t task_id);
Cedric Roux's avatar
 
Cedric Roux committed
176
177
178
179

/** \brief Return the printable string associated with the message
 * \param message_id Id of the message
 **/
180
const char *itti_get_message_name(MessagesIds message_id);
Cedric Roux's avatar
 
Cedric Roux committed
181

Cedric Roux's avatar
Cedric Roux committed
182
183
184
/** \brief Return the printable string associated with a task id
 * \param thread_id Id of the task
 **/
185
const char *itti_get_task_name(task_id_t task_id);
Cedric Roux's avatar
Cedric Roux committed
186

Cedric Roux's avatar
 
Cedric Roux committed
187
/** \brief Alloc and memset(0) a new itti message.
188
189
190
 * \param origin_task_id Task ID of the sending task
 * \param message_id Message ID
 * @returns NULL in case of failure or newly allocated mesage ref
Cedric Roux's avatar
 
Cedric Roux committed
191
 **/
192
inline MessageDef *itti_alloc_new_message(
Cedric Roux's avatar
Cedric Roux committed
193
    task_id_t   origin_task_id,
Cedric Roux's avatar
 
Cedric Roux committed
194
195
    MessagesIds message_id);

196
197
198
199
200
201
202
203
204
/** \brief handle signals and wait for all threads to join when the process complete.
 * This function should be called from the main thread after having created all ITTI tasks.
 **/
void itti_wait_tasks_end(void);

/** \brief Send a termination message to all tasks.
 * \param task_id task that is broadcasting the message.
 **/
void itti_send_terminate_message(task_id_t task_id);
Cedric Roux's avatar
 
Cedric Roux committed
205
206
207

#endif /* INTERTASK_INTERFACE_H_ */
/* @} */