summaryrefslogtreecommitdiffstats
path: root/c/src/librtems++/include/rtems++/rtemsEvent.h
blob: fceaab134a4b4c5ef7725ebad249cd8ec3494e24 (plain) (blame)
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
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
/*
  ------------------------------------------------------------------------
  $Id$
  ------------------------------------------------------------------------

  COPYRIGHT (c) 1997
  Objective Design Systems Ltd Pty (ODS)
  All rights reserved (R) Objective Design Systems Ltd Pty
  
  The license and distribution terms for this file may be found in the
  file LICENSE in this distribution or at
  http://www.rtems.com/license/LICENSE.

  ------------------------------------------------------------------------

  rtemsEvent class.

  This class allows the user to send and receive RTEMS events to a task.

  ------------------------------------------------------------------------ */

#if !defined(_rtemsEvent_h_)
#define _rtemsEvent_h_

#include <rtems++/rtemsStatusCode.h>
#include <rtems++/rtemsTask.h>

/* ----
    rtemsEvent
*/

class rtemsEvent
  : public rtemsStatusCode
{
public:
  // attribute a task can have
  
  enum WaitMode { wait = RTEMS_WAIT,
                  no_wait = RTEMS_NO_WAIT};
  enum Condition { any = RTEMS_EVENT_ANY,
                   all = RTEMS_EVENT_ALL};
  
  // only the first 4 characters of the name are taken  

  // connect to a task
  rtemsEvent(const char* name, rtems_unsigned32 node = RTEMS_SEARCH_ALL_NODES);

  // copy and default constructors
  rtemsEvent(const rtemsEvent& event);
  rtemsEvent();
  
  virtual ~rtemsEvent();    
  
  // connect to an existing task object, will not be the owner
  const rtemsEvent& operator=(const rtemsEvent& event);
  virtual const rtems_status_code connect(const char *name,
                                          const rtems_unsigned32 node = RTEMS_SEARCH_ALL_NODES);
  
  // send an event
  inline const rtems_status_code send(const rtems_id task,
                                      const rtems_event_set events);
  inline const rtems_status_code send(const rtemsTask& task,
                                      const rtems_event_set events) ;
  inline const rtems_status_code send(const rtems_event_set events);

  // receive an event, can block a task if no events waiting
  inline const rtems_status_code receive(const rtems_event_set event_in,
                                         rtems_event_set& event_out,
                                         const rtems_interval micro_secs = 0,
                                         const WaitMode wait = wait,
                                         const Condition condition = any);

  // object id, and name
  const rtems_id task_id_is() const { return id; }
  const rtems_name task_name_is() const { return name; }
  
private:   
  // task name
  rtems_name name;

  // the rtems task id, object handle
  rtems_id id;

};

const rtems_status_code rtemsEvent::send(const rtems_id task,
                                         const rtems_event_set events)
{
  set_status_code(rtems_event_send(task, events));
  return last_status_code();
}

const rtems_status_code rtemsEvent::send(const rtemsTask& task,
                                         const rtems_event_set events)
{
  set_status_code(rtems_event_send(task.id_is(), events));
  return last_status_code();
}

const rtems_status_code rtemsEvent::send(const rtems_event_set events)
{
  set_status_code(rtems_event_send(id, events));
  return last_status_code();
}

const rtems_status_code rtemsEvent::receive(const rtems_event_set event_in,
                                            rtems_event_set& event_out,
                                            const rtems_interval micro_secs,
                                            const WaitMode wait,
                                            const Condition condition)
{
  rtems_interval usecs =
    micro_secs && (micro_secs < _TOD_Microseconds_per_tick) ?
    _TOD_Microseconds_per_tick : micro_secs;
  set_status_code(rtems_event_receive(event_in,
                                      wait | condition,
                                      TOD_MICROSECONDS_TO_TICKS(usecs),
                                      &event_out));
  return last_status_code();
}

#endif  // _rtemsEvent_h_