HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HOM_ShellIO.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __HOM_ShellIO_h__
10 #define __HOM_ShellIO_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Module.h"
14 #include <string>
15 #include <hboost/tuple/tuple.hpp>
16 
17 SWIGOUT(%rename(ShellIO) HOM_ShellIO;)
18 
20 {
21 public:
23  { HOM_CONSTRUCT_OBJECT(this) }
25  { HOM_CONSTRUCT_OBJECT(this) }
26  virtual ~HOM_ShellIO()
27  { HOM_DESTRUCT_OBJECT(this) }
28 
29  // When this object is sys.stdin, python will call readline() to read
30  // a command.
31 #ifdef SWIG
32 %extend {
33  %kwargs readline;
34  InterpreterObject readline(int size=-1)
35  {
36  // readline() is just a wrapper around readlineWithKeyboardInterrupt().
37  // We need a way of knowing if this function raised a KeyboardInterrupt
38  // exception, though.
39  hboost::tuple<std::string, bool> result =
40  self->readlineWithKeyboardInterrupt(size);
41  if (result.get<1>())
42  {
43  // A KeyboardInterrupt exception has been set. Return NULL
44  // to let python know to check for an exception.
45  return NULL;
46  }
47  return HOMconvertValueForInterpreter(result.get<0>(), SWIG_POINTER_OWN);
48  }
49 
50  void addCloseCallback(InterpreterObject callback)
51  { self->addOpaqueCloseCallback(callback); }
52 
53  void removeCloseCallback(InterpreterObject callback)
54  { self->removeOpaqueCloseCallback(callback); }
55 
56  // Note that we return a vector of borrowed references because swig
57  // will increment the reference counts.
58  std::vector<InterpreterObject> CloseCallbacks()
59  {
60  std::vector<void *> opaque_callbacks(self->opaqueCloseCallbacks());
61 
62  std::vector<InterpreterObject> callbacks;
63  for (int i=0; i < opaque_callbacks.size(); ++i)
64  callbacks.push_back((InterpreterObject)opaque_callbacks[i]);
65  return callbacks;
66  }
67 
68  // These methods are deprecated and can be removed in the future:
69  void addExitCallback(InterpreterObject callback)
70  { self->addOpaqueCloseCallback(callback); }
71  void removeExitCallback(InterpreterObject callback)
72  { self->removeOpaqueCloseCallback(callback); }
73  std::vector<InterpreterObject> exitCallbacks()
74  {
75  std::vector<void *> opaque_callbacks(self->opaqueCloseCallbacks());
76 
77  std::vector<InterpreterObject> callbacks;
78  for (int i=0; i < opaque_callbacks.size(); ++i)
79  callbacks.push_back((InterpreterObject)opaque_callbacks[i]);
80  return callbacks;
81  }
82 }
83 #endif
84 
85  // readlineWithKeyboardInterrupt() is not wrapped by swig. It is used
86  // to implement readline() so readline can return a null PyObject*
87  // if it got a KeyboardInterrupt exception.
88  SWIGOUT(%ignore readlineWithKeyboardInterrupt;)
89  virtual hboost::tuple<std::string, bool /*interrupt_occurred*/>
90  readlineWithKeyboardInterrupt(int size) = 0;
91 
92  SWIGOUT(%ignore addOpaqueCloseCallback;)
93  virtual void addOpaqueCloseCallback(void *callback) = 0;
94  SWIGOUT(%ignore removeOpaqueCloseCallback;)
95  virtual void removeOpaqueCloseCallback(void *callback) = 0;
96  SWIGOUT(%ignore opaqueCloseCallbacks;)
97  virtual std::vector<void *> opaqueCloseCallbacks() = 0;
98  SWIGOUT(%ignore executeCloseCallbacks;)
99  virtual void executeCloseCallbacks() = 0;
100 
101  // When this object is set to stdout/stderr, python will call write().
102  virtual void write(const std::string &data) = 0;
103 
104  // Note that this method is not wrapped by swig. It is called from
105  // SI_PythonShell to determine if it should generate UI events to
106  // update the shell with the new data.
107  SWIGOUT(%ignore hasWrittenData;)
108  virtual bool hasWrittenData() = 0;
109 
110  // Note that this method is not werapped by swig.
111  // It is called from HOMF_RopNode and used to
112  // output verbose render messages to the Python shell.
113  SWIGOUT(%ignore getDataStream;)
114  virtual std::stringstream &getDataStream() = 0;
115 
116  // getAndClearWrittenData() is called by the shell window to display
117  // information written by python.
118  virtual std::string getAndClearWrittenData() = 0;
119 
120  // addDataForReading() is called by the shell window when the user types
121  // something there.
122  virtual void addDataForReading(const char *data) = 0;
123 
124  // addEOFForReading() is used to signal readline() that it should return,
125  // even if no readline() was read. It's called by the shell window when
126  // the user presses Ctrl+d and python isn't waiting for commands.
127  virtual void addEOFForReading() = 0;
128 
129  // interruptShellThread() is called by the shell window to raise a
130  // KeyboardInterrupt exception in the shell thread. It properly interrupts
131  // the python thread if it is currently calling readline().
132  virtual void interruptShellThread() = 0;
133 
134  // isWaitingForCommand() is called by the shell window to decide if
135  // a Ctrl+d should close the shell window or send an EOF.
136  // setIsWaitingForCommand() is called by the houdiniInterpreter module
137  // to indicate that it's waiting for a command.
138  virtual bool isWaitingForCommand() = 0;
139  virtual void setIsWaitingForCommand(bool on) = 0;
140 
141  // Note that this method is not wrapped by swig.
142  // It is called from SI_PythoNShell for synchronization purposes.
143  SWIGOUT(%ignore ensureIsReady;)
144  virtual void ensureIsReady() = 0;
145 
146  virtual bool isatty() = 0;
147  virtual void flush() = 0;
148 };
149 
150 #endif
virtual ~HOM_ShellIO()
Definition: HOM_ShellIO.h:26
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:973
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
png_uint_32 i
Definition: png.h:2877
GLsizeiptr size
Definition: glcorearb.h:663
#define HOM_API
Definition: HOM_API.h:13
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:972
GLboolean * data
Definition: glcorearb.h:130
HOM_ShellIO(const HOM_ShellIO &)
Definition: HOM_ShellIO.h:24
void write(T &out, bool v)
Definition: ImfXdr.h:332