00001 // -*- C++ -*- 00002 // vim:shiftwidth=4 sts=4 00003 00004 // outlet.h - This file defines an Outlet class. An Outlet is an object 00005 // that can be sent data. Connections can send data to Outlets, but 00006 // Outlets never send data anywhere. They only receive data. An object 00007 // that implements the sending of data is BiDirConn (a subclass of Outlet). 00008 // 00009 // $Id: outlet.h 384 2008-05-08 18:09:56Z cross $ 00010 00011 // ***** BEGIN LICENSE BLOCK ***** 00012 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00013 // 00014 // The contents of this file are subject to the Mozilla Public License 00015 // Version 1.1 (the "License"); you may not use this file except in 00016 // compliance with the License. You may obtain a copy of the License at 00017 // http://www.mozilla.org/MPL/ 00018 // 00019 // Software distributed under the License is distributed on an "AS IS" 00020 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00021 // the License for the specific language governing rights and limitations 00022 // under the License. 00023 // 00024 // The Original Code is the consmgr network/serial-line monitoring package. 00025 // 00026 // The Initial Developer of the Original Code is Chris P. Ross. 00027 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00028 // the Initial Developer. All Rights Reserved. 00029 // 00030 // Contributor(s): 00031 // 00032 // Alternatively, the contents of this file may be used under the terms of 00033 // either the GNU General Public License Version 2 or later (the "GPL"), or 00034 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00035 // in which case the provisions of the GPL or the LGPL are applicable instead 00036 // of those above. If you wish to allow use of your version of this file only 00037 // under the terms of either the GPL or the LGPL, and not to allow others to 00038 // use your version of this file under the terms of the MPL, indicate your 00039 // decision by deleting the provisions above and replace them with the notice 00040 // and other provisions required by the GPL or the LGPL. If you do not delete 00041 // the provisions above, a recipient may use your version of this file under 00042 // the terms of any one of the MPL, the GPL or the LGPL. 00043 // 00044 // ***** END LICENSE BLOCK ***** 00045 00046 #ifndef __OUTLET_H 00047 #define __OUTLET_H 00048 00049 extern "C" { 00050 #include <pthread.h> 00051 #include <signal.h> 00052 #include <string.h> 00053 #include <unistd.h> 00054 } 00055 00056 #include <deque> 00057 #include <set> 00058 #include <map> 00059 00060 #include <string> 00061 00062 #include "protocol.h" 00063 #include "connection.h" 00064 #include "connector.h" 00065 #include "consmgr.h" 00066 00070 class Outlet : public Connection { 00071 public: 00073 Outlet(ConnectorP&); 00074 virtual ~Outlet() throw(); 00075 00077 void queue_data(MessageP&); 00078 00080 void add_decoder(Decoder*); 00081 00082 virtual std::string class_name(void) const { return("Outlet"); }; 00083 virtual std::string get_id(void) const; 00084 00085 protected: 00087 void start_engine(void); 00088 00089 #ifdef SHOULD_NOT_BE_HERE 00090 // XXX - Should these be here? Does a Connection know how to keep/modify 00091 // connected state? If so, we need a lot more state stuff back... 00092 00093 // Connect. ?! Should this do anything? 00094 void connect() { }; 00096 void disconnect(); 00097 #endif 00098 00099 private: 00103 static void *writer_thread(void *); 00104 00106 void writer(void); 00107 00108 // this is called by writer to iterate the data deque and write 00109 // the data 00110 void write_data(); 00111 00113 pthread_t tid_writer; 00114 00115 // XXX - Should we have a wrapper class for this, to protect it 00116 // with a mutex? 00117 // *protocol handler* 00118 00119 protected: 00121 virtual void stop_engine(void); 00122 00123 private: 00125 std::deque<MessageP> data; 00127 pthread_mutex_t data_mutex; 00129 pthread_cond_t data_avail; 00131 typedef std::deque<MessageP>::iterator queue_iterator; 00132 00133 #if MAYBE_A_BAD_IDEA 00134 // A string to cache the ID of the outlet. Set/accessed by the 00135 // virtual get_id() function of the subclasses. 00136 std::string id_cache; 00137 #endif 00138 00139 #if 0 00140 // A global OutletList that contains the list of *all* outlets 00141 // is use by application. Also a friend class, because it needs 00142 // to know, upon destruction, if it's *this* master outlet list. 00143 // **Needs to move up to the MasterProcessController** 00144 static OutletList outlet_list; 00145 friend class OutletList; 00146 #endif 00147 }; 00148 00149 #endif /* __OUTLET_H */