log4cplus  2.0.0
connectorthread.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //  Copyright (C) 2013-2015, Vaclav Zeman. All rights reserved.
00003 //  
00004 //  Redistribution and use in source and binary forms, with or without modifica-
00005 //  tion, are permitted provided that the following conditions are met:
00006 //  
00007 //  1. Redistributions of  source code must  retain the above copyright  notice,
00008 //     this list of conditions and the following disclaimer.
00009 //  
00010 //  2. Redistributions in binary form must reproduce the above copyright notice,
00011 //     this list of conditions and the following disclaimer in the documentation
00012 //     and/or other materials provided with the distribution.
00013 //  
00014 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
00015 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00016 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
00017 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
00018 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
00019 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
00020 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
00021 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
00022 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
00023 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024 
00025 #ifndef LOG4CPLUS_HELPERS_CONNECTORTHREAD_H
00026 #define LOG4CPLUS_HELPERS_CONNECTORTHREAD_H
00027 
00028 #include <log4cplus/config.hxx>
00029 
00030 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00031 #pragma once
00032 #endif
00033 
00034 #include <log4cplus/thread/syncprims.h>
00035 #include <log4cplus/thread/threads.h>
00036 #include <log4cplus/helpers/socket.h>
00037 
00038 
00039 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
00040 
00041 namespace log4cplus { namespace helpers {
00042 
00043 
00044 class LOG4CPLUS_EXPORT ConnectorThread;
00045 
00047 class LOG4CPLUS_EXPORT IConnectorThreadClient
00048 {
00049 protected:
00050     virtual ~IConnectorThreadClient ();
00051 
00054     virtual thread::Mutex const & ctcGetAccessMutex () const = 0;
00055 
00057     virtual helpers::Socket & ctcGetSocket () = 0;
00058 
00061     virtual helpers::Socket ctcConnect () = 0;
00062 
00064     virtual void ctcSetConnected () = 0;
00065 
00066     friend class LOG4CPLUS_EXPORT ConnectorThread;
00067 };
00068 
00069 
00072 class LOG4CPLUS_EXPORT ConnectorThread
00073     : public thread::AbstractThread
00074 {
00075 public:
00077     ConnectorThread (IConnectorThreadClient & client);
00078     virtual ~ConnectorThread ();
00079     
00080     virtual void run();
00081 
00085     void terminate ();
00086 
00089     void trigger ();
00090     
00091 protected:
00093     IConnectorThreadClient & ctc;
00094 
00096     thread::ManualResetEvent trigger_ev;
00097 
00099     bool exit_flag;
00100 };
00101 
00102 
00103 } } // namespace log4cplus { namespace helpers {
00104 
00105 #endif // ! defined (LOG4CPLUS_SINGLE_THREADED)
00106 
00107 #endif // LOG4CPLUS_HELPERS_CONNECTORTHREAD_H