Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

scim_connection.h

Go to the documentation of this file.
00001 /** @file scim_connection.h
00002  * @brief C++ signal-slot connection interface.
00003  *
00004  * Most code of this file are came from Inti project.
00005  */
00006 
00007 /*
00008  * Smart Common Input Method
00009  * 
00010  * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
00011  * Copyright (c) 2003 James Su <suzhe@turbolinux.com.cn>
00012  * Copyright (c) 2002 James Su <suzhe@turbolinux.com.cn>
00013  * Copyright (c) 2002 The Inti Development Team.
00014  *
00015  *
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2 of the License, or (at your option) any later version.
00020  *
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  * GNU Lesser General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this program; if not, write to the
00028  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00029  * Boston, MA  02111-1307  USA
00030  *
00031  * $Id: scim_connection.h,v 1.8 2004/05/21 15:18:29 suzhe Exp $
00032  */
00033 
00034 #ifndef __SCIM_CONNECTION_H
00035 #define __SCIM_CONNECTION_H
00036 
00037 namespace scim {
00038 
00039 /**
00040  * @addtogroup SignalSlot
00041  * @{
00042  */
00043 
00044 class Slot;
00045 
00046 /**
00047  * @class Node 
00048  * @brief Base class for classes managing slots.
00049  * 
00050  * A node connects a slot to its Connection class, the class returned
00051  * from a signal's connect() method.
00052  */
00053 
00054 class Node : public ReferencedObject
00055 {
00056     Pointer <Slot> slot_;
00057 
00058 protected:
00059     Node(Slot *slot);
00060     //!< Constructor.
00061 
00062     virtual ~Node();
00063     //!< Destructor.
00064 
00065 public:
00066     Slot* slot() { return slot_.get (); }
00067     //!< Returns a pointer to the slot held by this node.
00068 
00069     virtual void block() = 0;
00070     //!< Block signal emission to the slot until unblock is called.
00071 
00072     virtual void unblock() = 0;
00073     //!< Unblock the slot so signal emmissions can be received.
00074 
00075     virtual void disconnect() = 0;
00076     //!< Disconnect the slot. The slot will no longer recieve signal emissions.
00077 };
00078 
00079 /**
00080  * @class Connection 
00081  * @brief A signal connection class.
00082  * 
00083  * A Connection class is returned by value from a signal's connect()
00084  * method. Using this class you can block, unblock and disconnect
00085  * a signal connection.
00086  */
00087 
00088 class Connection
00089 {
00090     mutable Pointer<Node> node_;
00091 
00092 public:
00093 //! @name Constructors
00094 //! @{
00095 
00096     Connection();
00097     //!< Default constructor.
00098 
00099     Connection(Node *node);
00100     //!< Construct a connection object for node.
00101     //!< @param node - a pointer to the Node class for this connection.
00102 
00103     Connection(const Connection& src);
00104     //!< Copy constructor.
00105 
00106     ~Connection();
00107     //!< Destructor.
00108 
00109     Connection& operator=(const Connection& src);
00110     //!< Assignment operator.
00111     
00112 //! @}
00113 //! @name Methods
00114 //! @{
00115 
00116     void block();
00117     //!< Block signal transmission to a slot.
00118     //!< The slot will not be called during any signal emissions unless it is unblocked again.
00119 
00120     void unblock();
00121     //!< Unblock a previously blocked slot.
00122     //!< A blocked slot is skipped during signal emissions and will not be invoked, unblocking
00123     //!< it (for exactly the number of times it has been blocked before) reverts its "blocked"
00124     //!< state, so the slot will be recognized by the signal system and is called upon future
00125     //!< or currently ongoing signal emissions.
00126 
00127     void disconnect();
00128     //!< Disconnect a slot.
00129     //!< The slot will not be called during any future or currently ongoing
00130     //!< emissions of the signal it has been connected to.
00131     
00132 //! @}
00133 };
00134 
00135 /** @} */
00136 
00137 } // namespace scim
00138 
00139 #endif //__SCIM_CONNECTION_H
00140 
00141 /*
00142 vi:ts=4:nowrap:ai:expandtab
00143 */
00144 

Generated on Tue Apr 19 00:10:59 2005 for scim by  doxygen 1.4.1