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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2