porting.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <!--
  5. Copyright Frank Mori Hess 2007-2009
  6. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <section last-revision="$Date: 2007-06-12 14:01:23 -0400 (Tue, 12 Jun 2007) $" id="signals2.api_changes">
  10. <title>Signals2 API Changes</title>
  11. <using-namespace name="boost::signals2"/>
  12. <using-namespace name="boost"/>
  13. <section id="signals2.porting">
  14. <title>Porting from Boost.Signals to Boost.Signals2</title>
  15. <para>The changes made to the Boost.Signals2 API compared to the original Boost.Signals
  16. library are summarized below. We also provide some notes on
  17. dealing with each change while porting existing Boost.Signals code to Boost.Signals2.
  18. </para>
  19. <itemizedlist>
  20. <listitem>
  21. <para>The namespace <code>boost::signals</code> has been replaced by <code>boost::signals2</code>
  22. to avoid conflict with the original Boost.Signals implementation, as well as the Qt "signals" macro.
  23. All the Boost.Signals2 classes are inside the <code>boost::signals2</code> namespace,
  24. unlike the original Boost.Signals which has some classes in the <code>boost</code>
  25. namespace in addition to its own <code>boost::signals</code> namespace.
  26. </para>
  27. <para>
  28. The Boost.Signals2 header files are contained in the
  29. <code>boost/signals2/</code> subdirectory instead of the <code>boost/signals</code>
  30. subdirectory used by the original Boost.Signals. Furthermore, all the headers except
  31. for the convenience header <code>boost/signals2.hpp</code> are inside the
  32. <code>boost/signals2/</code> subdirectory, unlike the original Boost.Signals which
  33. keeps a few headers in the parent <code>boost/</code> directory
  34. in addition to its own <code>boost/signals/</code> subdirectory.
  35. </para>
  36. <para>
  37. For example, the <code>signal</code> class is now
  38. in the <code>boost::signals2</code> namespace instead of the
  39. <code>boost</code> namespace,
  40. and it's header file is now at <code>boost/signals2/signal.hpp</code> instead of
  41. <code>boost/signal.hpp</code>.
  42. </para>
  43. <para>
  44. While porting, only trivial changes to <code>#include</code> directives
  45. and namespace qualifications should be required to deal with these changes.
  46. Furthermore, the new namespace and header locations for Boost.Signals2
  47. allow it to coexist in the same program with the original Boost.Signals library,
  48. and porting can be performed piecemeal.
  49. </para>
  50. </listitem>
  51. <listitem>
  52. <para>
  53. Automatic connection management is now achieved through the use of
  54. <classname>shared_ptr</classname>/<classname>weak_ptr</classname>
  55. and <methodname>signals2::slot::track</methodname>(), as described in the
  56. <link linkend="signals2.tutorial.connection-management">tutorial</link>.
  57. However, the old (thread-unsafe) Boost.Signals scheme of automatic connection management
  58. is still supported via the <classname>boost::signals2::trackable</classname> class.
  59. </para>
  60. <para>
  61. If you do not intend to make your program multi-threaded, the easiest porting path is to simply replace
  62. your uses of <classname>boost::signals::trackable</classname> as a base class with
  63. <classname>boost::signals2::trackable</classname>. Boost.Signals2 uses the same
  64. <functionname>boost::visit_each</functionname> mechanism to discover
  65. <code>trackable</code> objects
  66. as used by the original Boost.Signals library.
  67. </para>
  68. </listitem>
  69. <listitem>
  70. <para>Support for postconstructors (and predestructors) on objects managed by <classname>shared_ptr</classname>
  71. has been added with
  72. the <functionname>deconstruct</functionname> factory function.
  73. This was motivated by the importance of
  74. <code>shared_ptr</code> for the new connection tracking scheme, and the
  75. inability to obtain a <code>shared_ptr</code> to an object in its constructor.
  76. The use of <functionname>deconstruct</functionname> is described in the
  77. <link linkend="signals2.tutorial.deconstruct">tutorial</link>.
  78. </para>
  79. <para>
  80. The use of <functionname>deconstruct</functionname> is in no way required,
  81. it is only provided in the hope
  82. it may be useful. You may wish to use it if you are porting code where
  83. a class creates connections to its own member functions in its constructor,
  84. and you also
  85. wish to use the new automatic connection management scheme. You could then
  86. move the connection creation from the constructor to to the an
  87. <code>adl_postconstruct</code> function, where
  88. a reference to the owning <classname>shared_ptr</classname> is available for
  89. passing to <methodname>signals2::slot::track</methodname>.
  90. The <functionname>deconstruct</functionname> function would be used create objects
  91. of the class and run their associated <code>adl_postconstruct</code> function.
  92. You can enforce use of <functionname>deconstruct</functionname> by
  93. making the class' constructors private and declaring
  94. <classname>deconstruct_access</classname> a friend.
  95. </para>
  96. </listitem>
  97. <listitem>
  98. <para>
  99. The <classname>signals2::slot</classname> class takes a new <code>Signature</code> template parameter,
  100. is useable as a function object, and has some additional features to support the
  101. new Boost.Signals2 automatic connection management scheme.
  102. </para>
  103. <para>
  104. The changes to the slot class should generally not cause any porting difficulties,
  105. especially if you are using the <classname>boost::signals2::trackable</classname>
  106. compatibility class mentioned above. If you are converting your code over to
  107. use the new automatic connection management scheme, you will need to
  108. employ some of the new slot features, as described in the
  109. <link linkend="signals2.tutorial.connection-management">tutorial</link>.
  110. </para>
  111. </listitem>
  112. <listitem>
  113. <para>
  114. The <classname>optional_last_value</classname> class has replaced <code>last_value</code>
  115. as the default combiner for signals.
  116. </para>
  117. <para>
  118. The <classname>signals2::last_value</classname> combiner is still provided, although its
  119. behavior is slightly changed in that it
  120. throws an exception when no slots are connected on signal invocation, instead of
  121. always requiring at least one slot to be connected (except for its void specialization
  122. which never required any slots to be connected).
  123. </para>
  124. <para>
  125. If you are porting signals which have a <code>void</code> return type in their signature
  126. and they use the default combiner, there are no changes required. If you are
  127. using the default combiner with a non-void return type and care about the
  128. value returned from signal invocation, you will have to take into account that
  129. <classname>optional_last_value</classname> returns a
  130. <classname>boost::optional</classname> instead of a plain value. One simple
  131. way to deal with this is to use <code>boost::optional::operator*()</code> to access the
  132. value wrapped inside the returned <classname>boost::optional</classname>.
  133. </para>
  134. <para>
  135. Alternatively, you could do a port by specifying the <code>Combiner</code> template parameter
  136. for your <code>signals2::signal</code> to be <classname>signals2::last_value</classname>.
  137. </para>
  138. </listitem>
  139. <listitem>
  140. <para>
  141. The <classname>signals2::signal</classname> class has an additional typedef
  142. <classname>signals2::signal::extended_slot_type</classname>
  143. and new <methodname>signals2::signal::connect_extended</methodname>()
  144. methods. These allow connection of slots
  145. which take an additional <classname>signals2::connection</classname> argument, giving them thread-safe
  146. access to their signal/slot connection when they are invoked. There is also a
  147. new <code>ExtendedSlotFunction</code> template parameter for specifying the underlying slot function
  148. type for the new extended slots.
  149. </para>
  150. <para>
  151. These additions should have no effect on porting unless you are also converting
  152. your program from a single threaded program into a multi-threaded one. In that case,
  153. if you have slots which need access to their <classname>signals2::connection</classname>
  154. to the signal invoking them (for example to block or disconnect their connection)
  155. you may wish to connect the slots with
  156. <methodname>signals2::signal::connect_extended</methodname>().
  157. This also requires adding an additional connection argument to the slot.
  158. More information on how and why to use extended slots is available
  159. in the <link linkend="signals2.tutorial.extended-slot-type">tutorial</link>.
  160. </para>
  161. </listitem>
  162. <listitem>
  163. <para>
  164. The <classname>signals2::signal</classname> class has a new <code>Mutex</code> template parameter for specifying
  165. the mutex type used internally by the signal and its connections.
  166. </para>
  167. <para>
  168. The <code>Mutex</code> template parameter can be left to its default value of
  169. <classname>boost::signals2::mutex</classname> and should have little effect on porting.
  170. However, if you have a single-threaded program and are
  171. concerned about incuring a performance overhead from unneeded mutex locking, you may
  172. wish to use a different mutex for your signals such as <classname>dummy_mutex</classname>.
  173. See the <link linkend="signals2.tutorial.signal-mutex-template-parameter">tutorial</link>
  174. for more information on the <code>Mutex</code> parameter.
  175. </para>
  176. </listitem>
  177. <listitem>
  178. <para>The <code>signal::combiner()</code> method, which formerly returned a reference to the
  179. signal's combiner has been replaced by <methodname>signals2::signal::combiner</methodname>
  180. (which now returns the combiner by value) and <methodname>signals2::signal::set_combiner</methodname>.
  181. </para>
  182. <para>
  183. During porting it should be straightforward to replace uses of the old reference-returning
  184. <code>signal::combiner()</code>
  185. function with the new "by-value" <methodname>signals2::signal::combiner</methodname>
  186. and <methodname>signals2::signal::set_combiner</methodname> functions.
  187. However, you will need to inspect each call of the <code>combiner</code> method in your code
  188. to determine if your program logic has been broken by the changed
  189. return type.
  190. </para>
  191. </listitem>
  192. <listitem>
  193. <para>Connections no longer have <code>block()</code> and <code>unblock()</code> methods. Blocking
  194. of connections is now accomplished by creating <classname>shared_connection_block</classname> objects,
  195. which provide RAII-style blocking.
  196. </para>
  197. <para>
  198. If you have existing Boost.Signals code that blocks, for example:
  199. </para>
  200. <programlisting>
  201. namespace bs = boost::signals;
  202. bs::connection my_connection;
  203. //...
  204. my_connection.block();
  205. do_something();
  206. my_connection.unblock();
  207. </programlisting>
  208. <para>
  209. then the version ported to Boost.Signals2 would look like:
  210. </para>
  211. <programlisting>
  212. namespace bs2 = boost::signals2;
  213. bs2::connection my_connection;
  214. //...
  215. {
  216. bs2::shared_connection_block blocker(my_connection);
  217. do_something();
  218. } // blocker goes out of scope here and releases its block on my_connection
  219. </programlisting>
  220. </listitem>
  221. </itemizedlist>
  222. </section>
  223. <section id="signals2.api_history">
  224. <title>Signals2 API Development</title>
  225. <section id="signals2.api_history.1-56">
  226. <title>Version 1.56</title>
  227. <para>
  228. Version 1.56 modified the behavior of the signal destructor, in that it no longer
  229. explicitly calls disconnect_all_slots. Any signal invocations running
  230. concurrently with the signal destructor should now complete normally, rather
  231. than skipping all remaining slots. Once all concurrent signal invocations
  232. complete, all connections to the deleted signal will still ultimately
  233. be disconnected. This change brings Boost.Signals2
  234. behavior closer to the behavior of the original Boost.Signals library.
  235. </para>
  236. </section>
  237. <section id="signals2.api_history.1-45">
  238. <title>Version 1.45</title>
  239. <para>
  240. Version 1.45 added <methodname>slot::track_foreign</methodname>(). This method allows tracking
  241. of objects owned by <code>shared_ptr</code> classes other than <classname>boost::shared_ptr</classname>,
  242. for example <classname>std::shared_ptr</classname>.
  243. </para>
  244. </section>
  245. <section id="signals2.api_history.1-40">
  246. <title>Version 1.40</title>
  247. <para>
  248. Version 1.40 adds a few new features to the <classname>shared_connection_block</classname>
  249. class to make it more flexible:
  250. <itemizedlist>
  251. <listitem>
  252. <para>
  253. <classname>shared_connection_block</classname> is now default constructible.
  254. </para>
  255. </listitem>
  256. <listitem>
  257. <para>
  258. A <classname>shared_connection_block</classname> may now be constructed without
  259. immediately blocking its connection.
  260. </para>
  261. </listitem>
  262. <listitem>
  263. <para>
  264. The <methodname>shared_connection_block::connection</methodname>() query has been
  265. added, to provide access to the <code>shared_connection_block</code>s associated
  266. connection.
  267. </para>
  268. </listitem>
  269. </itemizedlist>
  270. </para>
  271. <para>Version 1.40 also introduces a variadic templates implementation of
  272. Signals2, which is used when Boost detects compiler support for variadic templates
  273. (variadic templates are a new feature of C++11).
  274. This change is mostly transparent to the user, however it does introduce a few
  275. visible tweaks to the interface as described in the following.
  276. </para>
  277. <para>
  278. The following library features are
  279. deprecated, and are only available if your compiler is NOT using
  280. variadic templates (i.e. BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined
  281. by Boost.Config).
  282. <itemizedlist>
  283. <listitem>
  284. <para>
  285. The "portable syntax" signal and slot classes, i.e. signals2::signal0, signal1, etc.
  286. </para>
  287. </listitem>
  288. <listitem>
  289. <para>
  290. The arg1_type, arg2_type, etc. member typedefs in the <classname>signals2::signal</classname> and
  291. <classname>signals2::slot</classname> classes. They are replaced by the
  292. template member classes <classname>signals2::signal::arg</classname> and
  293. <classname>signals2::slot::arg</classname>.
  294. </para>
  295. </listitem>
  296. </itemizedlist>
  297. </para>
  298. </section>
  299. <section id="signals2.api_history.1-39">
  300. <title>Version 1.39</title>
  301. <para>Version 1.39 is the first release of Boost to include the Signals2 library.</para>
  302. </section>
  303. </section>
  304. </section>