(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 mike           1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
 35 mike           1.15 # include <Pegasus/Common/CIMBinMsgSerializer.h>
 36                     # include <Pegasus/Common/CIMBinMsgDeserializer.h>
 37                     #else
 38                     # include <Pegasus/Common/CIMMessageSerializer.h>
 39                     # include <Pegasus/Common/CIMMessageDeserializer.h>
 40                     #endif
 41                     
 42 kumpf          1.1  #include <Pegasus/Common/MessageLoader.h>
 43                     #include <Pegasus/Common/Exception.h>
 44                     #include <Pegasus/Common/Tracer.h>
 45                     
 46                     #include "AnonymousPipe.h"
 47                     
 48                     
 49                     #if defined (PEGASUS_OS_TYPE_WINDOWS)
 50                     # include "AnonymousPipeWindows.cpp"
 51                     #elif defined (PEGASUS_OS_TYPE_UNIX)
 52 mike           1.8  # include "AnonymousPipePOSIX.cpp"
 53 gs.keenan      1.5  #elif defined (PEGASUS_OS_VMS)
 54 mike           1.8  # include "AnonymousPipePOSIX.cpp"
 55 kumpf          1.1  #else
 56                     # error "Unsupported platform"
 57                     #endif
 58                     
 59 mike           1.15 
 60 kumpf          1.1  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.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
 70 mike           1.15     CIMBuffer messageBuffer(4096);
 71                     #else
 72 mike           1.6      Buffer messageBuffer;
 73 kumpf          1.1      messageBuffer.reserveCapacity (4096);
 74 mike           1.15 #endif
 75                     
 76 kumpf          1.1      try
 77                         {
 78 mike           1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
 79 mike           1.15         CIMBinMsgSerializer::serialize(messageBuffer, message);
 80                     #else
 81 kumpf          1.1          CIMMessageSerializer::serialize (messageBuffer, message);
 82 mike           1.15 #endif
 83 kumpf          1.1      }
 84                         catch (Exception & e)
 85                         {
 86 thilo.boehm    1.14         PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
 87                                 "Failed to serialize message: %s", 
 88                                 (const char*)e.getMessage().getCString()));
 89 kumpf          1.1          PEG_METHOD_EXIT ();
 90                             throw;
 91                         }
 92                     
 93                         //
 94                         // Write the serialized message to the pipe
 95                         //
 96 kumpf          1.13     Uint32 messageLength = messageBuffer.size();
 97                         const char * messageData = messageBuffer.getData ();
 98 kumpf          1.1  
 99 kumpf          1.13     Status writeStatus =
100                             writeBuffer((const char*) &messageLength, sizeof(Uint32));
101 kumpf          1.1  
102 kumpf          1.13     if (writeStatus == STATUS_SUCCESS)
103 kumpf          1.1      {
104 kumpf          1.13         writeStatus = writeBuffer(messageData, messageLength);
105 kumpf          1.1      }
106                     
107                         PEG_METHOD_EXIT ();
108                         return writeStatus;
109                     }
110                     
111                     AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
112 mike           1.15 { 
113 kumpf          1.1      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                             //
134 kumpf          1.1          PEG_METHOD_EXIT ();
135                             return STATUS_SUCCESS;
136                         }
137                     
138                         //
139                         //  Read the message data
140                         //
141 mike           1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
142 mike           1.15     // CIMBuffer uses realloc() and free() so the buffer must be allocated
143                         // with malloc().
144                         AutoPtr<char, FreeCharPtr> messageBuffer((char*)malloc(messageLength + 1));
145                     #else
146 kumpf          1.1      AutoArrayPtr <char> messageBuffer (new char [messageLength + 1]);
147 mike           1.15 #endif
148 kumpf          1.1  
149                         //
150                         //  We know a message is coming
151                         //  Keep reading even if interrupted
152                         //
153                         do
154                         {
155                             readStatus = readBuffer (messageBuffer.get (), messageLength);
156                         } while (readStatus == STATUS_INTERRUPT);
157                     
158                         if (readStatus != STATUS_SUCCESS)
159                         {
160                             PEG_METHOD_EXIT ();
161                             return readStatus;
162                         }
163                     
164                         try
165                         {
166                             //
167                             //  De-serialize the message
168                             //
169 mike           1.16 #if defined(PEGASUS_ENABLE_PROTOCOL_INTERNAL_BINARY)
170 mike           1.15         // CIMBuffer frees messageBuffer upon destruction.
171                             CIMBuffer buf(messageBuffer.release(), messageLength);
172                             message = CIMBinMsgDeserializer::deserialize(buf, messageLength);
173                     
174                             if (!message)
175                             {
176                                 throw CIMException(CIM_ERR_FAILED, "deserialize() failed");
177                             }
178                     #else
179 kumpf          1.1          message = CIMMessageDeserializer::deserialize (messageBuffer.get ());
180 mike           1.15 #endif
181 kumpf          1.1      }
182                         catch (Exception & e)
183                         {
184                             //
185                             //  De-serialization failed
186                             //
187 thilo.boehm    1.14         PEG_TRACE ((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
188                                 "Failed to de-serialize message: %s",
189                                 (const char*)e.getMessage().getCString()));
190 kumpf          1.1          PEG_METHOD_EXIT ();
191                             throw;
192                         }
193                     
194                         PEG_METHOD_EXIT ();
195                         return readStatus;
196                     }
197                     
198                     PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2