1 karl 1.4 //%2005////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 karl 1.2 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 kumpf 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.2 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.4 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 kumpf 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Carol Ann Krug Graves, Hewlett-Packard Company
31 // (carolann_graves@hp.com)
32 kumpf 1.1 //
|
33 david.dillard 1.3 // Modified By: David Dillard, VERITAS Software Corp.
34 // (david.dillard@veritas.com)
|
35 gs.keenan 1.5 // Sean Keenan (sean.keenan@hp.com)
|
36 kumpf 1.1 //
37 //%/////////////////////////////////////////////////////////////////////////////
38
39 #include <Pegasus/Common/CIMMessageSerializer.h>
40 #include <Pegasus/Common/CIMMessageDeserializer.h>
41 #include <Pegasus/Common/MessageLoader.h>
42 #include <Pegasus/Common/Exception.h>
43 #include <Pegasus/Common/Tracer.h>
44
45 #include "AnonymousPipe.h"
46
47
48 #if defined (PEGASUS_OS_TYPE_WINDOWS)
49 # include "AnonymousPipeWindows.cpp"
50 #elif defined (PEGASUS_OS_TYPE_UNIX)
51 # include "AnonymousPipeUnix.cpp"
|
52 gs.keenan 1.5 #elif defined (PEGASUS_OS_VMS)
53 # include "AnonymousPipeVms.cpp"
|
54 kumpf 1.1 #else
55 # error "Unsupported platform"
56 #endif
57
58 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.5.8.1 Buffer messageBuffer;
|
68 kumpf 1.1 messageBuffer.reserveCapacity (4096);
69 try
70 {
71 CIMMessageSerializer::serialize (messageBuffer, message);
72 }
73 catch (Exception & e)
74 {
75 PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
76 "Failed to serialize message: " + e.getMessage ());
77 PEG_METHOD_EXIT ();
78 throw;
79 }
80
81 //
82 // Write the serialized message to the pipe
83 //
84 Status writeStatus;
85 try
86 {
87 Uint32 messageLength = messageBuffer.size ();
88 const char * messageData = messageBuffer.getData ();
89 kumpf 1.1
90 writeStatus = writeBuffer ((const char *) &messageLength,
91 sizeof (Uint32));
92
93 if (writeStatus == STATUS_SUCCESS)
94 {
95 writeStatus = writeBuffer (messageBuffer.getData (),
96 messageLength);
97 }
98 }
99 catch (...)
100 {
101 PEG_METHOD_EXIT ();
102 throw;
103 }
104
105 PEG_METHOD_EXIT ();
106 return writeStatus;
107 }
108
109 AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
110 kumpf 1.1 {
111 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 kumpf 1.1 //
132 PEG_METHOD_EXIT ();
133 return STATUS_SUCCESS;
134 }
135
136 //
137 // Read the message data
138 //
139 AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
140
141 //
142 // We know a message is coming
143 // Keep reading even if interrupted
144 //
145 do
146 {
147 readStatus = readBuffer (messageBuffer.get (), messageLength);
148 } while (readStatus == STATUS_INTERRUPT);
149
150 if (readStatus != STATUS_SUCCESS)
151 {
152 kumpf 1.1 PEG_METHOD_EXIT ();
153 return readStatus;
154 }
155
156 try
157 {
158 //
159 // De-serialize the message
160 //
161 message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
162 }
163 catch (Exception & e)
164 {
165 //
166 // De-serialization failed
167 //
168 PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
169 "Failed to de-serialize message: " + e.getMessage ());
170 PEG_METHOD_EXIT ();
171 throw;
172 }
173 kumpf 1.1
174 PEG_METHOD_EXIT ();
175 return readStatus;
176 }
177
178 PEGASUS_NAMESPACE_END
|