1 martin 1.17 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.18 //
|
3 martin 1.17 // 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 martin 1.18 //
|
10 martin 1.17 // 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 martin 1.18 //
|
17 martin 1.17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.18 //
|
20 martin 1.17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.18 // 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 martin 1.18 //
|
28 martin 1.17 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
|
30 kamal.locahana 1.10 //%////////////////////////////////////////////////////////////////////////////
|
31 kumpf 1.1
|
32 marek 1.20 #include <Pegasus/Common/CIMBinMsgSerializer.h>
33 #include <Pegasus/Common/CIMBinMsgDeserializer.h>
|
34 kumpf 1.1 #include <Pegasus/Common/MessageLoader.h>
35 #include <Pegasus/Common/Exception.h>
36 #include <Pegasus/Common/Tracer.h>
37
38 #include "AnonymousPipe.h"
39
40
41 #if defined (PEGASUS_OS_TYPE_WINDOWS)
42 # include "AnonymousPipeWindows.cpp"
43 #elif defined (PEGASUS_OS_TYPE_UNIX)
|
44 mike 1.8 # include "AnonymousPipePOSIX.cpp"
|
45 gs.keenan 1.5 #elif defined (PEGASUS_OS_VMS)
|
46 mike 1.8 # include "AnonymousPipePOSIX.cpp"
|
47 kumpf 1.1 #else
48 # error "Unsupported platform"
49 #endif
50
|
51 mike 1.15
|
52 kumpf 1.1 PEGASUS_NAMESPACE_BEGIN
53
54 AnonymousPipe::Status AnonymousPipe::writeMessage (CIMMessage * message)
55 {
56 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::writeMessage");
57
58 //
59 // Serialize the request
60 //
|
61 mike 1.15 CIMBuffer messageBuffer(4096);
62
|
63 kumpf 1.1 try
64 {
|
65 mike 1.15 CIMBinMsgSerializer::serialize(messageBuffer, message);
|
66 kumpf 1.1 }
67 catch (Exception & e)
68 {
|
69 thilo.boehm 1.14 PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
|
70 kumpf 1.19 "Failed to serialize message: %s",
|
71 thilo.boehm 1.14 (const char*)e.getMessage().getCString()));
|
72 kumpf 1.1 PEG_METHOD_EXIT ();
73 throw;
74 }
75
76 //
77 // Write the serialized message to the pipe
78 //
|
79 kumpf 1.13 Uint32 messageLength = messageBuffer.size();
80 const char * messageData = messageBuffer.getData ();
|
81 kumpf 1.1
|
82 kumpf 1.13 Status writeStatus =
83 writeBuffer((const char*) &messageLength, sizeof(Uint32));
|
84 kumpf 1.1
|
85 kumpf 1.13 if (writeStatus == STATUS_SUCCESS)
|
86 kumpf 1.1 {
|
87 kumpf 1.13 writeStatus = writeBuffer(messageData, messageLength);
|
88 kumpf 1.1 }
89
90 PEG_METHOD_EXIT ();
91 return writeStatus;
92 }
93
94 AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
|
95 kumpf 1.19 {
|
96 kumpf 1.1 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");
97
98 message = 0;
99
100 //
101 // Read the message length
102 //
103 Uint32 messageLength;
104 Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));
105
106 if (readStatus != STATUS_SUCCESS)
107 {
108 PEG_METHOD_EXIT ();
109 return readStatus;
110 }
111
112 if (messageLength == 0)
113 {
114 //
115 // Null message
116 //
117 kumpf 1.1 PEG_METHOD_EXIT ();
118 return STATUS_SUCCESS;
119 }
120
121 //
122 // Read the message data
123 //
|
124 mike 1.15 // CIMBuffer uses realloc() and free() so the buffer must be allocated
125 // with malloc().
126 AutoPtr<char, FreeCharPtr> messageBuffer((char*)malloc(messageLength + 1));
|
127 kumpf 1.1
128 //
129 // We know a message is coming
130 // Keep reading even if interrupted
131 //
132 do
133 {
134 readStatus = readBuffer (messageBuffer.get (), messageLength);
135 } while (readStatus == STATUS_INTERRUPT);
136
137 if (readStatus != STATUS_SUCCESS)
138 {
139 PEG_METHOD_EXIT ();
140 return readStatus;
141 }
142
143 try
144 {
145 //
146 // De-serialize the message
147 //
|
148 mike 1.15 // CIMBuffer frees messageBuffer upon destruction.
149 CIMBuffer buf(messageBuffer.release(), messageLength);
150 message = CIMBinMsgDeserializer::deserialize(buf, messageLength);
151
152 if (!message)
153 {
154 throw CIMException(CIM_ERR_FAILED, "deserialize() failed");
155 }
|
156 kumpf 1.1 }
157 catch (Exception & e)
158 {
159 //
160 // De-serialization failed
161 //
|
162 thilo.boehm 1.14 PEG_TRACE ((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
163 "Failed to de-serialize message: %s",
164 (const char*)e.getMessage().getCString()));
|
165 kumpf 1.1 PEG_METHOD_EXIT ();
166 throw;
167 }
168
169 PEG_METHOD_EXIT ();
170 return readStatus;
171 }
172
173 PEGASUS_NAMESPACE_END
|