OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librtems++/] [src/] [rtemsMessageQueue.cc] - Blame information for rev 228

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
  ------------------------------------------------------------------------
3
  $Id: rtemsMessageQueue.cc,v 1.2 2001-09-27 12:02:05 chris Exp $
4
  ------------------------------------------------------------------------
5
 
6
  COPYRIGHT (c) 1997
7
  Objective Design Systems Ltd Pty (ODS)
8
  All rights reserved (R) Objective Design Systems Ltd Pty
9
 
10
  The license and distribution terms for this file may be found in the
11
  file LICENSE in this distribution or at
12
  http://www.OARcorp.com/rtems/license.html.
13
 
14
  ------------------------------------------------------------------------
15
 
16
  See header file.
17
 
18
  ------------------------------------------------------------------------
19
*/
20
 
21
#include <string.h>
22
#include <rtems++/rtemsMessageQueue.h>
23
 
24
/* ----
25
   rtemsMessageQueue
26
*/
27
 
28
rtemsMessageQueue::rtemsMessageQueue(const char* mqname,
29
                                     const rtems_unsigned32 count,
30
                                     const rtems_unsigned32 max_message_size,
31
                                     const WaitMode wait_mode,
32
                                     const Scope scope)
33
  : name(0),
34
    owner(true),
35
    id(0)
36
{
37
  strcpy(name_str, "NOID");
38
  create(mqname, count, max_message_size, wait_mode, scope);
39
}
40
 
41
rtemsMessageQueue::rtemsMessageQueue(const char *mqname,
42
                                     const rtems_unsigned32 node)
43
  : name(0),
44
    owner(false),
45
    id(0)
46
{
47
  strcpy(name_str, "NOID");
48
  connect(mqname, node);
49
}
50
 
51
rtemsMessageQueue::rtemsMessageQueue(const rtemsMessageQueue& message_queue)
52
  : name(0),
53
    owner(false),
54
    id(0)
55
{
56
  name = message_queue.name;
57
  strcpy(name_str, message_queue.name_str);
58
  id = message_queue.id;
59
}
60
 
61
rtemsMessageQueue::rtemsMessageQueue()
62
  : name(0),
63
    owner(false),
64
    id(0)
65
{
66
  strcpy(name_str, "NOID");
67
}
68
 
69
rtemsMessageQueue::~rtemsMessageQueue()
70
{
71
  destroy();
72
}
73
 
74
void rtemsMessageQueue::make_invalid()
75
{
76
  strcpy(name_str, "NOID");
77
  name = 0;
78
  id = 0;
79
  owner = false;
80
}
81
 
82
const rtems_status_code rtemsMessageQueue::create(const char* mqname,
83
                                                  const rtems_unsigned32 count,
84
                                                  const rtems_unsigned32 max_message_size,
85
                                                  const WaitMode wait_mode,
86
                                                  const Scope scope)
87
{
88
  if (id)
89
    return set_status_code(RTEMS_ILLEGAL_ON_SELF);
90
 
91
  owner = true;
92
 
93
  strcpy(name_str, "    ");
94
  for (int c = 0; (c < 4) && (mqname[c] != '\0'); c++)
95
    name_str[c] = mqname[c];
96
  name = rtems_build_name(name_str[0],
97
                          name_str[1],
98
                          name_str[2],
99
                          name_str[3]);
100
 
101
  set_status_code(rtems_message_queue_create(name,
102
                                             count,
103
                                             max_message_size,
104
                                             scope | wait_mode,
105
                                             &id));
106
 
107
  if (unsuccessful())
108
  {
109
    make_invalid();
110
  }
111
 
112
  return last_status_code();
113
}
114
 
115
const rtems_status_code rtemsMessageQueue::destroy()
116
{
117
  if (id && owner)
118
  {
119
    set_status_code(rtems_message_queue_delete(id));
120
    make_invalid();
121
  }
122
  else
123
    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
124
 
125
  return last_status_code();
126
}
127
 
128
const rtemsMessageQueue& rtemsMessageQueue::operator=(const rtemsMessageQueue& message_queue)
129
{
130
  if (!owner)
131
  {
132
    name = message_queue.name;
133
    strcpy(name_str, message_queue.name_str);
134
    id = message_queue.id;
135
  }
136
 
137
  return *this;
138
}
139
 
140
const rtems_status_code rtemsMessageQueue::connect(const char *mqname,
141
                                                   const rtems_unsigned32 node)
142
{
143
  if (id && owner)
144
    return set_status_code(RTEMS_UNSATISFIED);
145
 
146
  // change state to not owner
147
  owner = false;
148
 
149
  strcpy(name_str, "    ");
150
  for (int c = 0; (c < 4) && (mqname[c] != '\0'); c++)
151
    name_str[c] = mqname[c];
152
  name = rtems_build_name(name_str[0],
153
                          name_str[1],
154
                          name_str[2],
155
                          name_str[3]);
156
 
157
  set_status_code(rtems_message_queue_ident(name, node, &id));
158
 
159
  if (unsuccessful())
160
  {
161
    make_invalid();
162
  }
163
 
164
  return last_status_code();
165
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.