Browse Source

MsgPump Snippet

Carl Olsen 5 years ago
parent
commit
b78f8340c9
3 changed files with 98 additions and 4 deletions
  1. 24 4
      README.md
  2. 57 0
      c++-mode/msgPump
  3. 17 0
      doc/Doc.org

+ 24 - 4
README.md

@@ -1,5 +1,25 @@
-# YasThreads
+<div id="table-of-contents">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents">
+<ul>
+<li><a href="#sec-1">1. Yas-Threads</a></li>
+</ul>
+</div>
+</div>
 
-This repository will be the developement of
-Yassnippet to create message pump skeleton.
-That is a thread based system.
+# Yas-Threads<a id="sec-1" name="sec-1"></a>
+
+Threads are great, coding it is not so much fun.
+Well, at least not writing it by hand. So by doing a YASnippet that do
+the boring work it is possible to focus on more fun things.
+
+This snippet will create a skeleton class for a message pump.
+A message pump is a thread-based system that together with a queue
+receives a call and adds a (function) object to the queue, when the thread is
+ready it pulls the message and executes the object. This means that
+every call to the interface will be asynchronous, and returns
+immediately. The execution of the call will be based on when and where
+the thread is located in the queue. Its possible to add priority to
+the queue, but this is not done in this implementation. As mentioned
+before it is just a skeleton, its up to the user to actually do the
+fun stuff of creating what is needed.

+ 57 - 0
c++-mode/msgPump

@@ -0,0 +1,57 @@
+# -*- mode: snippet -*-
+# name: Message pump
+# key: msgPump
+# group: col
+# --
+
+#include <functional>
+#include <thread>
+
+/**
+* \class ${1:`(file-name-nondirectory (file-name-sans-extension (buffer-file-name)))`}
+* \brief short description of class $1
+*
+*
+* $0 This class runs asynchronous, this should be a longer description.
+* \addtogroup $1
+*/
+
+class $1
+{
+public:
+  /** 
+   * Typedef for message pump function, these are to 
+   * placed in the message queue
+   */
+  typedef std::function< bool () > FunT;
+  /**
+   * Typedef message queue, where functions are placed
+   */
+  typedef Util::Queue< FunT > FunctionMsgQueueT;
+
+  /**
+   * \brief $2 short description
+   * 
+   *  $2 Longer description
+   */
+  void ${2:startSystem}();
+
+  /**
+   * \brief $3 short description
+   * 
+   *  $3 Longer description
+   */
+  void ${3:stopSystem}();
+
+private:
+  /**
+   * \brief Thread runnable method
+   * 
+   * This message is where the thread is executing.
+   */
+  void ${4:run}();
+  /** Current thread */
+  std::thread *${5:itsThread_};
+  /** Current message queue*/
+  FunctionMsgQueueT ${6:itsQueue_};
+};

+ 17 - 0
doc/Doc.org

@@ -0,0 +1,17 @@
+* Yas-Threads
+Threads are great, coding it is not so much fun.
+Well, at least not writing it by hand. So by doing a YASnippet that do
+the boring work it is possible to focus on more fun things.
+
+This snippet will create a skeleton class for a message pump.
+A message pump is a thread-based system that together with a queue
+receives a call and adds a (function) object to the queue, when the thread is
+ready it pulls the message and executes the object. This means that
+every call to the interface will be asynchronous, and returns
+immediately. The execution of the call will be based on when and where
+the thread is located in the queue. Its possible to add priority to
+the queue, but this is not done in this implementation. As mentioned
+before it is just a skeleton, its up to the user to actually do the
+fun stuff of creating what is needed.
+
+