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

  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 kumpf         1.1 //
 36                   //%/////////////////////////////////////////////////////////////////////////////
 37                   
 38                   #include <Pegasus/Common/CIMMessageSerializer.h>
 39                   #include <Pegasus/Common/CIMMessageDeserializer.h>
 40                   #include <Pegasus/Common/MessageLoader.h>
 41                   #include <Pegasus/Common/Exception.h>
 42                   #include <Pegasus/Common/Tracer.h>
 43                   
 44                   #include "AnonymousPipe.h"
 45                   
 46                   
 47                   #if defined (PEGASUS_OS_TYPE_WINDOWS)
 48                   # include "AnonymousPipeWindows.cpp"
 49                   #elif defined (PEGASUS_OS_TYPE_UNIX)
 50                   # include "AnonymousPipeUnix.cpp"
 51                   #else
 52                   # error "Unsupported platform"
 53                   #endif
 54                   
 55                   PEGASUS_NAMESPACE_BEGIN
 56 kumpf         1.1 
 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 david.dillard 1.3     Array<char> 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                       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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2