xrubythread.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef xrubythreadH
15 #define xrubythreadH
16 //---------------------------------------------------------------------------
17 #include "xnode.h"
18 
19 #define RUBY_THREAD_ACTION_KILL "kill"
20 #define RUBY_THREAD_ACTION_WAKEUP "wakeup"
21 #define RUBY_THREAD_ACTION_FAILURE "failure"
22 #define RUBY_THREAD_ACTION_STARTING "starting"
23 
24 #define RUBY_THREAD_STATUS_RUN "run"
25 #define RUBY_THREAD_STATUS_SLEEP "sleep"
26 #define RUBY_THREAD_STATUS_ABORTING "aborting"
27 #define RUBY_THREAD_STATUS_STARTING "starting"
28 #define RUBY_THREAD_STATUS_N_A ""
29 //---------------------------------------------------------------------------
30 //! XRubyThread object is a communicator for Ruby thread.
31 //! \sa XRubySupport
32 class XRubyThread : public XNode {
33 public:
34  XRubyThread(const char *name, bool runtime, const XString &filename);
35  virtual ~XRubyThread() {}
36 
37  bool isRunning() const;
38  bool isAlive() const;
39  void kill();
40  void resume();
41 
42  //! def. input gets(). Return "" if the buffer is empty.
43  XString gets();
44  const shared_ptr<XStringNode> &lineinput() const {return m_lineinput;}
45 
46  const shared_ptr<XStringNode> &status() const {return m_status;}
47  const shared_ptr<XStringNode> &filename() const {return m_filename;}
48 // shared_ptr<XStringNode> &action() const {return m_action;}
49  const shared_ptr<XLongNode> &threadID() const {return m_threadID;}
50 
51  struct Payload : public XNode::Payload {
52  using Talker = Talker<shared_ptr<XString>>;
53  Talker &onMessageOut() {return m_tlkOnMessageOut;}
54  const Talker &onMessageOut() const {return m_tlkOnMessageOut;}
55  private:
56  Talker m_tlkOnMessageOut;
57  };
58 private:
59  const shared_ptr<XStringNode> m_filename;
60  shared_ptr<XStringNode> m_status;
61  shared_ptr<XStringNode> m_action;
62  shared_ptr<XStringNode> m_lineinput;
63  shared_ptr<XLongNode> m_threadID;
64  shared_ptr<XListener> m_lsnOnLineChanged;
65  void onLineChanged(const Snapshot &shot, XValueNodeBase *);
66  std::deque<XString> m_lineBuffer;
67  XMutex m_lineBufferMutex;
68 };
69 
70 //---------------------------------------------------------------------------
71 #endif

Generated for KAME4 by  doxygen 1.8.3