00001 // -*- C++ -*- 00002 // vim:ts=8 sts=4 sw=4 00003 00004 // ***** BEGIN LICENSE BLOCK ***** 00005 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00006 // 00007 // The contents of this file are subject to the Mozilla Public License 00008 // Version 1.1 (the "License"); you may not use this file except in 00009 // compliance with the License. You may obtain a copy of the License at 00010 // http://www.mozilla.org/MPL/ 00011 // 00012 // Software distributed under the License is distributed on an "AS IS" 00013 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00014 // the License for the specific language governing rights and limitations 00015 // under the License. 00016 // 00017 // The Original Code is the consmgr network/serial-line monitoring package. 00018 // 00019 // The Initial Developer of the Original Code is Chris P. Ross. 00020 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00021 // the Initial Developer. All Rights Reserved. 00022 // 00023 // Contributor(s): 00024 // Geoff Adams 00025 // 00026 // Alternatively, the contents of this file may be used under the terms of 00027 // either the GNU General Public License Version 2 or later (the "GPL"), or 00028 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00029 // in which case the provisions of the GPL or the LGPL are applicable instead 00030 // of those above. If you wish to allow use of your version of this file only 00031 // under the terms of either the GPL or the LGPL, and not to allow others to 00032 // use your version of this file under the terms of the MPL, indicate your 00033 // decision by deleting the provisions above and replace them with the notice 00034 // and other provisions required by the GPL or the LGPL. If you do not delete 00035 // the provisions above, a recipient may use your version of this file under 00036 // the terms of any one of the MPL, the GPL or the LGPL. 00037 // 00038 // ***** END LICENSE BLOCK ***** 00039 00040 #ifndef __CONNECTOR_H 00041 #define __CONNECTOR_H 00042 00043 #include <loki/SmartPtr.h> 00044 00045 #include "message.h" 00046 #include "messager.h" 00047 00065 class Connector 00066 #if 0 00067 : protected Messager 00068 #endif 00069 { 00070 public: 00071 virtual ~Connector() {} 00072 00082 virtual void disconnect() = 0; 00083 00085 // The owning object is expected to delete this object once it receives 00086 // this message; there is nothing more to be done with it. 00087 // Always make sure you delete the Connector object before the given 00088 // Messageable stops being capable of receiving Messages. 00089 #if 0 00090 virtual void notify_on_disconnect(const Messageable *owner) = 0; 00091 #endif 00092 00093 // Read a blob of data from the underlying connection. The caller is 00094 // responsible for freeing the returned Data object. 00095 virtual Data *read() = 0; 00096 00098 virtual ssize_t write(const Data &b) = 0; 00099 00101 virtual std::string get_id() const = 0; 00102 00103 // XXX - We haven't considered our reconnection strategy, yet, but when 00104 // we do, it might involve adding methods like the following. Right now, 00105 // we expect that when a disconnection message is sent out, the owning 00106 // object will simply delete us. 00107 //virtual bool can_reconnect() = 0; 00108 //virtual void reconnect() = 0; 00109 00111 virtual bool connected() const = 0; 00112 00113 protected: 00116 static const size_t BufSize = 4096; 00117 00118 }; 00119 00125 typedef Loki::SmartPtr<Connector, 00126 Loki::RefCountedMTAdj<Loki::ObjectLevelLockable>::RefCountedMT> 00127 ConnectorP; 00128 00131 #endif /* __CONNECTOR_H */