1 karl 1.7 //%2006////////////////////////////////////////////////////////////////////////
|
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 karl 1.7 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 kumpf 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
|
30 kamal.locahana 1.10 //=============================================================================
|
31 kumpf 1.1 //
|
32 kamal.locahana 1.10 //%////////////////////////////////////////////////////////////////////////////
|
33 kumpf 1.1
34 #include <Pegasus/Common/CIMMessageSerializer.h>
35 #include <Pegasus/Common/CIMMessageDeserializer.h>
36 #include <Pegasus/Common/MessageLoader.h>
37 #include <Pegasus/Common/Exception.h>
38 #include <Pegasus/Common/Tracer.h>
39
40 #include "AnonymousPipe.h"
41
42
43 #if defined (PEGASUS_OS_TYPE_WINDOWS)
44 # include "AnonymousPipeWindows.cpp"
45 #elif defined (PEGASUS_OS_TYPE_UNIX)
|
46 mike 1.8 # include "AnonymousPipePOSIX.cpp"
|
47 gs.keenan 1.5 #elif defined (PEGASUS_OS_VMS)
|
48 mike 1.8 # include "AnonymousPipePOSIX.cpp"
|
49 mike 1.13.2.1 #elif defined (PEGASUS_OS_VXWORKS)
50 # include "AnonymousPipePOSIX.cpp"
|
51 kumpf 1.1 #else
52 # error "Unsupported platform"
53 #endif
54
55 PEGASUS_NAMESPACE_BEGIN
56
57 AnonymousPipe::Status AnonymousPipe::writeMessage (CIMMessage * message)
58 {
59 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::writeMessage");
60
61 //
62 // Serialize the request
63 //
|
64 mike 1.6 Buffer messageBuffer;
|
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 kumpf 1.13 Uint32 messageLength = messageBuffer.size();
82 const char * messageData = messageBuffer.getData ();
|
83 kumpf 1.1
|
84 kumpf 1.13 Status writeStatus =
85 writeBuffer((const char*) &messageLength, sizeof(Uint32));
|
86 kumpf 1.1
|
87 kumpf 1.13 if (writeStatus == STATUS_SUCCESS)
|
88 kumpf 1.1 {
|
89 kumpf 1.13 writeStatus = writeBuffer(messageData, messageLength);
|
90 kumpf 1.1 }
91
92 PEG_METHOD_EXIT ();
93 return writeStatus;
94 }
95
96 AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
97 {
98 PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");
99
100 message = 0;
101
102 //
103 // Read the message length
104 //
105 Uint32 messageLength;
106 Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));
107
108 if (readStatus != STATUS_SUCCESS)
109 {
110 PEG_METHOD_EXIT ();
111 kumpf 1.1 return readStatus;
112 }
113
114 if (messageLength == 0)
115 {
116 //
117 // Null message
118 //
119 PEG_METHOD_EXIT ();
120 return STATUS_SUCCESS;
121 }
122
123 //
124 // Read the message data
125 //
126 AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
127
128 //
129 // We know a message is coming
130 // Keep reading even if interrupted
131 //
132 kumpf 1.1 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 message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
149 }
150 catch (Exception & e)
151 {
152 //
153 kumpf 1.1 // De-serialization failed
154 //
155 PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
156 "Failed to de-serialize message: " + e.getMessage ());
157 PEG_METHOD_EXIT ();
158 throw;
159 }
160
161 PEG_METHOD_EXIT ();
162 return readStatus;
163 }
164
165 PEGASUS_NAMESPACE_END
|