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.;
|
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 //
|
65 kumpf 1.1 messageBuffer.reserveCapacity (4096);
66 try
67 {
68 CIMMessageSerializer::serialize (messageBuffer, message);
69 }
70 catch (Exception & e)
71 {
72 PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
73 "Failed to serialize message: " + e.getMessage ());
74 PEG_METHOD_EXIT ();
75 throw;
76 }
77
78 //
79 // Write the serialized message to the pipe
80 //
81 Status writeStatus;
82 try
83 {
84 Uint32 messageLength = messageBuffer.size ();
85 const char * messageData = messageBuffer.getData ();
86 kumpf 1.1
87 writeStatus = writeBuffer ((const char *) &messageLength,
88 sizeof (Uint32));
89
90 if (writeStatus == STATUS_SUCCESS)
91 {
92 writeStatus = writeBuffer (messageBuffer.getData (),
93 messageLength);
94 }
95 }
96 catch (...)
97 {
98 PEG_METHOD_EXIT ();
99 throw;
100 }
101
102 PEG_METHOD_EXIT ();
103 return writeStatus;
104 }
105
106 AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
107 kumpf 1.1 {
108 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");
109
110 message = 0;
111
112 //
113 // Read the message length
114 //
115 Uint32 messageLength;
116 Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));
117
118 if (readStatus != STATUS_SUCCESS)
119 {
120 PEG_METHOD_EXIT ();
121 return readStatus;
122 }
123
124 if (messageLength == 0)
125 {
126 //
127 // Null message
128 kumpf 1.1 //
129 PEG_METHOD_EXIT ();
130 return STATUS_SUCCESS;
131 }
132
133 //
134 // Read the message data
135 //
136 AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
137
138 //
139 // We know a message is coming
140 // Keep reading even if interrupted
141 //
142 do
143 {
144 readStatus = readBuffer (messageBuffer.get (), messageLength);
145 } while (readStatus == STATUS_INTERRUPT);
146
147 if (readStatus != STATUS_SUCCESS)
148 {
149 kumpf 1.1 PEG_METHOD_EXIT ();
150 return readStatus;
151 }
152
153 try
154 {
155 //
156 // De-serialize the message
157 //
158 message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
159 }
160 catch (Exception & e)
161 {
162 //
163 // De-serialization failed
164 //
165 PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
166 "Failed to de-serialize message: " + e.getMessage ());
167 PEG_METHOD_EXIT ();
168 throw;
169 }
170 kumpf 1.1
171 PEG_METHOD_EXIT ();
172 return readStatus;
173 }
174
175 PEGASUS_NAMESPACE_END
|