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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2