Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / C++NPv1 / Logging_Handler.h
blob4cfb7960bd141daba550dd5ab9682998f194afb5
1 /*
2 ** Copyright 2001 Addison Wesley. All Rights Reserved.
3 */
5 #ifndef _LOGGING_HANDLER_H
6 #define _LOGGING_HANDLER_H
8 #include "ace/FILE_IO.h"
9 #include "ace/SOCK_Stream.h"
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 class ACE_Message_Block;
13 ACE_END_VERSIONED_NAMESPACE_DECL
15 class Logging_Handler
17 protected:
18 ACE_FILE_IO &log_file_; // Reference to a log file.
20 ACE_SOCK_Stream logging_peer_; // Connected to the client.
22 public:
23 // Initialization and termination methods.
24 Logging_Handler (ACE_FILE_IO &log_file): log_file_ (log_file) {}
25 Logging_Handler (ACE_FILE_IO &log_file,
26 ACE_HANDLE handle): log_file_ (log_file)
27 { logging_peer_.set_handle (handle); }
28 Logging_Handler (ACE_FILE_IO &log_file,
29 const ACE_SOCK_Stream &logging_peer)
30 : log_file_ (log_file), logging_peer_ (logging_peer) {}
31 int close () { return logging_peer_.close (); }
33 // Receive one log record from a connected client. Returns
34 // length of record on success and <mblk> contains the
35 // hostname, <mblk->cont()> contains the log record header
36 // (the byte order and the length) and the data. Returns -1 on
37 // failure or connection close.
38 int recv_log_record (ACE_Message_Block *&log_record);
40 // Write one record to the log file. The <mblk> contains the
41 // hostname and the <mblk->cont> contains the log record.
42 // Returns length of record written on success, or -1 on failure.
43 int write_log_record (ACE_Message_Block *log_record);
45 // Log one record by calling <recv_log_record> and
46 // <write_log_record>. Returns 0 on success and -1 on failure.
47 int log_record ();
49 // Accessor method.
50 ACE_SOCK_Stream &peer () { return logging_peer_; }
53 #endif /* _LOGGING_HANDLER_H */