00001
00002
00003 #include "ace/Log_Msg_IPC.h"
00004 #include "ace/Log_Record.h"
00005 #include "ace/CDR_Stream.h"
00006
00007 ACE_RCSID(ace, Log_Msg_IPC, "Log_Msg_IPC.cpp,v 4.9 2006/05/26 21:49:34 schmidt Exp")
00008
00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 ACE_Log_Msg_IPC::ACE_Log_Msg_IPC (void)
00012 {
00013 }
00014
00015 ACE_Log_Msg_IPC::~ACE_Log_Msg_IPC (void)
00016 {
00017 (void) this->close ();
00018 }
00019
00020 int
00021 ACE_Log_Msg_IPC::open (const ACE_TCHAR *logger_key)
00022 {
00023 ACE_LOG_MSG_IPC_CONNECTOR con;
00024 return con.connect (this->message_queue_,
00025 ACE_LOG_MSG_IPC_ADDR (logger_key));
00026 }
00027
00028 int
00029 ACE_Log_Msg_IPC::reset (void)
00030 {
00031 if (this->message_queue_.get_handle () != ACE_INVALID_HANDLE)
00032 {
00033
00034
00035 return this->close ();
00036 }
00037 return 0;
00038 }
00039
00040 int
00041 ACE_Log_Msg_IPC::close (void)
00042 {
00043 return this->message_queue_.close ();
00044 }
00045
00046 int
00047 ACE_Log_Msg_IPC::log (ACE_Log_Record &log_record)
00048 {
00049
00050
00051 const size_t max_payload_size =
00052 4
00053 + 8
00054 + 4
00055 + 4
00056 + ACE_Log_Record::MAXLOGMSGLEN
00057 + ACE_CDR::MAX_ALIGNMENT;
00058
00059
00060 ACE_OutputCDR payload (max_payload_size);
00061 payload << log_record;
00062
00063
00064 ACE_CDR::ULong length = payload.total_length ();
00065
00066
00067
00068 ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
00069 header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
00070
00071
00072 header << ACE_CDR::ULong (length);
00073
00074
00075 iovec iov[2];
00076 iov[0].iov_base = header.begin ()->rd_ptr ();
00077 iov[0].iov_len = 8;
00078 iov[1].iov_base = payload.begin ()->rd_ptr ();
00079 iov[1].iov_len = length;
00080
00081 #if defined (ACE_HAS_STREAM_PIPES)
00082
00083
00084
00085 ACE_Str_Buf header_msg (static_cast<void *> (header.begin ()->rd_ptr ()),
00086 static_cast<int> (8));
00087
00088 ACE_Str_Buf payload_msg (static_cast<void *> (payload.begin ()->rd_ptr ()),
00089 static_cast<int> (length));
00090
00091 return this->message_queue_.send (&header_msg,
00092 &payload_msg,
00093 static_cast<int> (log_record.priority ()),
00094 MSG_BAND);
00095 #else
00096
00097
00098 return this->message_queue_.sendv_n (iov, 2);
00099 #endif
00100 }
00101
00102 ACE_END_VERSIONED_NAMESPACE_DECL