[libvtemm] Fix a bug in Master class. This causes another API version bump.



commit adfa3743d8fbb5f497b3f0eb3f2e8391ffc0670f
Author: Krzesimir Nowak <krnowak svn gnome org>
Date:   Tue Jul 21 21:31:05 2009 +0200

    Fix a bug in Master class. This causes another API version bump.
    
    * configure.ac: Bumped minor API version to 2 and current so
    version to 8.
    * src/libvtemm/ptymaster.cc:
    * src/libvtemm/ptymaster.h: Now close() in destructor will be
    called when instance is main instance. Added getter and setter for
    main. Updated documentation. open() will set instance as main.
    Added copy constructor, which will create non-main copy instances.

 configure.ac              |    4 ++--
 src/libvtemm/ptymaster.cc |   27 ++++++++++++++++++++++++---
 src/libvtemm/ptymaster.h  |   36 +++++++++++++++++++++++++++++-------
 3 files changed, 55 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d60f972..236c11c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ m4_define([PACKAGEMM_MICRO_VERSION], [4])
 m4_define([PACKAGEMM_RELEASE], [PACKAGEMM_MAJOR_VERSION.PACKAGEMM_MINOR_VERSION])
 m4_define([PACKAGEMM_VERSION], [PACKAGEMM_RELEASE.PACKAGEMM_MICRO_VERSION])
 m4_define([PACKAGEMM_API_MAJOR_VERSION], [1])
-m4_define([PACKAGEMM_API_MINOR_VERSION], [1])
+m4_define([PACKAGEMM_API_MINOR_VERSION], [2])
 m4_define([PACKAGEMM_API_VERSION], [PACKAGEMM_API_MAJOR_VERSION.PACKAGEMM_API_MINOR_VERSION])
 m4_define([PACKAGEMM_C_NAME], [vte])
 m4_define([PACKAGEMM_NAME], [lib]PACKAGEMM_C_NAME[mm])
@@ -35,7 +35,7 @@ AC_CONFIG_MACRO_DIR([scripts])
 #  ? :+1 : ?   == just some internal changes, nothing breaks but might work 
 #                 better
 # CURRENT : REVISION : AGE
-LIBVTEMM_SO_VERSION=7:0:0
+LIBVTEMM_SO_VERSION=8:0:0
 
 AC_SUBST([LIBVTEMM_SO_VERSION])
 
diff --git a/src/libvtemm/ptymaster.cc b/src/libvtemm/ptymaster.cc
index a81e5ae..67fe397 100644
--- a/src/libvtemm/ptymaster.cc
+++ b/src/libvtemm/ptymaster.cc
@@ -33,14 +33,21 @@ namespace Vte
 namespace Pty
 {
 
-Master::Master(int d)
+Master::Master(int d, bool is_main)
 :
-  m_d(d)
+  m_d(d),
+  m_is_main(is_main)
+{}
+
+Master::Master(const Master& master)
+:
+  m_d(master.m_d),
+  m_is_main(false)
 {}
 
 Master::~Master()
 {
-  if (m_d != -1)
+  if ((m_d != -1) && (is_main))
   {
     close();
   }
@@ -66,6 +73,7 @@ Master::open(const std::string& command,
   m_d = _vte_pty_open(&child, c_env_add, c_command, c_argv, c_directory, columns, rows, static_cast<gboolean>(lastlog), static_cast<gboolean>(utmp), static_cast<gboolean>(wtmp));
   g_strfreev(c_env_add);
   g_strfreev(c_argv);
+  m_is_main = true;
   return child;
 }
 
@@ -109,6 +117,19 @@ Master::close()
 {
   _vte_pty_close(m_d);
   m_d = -1;
+  m_is_main = false;
+}
+
+void
+Master::set_is_main(bool setting)
+{
+  m_is_main = setting;
+}
+
+bool
+Master::get_is_main() const
+{
+  return m_is_main;
 }
 
 } // namespace Pty
diff --git a/src/libvtemm/ptymaster.h b/src/libvtemm/ptymaster.h
index cebff77..6d16f5c 100644
--- a/src/libvtemm/ptymaster.h
+++ b/src/libvtemm/ptymaster.h
@@ -39,20 +39,29 @@ namespace Pty
 class Master
 {
 public:
+  
   /** Sets descriptor for the master side of PTY pair to @a d. Use other than
-   * default value at your own risk. Otherwise
-   * use open() to set a descriptor.
+   * default value at your own risk. Otherwise use open() to set a descriptor.
+   * It allows you to set this instance as a main instance.
    * @param d Descriptor for the master side of PTY pair. -1 by default.
+   * @param is_main Setting for main instance.
+   */
+  Master(int d = -1, bool is_main = false);
+  
+  /** Just a copy constructor. Copied instance won't be a main instance even if
+   * original is.
+   * @param master Original master to copy.
    */
-  Master(int d = -1);
-  /** If master side of PTY pair is not equal to -1, it calls close().
-   * Otherwise it do nothing.
+  Master(const Master& master);
+  
+  /** If master side of PTY pair is not equal to -1 and is set as main, it calls
+   * close(). Otherwise it does nothing.
    */
   ~Master();
 
   /** Start up the given binary (exact path, not interpreted at all) in a
    * pseudo-terminal of its own, returning the child's PID and logging the
-   * session to the specified files.
+   * session to the specified files. Sets this instance as main instance.
    * @param command Command to be executed (not interpreted at all). If empty, fork will be executed.
    * @param argv Empty string terminated list of arguments given to executed binary (argv[0] should be a binary name). See Gnome::Vte::Terminal::fork_command() for description about format of this parameter.
    * @param env_add Empty string terminated list of environment variables to be added before executing a command. See Gnome::Vte::Terminal::fork_command() for description about format of this parameter.
@@ -100,11 +109,24 @@ public:
    */
   int get_pty() const;
 
-  /** Close a pty. This is also called in destructor.
+  /** Close a pty.
    */
   void close();
+  
+  /** Sets this instance as main instance holding descriptor of the master side
+   * of PTY pair. If this instance is main instance, then on its destruction
+   * close() will be called. This setting is not copied.
+   * @param setting @c true if this instance is main instance.
+   */
+  void set_is_main(bool setting = true);
+  
+  /** Checks if this instance is main instance.
+   * @return @c true if this instance is main instance.
+   */
+  bool get_is_main() const;
 private:
   int m_d;
+  bool m_is_main;
 };
 
 } // namespace Pty



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]