(file) Return to AnonymousPipe.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2