(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 kamal.locahana 1.10 //=============================================================================
 31 kumpf          1.1  //
 32 kamal.locahana 1.10 //%////////////////////////////////////////////////////////////////////////////
 33 kumpf          1.1  
 34                     #include <Pegasus/Common/CIMMessageSerializer.h>
 35                     #include <Pegasus/Common/CIMMessageDeserializer.h>
 36                     #include <Pegasus/Common/MessageLoader.h>
 37                     #include <Pegasus/Common/Exception.h>
 38                     #include <Pegasus/Common/Tracer.h>
 39                     
 40                     #include "AnonymousPipe.h"
 41                     
 42                     
 43                     #if defined (PEGASUS_OS_TYPE_WINDOWS)
 44                     # include "AnonymousPipeWindows.cpp"
 45                     #elif defined (PEGASUS_OS_TYPE_UNIX)
 46 mike           1.8  # include "AnonymousPipePOSIX.cpp"
 47 gs.keenan      1.5  #elif defined (PEGASUS_OS_VMS)
 48 mike           1.8  # include "AnonymousPipePOSIX.cpp"
 49 kumpf          1.1  #else
 50                     # error "Unsupported platform"
 51                     #endif
 52                     
 53                     PEGASUS_NAMESPACE_BEGIN
 54                     
 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 mike           1.6      Buffer 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 kumpf          1.13     Uint32 messageLength = messageBuffer.size();
 80                         const char * messageData = messageBuffer.getData ();
 81 kumpf          1.1  
 82 kumpf          1.13     Status writeStatus =
 83                             writeBuffer((const char*) &messageLength, sizeof(Uint32));
 84 kumpf          1.1  
 85 kumpf          1.13     if (writeStatus == STATUS_SUCCESS)
 86 kumpf          1.1      {
 87 kumpf          1.13         writeStatus = writeBuffer(messageData, messageLength);
 88 kumpf          1.1      }
 89                     
 90                         PEG_METHOD_EXIT ();
 91                         return writeStatus;
 92                     }
 93                     
 94                     AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
 95                     {
 96                         PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");
 97                     
 98                         message = 0;
 99                     
100                         //
101                         //  Read the message length
102                         //
103                         Uint32 messageLength;
104                         Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));
105                     
106                         if (readStatus != STATUS_SUCCESS)
107                         {
108                             PEG_METHOD_EXIT ();
109 kumpf          1.1          return readStatus;
110                         }
111                     
112                         if (messageLength == 0)
113                         {
114                             //
115                             //  Null message
116                             //
117                             PEG_METHOD_EXIT ();
118                             return STATUS_SUCCESS;
119                         }
120                     
121                         //
122                         //  Read the message data
123                         //
124                         AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
125                     
126                         //
127                         //  We know a message is coming
128                         //  Keep reading even if interrupted
129                         //
130 kumpf          1.1      do
131                         {
132                             readStatus = readBuffer (messageBuffer.get (), messageLength);
133                         } while (readStatus == STATUS_INTERRUPT);
134                     
135                         if (readStatus != STATUS_SUCCESS)
136                         {
137                             PEG_METHOD_EXIT ();
138                             return readStatus;
139                         }
140                     
141                         try
142                         {
143                             //
144                             //  De-serialize the message
145                             //
146                             message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
147                         }
148                         catch (Exception & e)
149                         {
150                             //
151 kumpf          1.1          //  De-serialization failed
152                             //
153                             PEG_TRACE_STRING (TRC_OS_ABSTRACTION, Tracer::LEVEL2,
154                                 "Failed to de-serialize message: " + e.getMessage ());
155                             PEG_METHOD_EXIT ();
156                             throw;
157                         }
158                     
159                         PEG_METHOD_EXIT ();
160                         return readStatus;
161                     }
162                     
163                     PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2