1 martin 1.17 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 martin 1.17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 kumpf 1.1 //
|
28 martin 1.17 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
|
30 kamal.locahana 1.10 //%////////////////////////////////////////////////////////////////////////////
|
31 kumpf 1.1
|
32 mike 1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
|
33 mike 1.15 # include <Pegasus/Common/CIMBinMsgSerializer.h>
34 # include <Pegasus/Common/CIMBinMsgDeserializer.h>
35 #else
36 # include <Pegasus/Common/CIMMessageSerializer.h>
37 # include <Pegasus/Common/CIMMessageDeserializer.h>
38 #endif
39
|
40 kumpf 1.1 #include <Pegasus/Common/MessageLoader.h>
41 #include <Pegasus/Common/Exception.h>
42 #include <Pegasus/Common/Tracer.h>
43
44 #include "AnonymousPipe.h"
45
46
47 #if defined (PEGASUS_OS_TYPE_WINDOWS)
48 # include "AnonymousPipeWindows.cpp"
49 #elif defined (PEGASUS_OS_TYPE_UNIX)
|
50 mike 1.8 # include "AnonymousPipePOSIX.cpp"
|
51 gs.keenan 1.5 #elif defined (PEGASUS_OS_VMS)
|
52 mike 1.8 # include "AnonymousPipePOSIX.cpp"
|
53 kumpf 1.1 #else
54 # error "Unsupported platform"
55 #endif
56
|
57 mike 1.15
|
58 kumpf 1.1 PEGASUS_NAMESPACE_BEGIN
59
60 AnonymousPipe::Status AnonymousPipe::writeMessage (CIMMessage * message)
61 {
62 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::writeMessage");
63
64 //
65 // Serialize the request
66 //
|
67 mike 1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
|
68 mike 1.15 CIMBuffer messageBuffer(4096);
69 #else
|
70 mike 1.6 Buffer messageBuffer;
|
71 kumpf 1.1 messageBuffer.reserveCapacity (4096);
|
72 mike 1.15 #endif
73
|
74 kumpf 1.1 try
75 {
|
76 mike 1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
|
77 mike 1.15 CIMBinMsgSerializer::serialize(messageBuffer, message);
78 #else
|
79 kumpf 1.1 CIMMessageSerializer::serialize (messageBuffer, message);
|
80 mike 1.15 #endif
|
81 kumpf 1.1 }
82 catch (Exception & e)
83 {
|
84 thilo.boehm 1.14 PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
85 "Failed to serialize message: %s",
86 (const char*)e.getMessage().getCString()));
|
87 kumpf 1.1 PEG_METHOD_EXIT ();
88 throw;
89 }
90
91 //
92 // Write the serialized message to the pipe
93 //
|
94 kumpf 1.13 Uint32 messageLength = messageBuffer.size();
95 const char * messageData = messageBuffer.getData ();
|
96 kumpf 1.1
|
97 kumpf 1.13 Status writeStatus =
98 writeBuffer((const char*) &messageLength, sizeof(Uint32));
|
99 kumpf 1.1
|
100 kumpf 1.13 if (writeStatus == STATUS_SUCCESS)
|
101 kumpf 1.1 {
|
102 kumpf 1.13 writeStatus = writeBuffer(messageData, messageLength);
|
103 kumpf 1.1 }
104
105 PEG_METHOD_EXIT ();
106 return writeStatus;
107 }
108
109 AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
|
110 mike 1.15 {
|
111 kumpf 1.1 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");
112
113 message = 0;
114
115 //
116 // Read the message length
117 //
118 Uint32 messageLength;
119 Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));
120
121 if (readStatus != STATUS_SUCCESS)
122 {
123 PEG_METHOD_EXIT ();
124 return readStatus;
125 }
126
127 if (messageLength == 0)
128 {
129 //
130 // Null message
131 //
132 kumpf 1.1 PEG_METHOD_EXIT ();
133 return STATUS_SUCCESS;
134 }
135
136 //
137 // Read the message data
138 //
|
139 mike 1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
|
140 mike 1.15 // CIMBuffer uses realloc() and free() so the buffer must be allocated
141 // with malloc().
142 AutoPtr<char, FreeCharPtr> messageBuffer((char*)malloc(messageLength + 1));
143 #else
|
144 kumpf 1.1 AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
|
145 mike 1.15 #endif
|
146 kumpf 1.1
147 //
148 // We know a message is coming
149 // Keep reading even if interrupted
150 //
151 do
152 {
153 readStatus = readBuffer (messageBuffer.get (), messageLength);
154 } while (readStatus == STATUS_INTERRUPT);
155
156 if (readStatus != STATUS_SUCCESS)
157 {
158 PEG_METHOD_EXIT ();
159 return readStatus;
160 }
161
162 try
163 {
164 //
165 // De-serialize the message
166 //
|
167 mike 1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
|
168 mike 1.15 // CIMBuffer frees messageBuffer upon destruction.
169 CIMBuffer buf(messageBuffer.release(), messageLength);
170 message = CIMBinMsgDeserializer::deserialize(buf, messageLength);
171
172 if (!message)
173 {
174 throw CIMException(CIM_ERR_FAILED, "deserialize() failed");
175 }
176 #else
|
177 kumpf 1.1 message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
|
178 mike 1.15 #endif
|
179 kumpf 1.1 }
180 catch (Exception & e)
181 {
182 //
183 // De-serialization failed
184 //
|
185 thilo.boehm 1.14 PEG_TRACE ((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
186 "Failed to de-serialize message: %s",
187 (const char*)e.getMessage().getCString()));
|
188 kumpf 1.1 PEG_METHOD_EXIT ();
189 throw;
190 }
191
192 PEG_METHOD_EXIT ();
193 return readStatus;
194 }
195
196 PEGASUS_NAMESPACE_END
|