Public Member Functions | Private Attributes

ACE_Log_Msg_IPC Class Reference

Defines the interfaces for ACE_Log_Msg backend. More...

#include <Log_Msg_IPC.h>

Inheritance diagram for ACE_Log_Msg_IPC:
Inheritance graph
[legend]
Collaboration diagram for ACE_Log_Msg_IPC:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ACE_Log_Msg_IPC (void)
 Constructor.
virtual ~ACE_Log_Msg_IPC (void)
 Destructor.
virtual int open (const ACE_TCHAR *logger_key)
 Open a new connection.
virtual int reset (void)
virtual int close (void)
 Close the backend completely.
virtual ssize_t log (ACE_Log_Record &log_record)

Private Attributes

ACE_LOG_MSG_IPC_STREAM message_queue_

Detailed Description

Defines the interfaces for ACE_Log_Msg backend.

Implement an ACE_Log_Msg_Backend that logs to a remote logging process.

Definition at line 51 of file Log_Msg_IPC.h.


Constructor & Destructor Documentation

ACE_Log_Msg_IPC::ACE_Log_Msg_IPC ( void   ) 

Constructor.

Definition at line 12 of file Log_Msg_IPC.cpp.

{
}

ACE_Log_Msg_IPC::~ACE_Log_Msg_IPC ( void   )  [virtual]

Destructor.

Definition at line 16 of file Log_Msg_IPC.cpp.

{
  (void) this->close ();
}


Member Function Documentation

int ACE_Log_Msg_IPC::close ( void   )  [virtual]

Close the backend completely.

Implements ACE_Log_Msg_Backend.

Definition at line 42 of file Log_Msg_IPC.cpp.

{
  return this->message_queue_.close ();
}

ssize_t ACE_Log_Msg_IPC::log ( ACE_Log_Record log_record  )  [virtual]

Process a log record.

Parameters:
log_record The ACE_Log_Record to process.
Return values:
-1 for failure; else it is customarily the number of bytes processed, but can also be 0 to signify success.

Implements ACE_Log_Msg_Backend.

Definition at line 48 of file Log_Msg_IPC.cpp.

{
  // Serialize the log record using a CDR stream, allocate enough
  // space for the complete <ACE_Log_Record>.
  size_t const max_payload_size =
    4    // type
    + 4  // pid
    + 12 // timestamp
    + 4  // process id
    + 4  // data length
#if defined (ACE_USES_WCHAR)
    + (log_record.msg_data_len () * ACE_OutputCDR::wchar_maxbytes())  // message
#else
    + log_record.msg_data_len () // message
#endif
    + ACE_CDR::MAX_ALIGNMENT;     // padding;

  // Insert contents of <log_record> into payload stream.
  ACE_OutputCDR payload (max_payload_size);
  if (!(payload << log_record))
    return -1;

  // Get the number of bytes used by the CDR stream. If it becomes desireable
  // to support payloads more than 4GB, this field will need to be changed
  // to a 64-bit value.
  ACE_CDR::ULong const length =
    ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length ());

  // Send a header so the receiver can determine the byte order and
  // size of the incoming CDR stream.
  ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
  if (!(header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER)))
   return -1;

  // Store the size of the payload that follows
  if (!(header << ACE_CDR::ULong (length)))
   return -1;

  // Use an iovec to send both buffer and payload simultaneously.
  iovec iov[2];
  iov[0].iov_base = header.begin ()->rd_ptr ();
  iov[0].iov_len  = 8;
  iov[1].iov_base = payload.begin ()->rd_ptr ();
  iov[1].iov_len  = length;

#if (ACE_HAS_STREAM_LOG_MSG_IPC == 1)
  // Use the <putpmsg> API if supported to ensure correct message
  // queueing according to priority.

  ACE_Str_Buf header_msg (static_cast<void *> (header.begin ()->rd_ptr ()),
                          static_cast<int> (8));

  ACE_Str_Buf payload_msg (static_cast<void *> (payload.begin ()->rd_ptr ()),
                           static_cast<int> (length));

  return this->message_queue_.send (&header_msg,
                                    &payload_msg,
                                    static_cast<int> (log_record.priority ()),
                                    MSG_BAND);
#else
  // We're running over sockets, so send header and payload
  // efficiently using "gather-write".
  return this->message_queue_.sendv_n (iov, 2);
#endif /* ACE_HAS_STREAM_LOG_MSG_IPC */
}

int ACE_Log_Msg_IPC::open ( const ACE_TCHAR logger_key  )  [virtual]

Open a new connection.

Implements ACE_Log_Msg_Backend.

Definition at line 22 of file Log_Msg_IPC.cpp.

{
  ACE_LOG_MSG_IPC_CONNECTOR con;
  return con.connect (this->message_queue_,
                      ACE_LOG_MSG_IPC_ADDR (logger_key));
}

int ACE_Log_Msg_IPC::reset ( void   )  [virtual]

Reset the backend. When changing the logging destination the backend may need to properly disconnect from the remote logging daemon and reclaim some local resources. But we try to reduce the number of local allocations/deallocations.

Implements ACE_Log_Msg_Backend.

Definition at line 30 of file Log_Msg_IPC.cpp.

{
  if (this->message_queue_.get_handle () != ACE_INVALID_HANDLE)
    {
      // If we don't do this, handles aren't reused on Win32 and the
      // server eventually crashes!
      return this->close ();
    }
  return 0;
}


Member Data Documentation

Definition at line 75 of file Log_Msg_IPC.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines