(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 david.dillard 1.3 // Modified By: David Dillard, VERITAS Software Corp.
 32                   //                  (david.dillard@veritas.com)
 33 kumpf         1.1 //
 34                   //%/////////////////////////////////////////////////////////////////////////////
 35                   
 36                   #include <Pegasus/Common/CIMMessageSerializer.h>
 37                   #include <Pegasus/Common/CIMMessageDeserializer.h>
 38                   #include <Pegasus/Common/MessageLoader.h>
 39                   #include <Pegasus/Common/Exception.h>
 40                   #include <Pegasus/Common/Tracer.h>
 41                   
 42                   #include "AnonymousPipe.h"
 43                   
 44                   
 45                   #if defined (PEGASUS_OS_TYPE_WINDOWS)
 46                   # include "AnonymousPipeWindows.cpp"
 47                   #elif defined (PEGASUS_OS_TYPE_UNIX)
 48                   # include "AnonymousPipeUnix.cpp"
 49                   #else
 50                   # error "Unsupported platform"
 51                   #endif
 52                   
 53                   PEGASUS_NAMESPACE_BEGIN
 54 kumpf         1.1 
 55                   AnonymousPipe::Status AnonymousPipe::writeMessage (CIMMessage * message)
 56                   {
 57                       PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::writeMessage");
 58                   
 59                       //
 60                       // Serialize the request
 61                       //
 62 david.dillard 1.3     Array<char> messageBuffer;
 63 kumpf         1.1     messageBuffer.reserveCapacity (4096);
 64                       try
 65                       {
 66                           CIMMessageSerializer::serialize (messageBuffer, message);
 67                       }
 68                       catch (Exception & e)
 69                       {
 70                           PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
 71                               "Failed to serialize message: " + e.getMessage ());
 72                           PEG_METHOD_EXIT ();
 73                           throw;
 74                       }
 75                   
 76                       //
 77                       // Write the serialized message to the pipe
 78                       //
 79                       Status writeStatus;
 80                       try
 81                       {
 82                           Uint32 messageLength = messageBuffer.size ();
 83                           const char * messageData = messageBuffer.getData ();
 84 kumpf         1.1 
 85                           writeStatus = writeBuffer ((const char *) &messageLength, 
 86                               sizeof (Uint32));
 87                   
 88                           if (writeStatus == STATUS_SUCCESS)
 89                           {
 90                               writeStatus = writeBuffer (messageBuffer.getData (), 
 91                                   messageLength);
 92                           }
 93                       }
 94                       catch (...)
 95                       {
 96                           PEG_METHOD_EXIT ();
 97                           throw;
 98                       }
 99                   
100                       PEG_METHOD_EXIT ();
101                       return writeStatus;
102                   }
103                   
104                   AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
105 kumpf         1.1 {
106                       PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");
107                   
108                       message = 0;
109                   
110                       //
111                       //  Read the message length
112                       //
113                       Uint32 messageLength;
114                       Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));
115                   
116                       if (readStatus != STATUS_SUCCESS)
117                       {
118                           PEG_METHOD_EXIT ();
119                           return readStatus;
120                       }
121                   
122                       if (messageLength == 0)
123                       {
124                           //
125                           //  Null message
126 kumpf         1.1         //
127                           PEG_METHOD_EXIT ();
128                           return STATUS_SUCCESS;
129                       }
130                   
131                       //
132                       //  Read the message data
133                       //
134                       AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
135                   
136                       //
137                       //  We know a message is coming
138                       //  Keep reading even if interrupted
139                       //
140                       do
141                       {
142                           readStatus = readBuffer (messageBuffer.get (), messageLength);
143                       } while (readStatus == STATUS_INTERRUPT);
144                   
145                       if (readStatus != STATUS_SUCCESS)
146                       {
147 kumpf         1.1         PEG_METHOD_EXIT ();
148                           return readStatus;
149                       }
150                   
151                       try
152                       {
153                           //
154                           //  De-serialize the message
155                           //
156                           message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
157                       }
158                       catch (Exception & e)
159                       {
160                           //
161                           //  De-serialization failed
162                           //
163                           PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
164                               "Failed to de-serialize message: " + e.getMessage ());
165                           PEG_METHOD_EXIT ();
166                           throw;
167                       }
168 kumpf         1.1 
169                       PEG_METHOD_EXIT ();
170                       return readStatus;
171                   }
172                   
173                   PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2