HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 <UT/UT_Tuple.h>
15 #include <string>
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.
40  self->readlineWithKeyboardInterrupt(size);
41  if (UTtupleGet<1>(result))
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(UTtupleGet<0>(result),
48  SWIG_POINTER_OWN);
49  }
50 
51  void addCloseCallback(InterpreterObject callback)
52  { self->addOpaqueCloseCallback(callback); }
53 
54  void removeCloseCallback(InterpreterObject callback)
55  { self->removeOpaqueCloseCallback(callback); }
56 
57  // Note that we return a vector of borrowed references because swig
58  // will increment the reference counts.
59  std::vector<InterpreterObject> CloseCallbacks()
60  {
61  std::vector<void *> opaque_callbacks(self->opaqueCloseCallbacks());
62 
63  std::vector<InterpreterObject> callbacks;
64  for (int i=0; i < opaque_callbacks.size(); ++i)
65  callbacks.push_back((InterpreterObject)opaque_callbacks[i]);
66  return callbacks;
67  }
68 
69  // These methods are deprecated and can be removed in the future:
70  void addExitCallback(InterpreterObject callback)
71  { self->addOpaqueCloseCallback(callback); }
72  void removeExitCallback(InterpreterObject callback)
73  { self->removeOpaqueCloseCallback(callback); }
74  std::vector<InterpreterObject> exitCallbacks()
75  {
76  std::vector<void *> opaque_callbacks(self->opaqueCloseCallbacks());
77 
78  std::vector<InterpreterObject> callbacks;
79  for (int i=0; i < opaque_callbacks.size(); ++i)
80  callbacks.push_back((InterpreterObject)opaque_callbacks[i]);
81  return callbacks;
82  }
83 }
84 #endif
85 
86  // readlineWithKeyboardInterrupt() is not wrapped by swig. It is used
87  // to implement readline() so readline can return a null PyObject*
88  // if it got a KeyboardInterrupt exception.
89  SWIGOUT(%ignore readlineWithKeyboardInterrupt;)
91  readlineWithKeyboardInterrupt(int size) = 0;
92 
93  SWIGOUT(%ignore addOpaqueCloseCallback;)
94  virtual void addOpaqueCloseCallback(void *callback) = 0;
95  SWIGOUT(%ignore removeOpaqueCloseCallback;)
96  virtual void removeOpaqueCloseCallback(void *callback) = 0;
97  SWIGOUT(%ignore opaqueCloseCallbacks;)
98  virtual std::vector<void *> opaqueCloseCallbacks() = 0;
99  SWIGOUT(%ignore executeCloseCallbacks;)
100  virtual void executeCloseCallbacks() = 0;
101 
102  // When this object is set to stdout/stderr, python will call write().
103  virtual void write(const std::string &data) = 0;
104 
105  // Note that this method is not wrapped by swig. It is called from
106  // SI_PythonShell to determine if it should generate UI events to
107  // update the shell with the new data.
108  SWIGOUT(%ignore hasWrittenData;)
109  virtual bool hasWrittenData() = 0;
110 
111  // Note that this method is not werapped by swig.
112  // It is called from HOMF_RopNode and used to
113  // output verbose render messages to the Python shell.
114  SWIGOUT(%ignore getDataStream;)
115  virtual std::stringstream &getDataStream() = 0;
116 
117  // getAndClearWrittenData() is called by the shell window to display
118  // information written by python.
119  virtual std::string getAndClearWrittenData() = 0;
120 
121  // addDataForReading() is called by the shell window when the user types
122  // something there.
123  virtual void addDataForReading(const char *data) = 0;
124 
125  // addEOFForReading() is used to signal readline() that it should return,
126  // even if no readline() was read. It's called by the shell window when
127  // the user presses Ctrl+d and python isn't waiting for commands.
128  virtual void addEOFForReading() = 0;
129 
130  // interruptShellThread() is called by the shell window to raise a
131  // KeyboardInterrupt exception in the shell thread. It properly interrupts
132  // the python thread if it is currently calling readline().
133  virtual void interruptShellThread() = 0;
134 
135  // isWaitingForCommand() is called by the shell window to decide if
136  // a Ctrl+d should close the shell window or send an EOF.
137  // setIsWaitingForCommand() is called by the houdiniInterpreter module
138  // to indicate that it's waiting for a command.
139  virtual bool isWaitingForCommand() = 0;
140  virtual void setIsWaitingForCommand(bool on) = 0;
141 
142  // Note that this method is not wrapped by swig.
143  // It is called from SI_PythoNShell for synchronization purposes.
144  SWIGOUT(%ignore ensureIsReady;)
145  virtual void ensureIsReady() = 0;
146 
147  virtual bool isatty() = 0;
148  virtual void flush() = 0;
149 };
150 
151 #endif
virtual ~HOM_ShellIO()
Definition: HOM_ShellIO.h:26
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1053
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
std::tuple< Types...> UT_Tuple
Definition: UT_Tuple.h:53
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:1052
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