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  // This is deprecated for lowercase closeCallbacks()
69  std::vector<InterpreterObject> CloseCallbacks()
70  {
71  std::vector<void *> opaque_callbacks(self->opaqueCloseCallbacks());
72 
73  std::vector<InterpreterObject> callbacks;
74  for (int i=0; i < opaque_callbacks.size(); ++i)
75  callbacks.push_back((InterpreterObject)opaque_callbacks[i]);
76  return callbacks;
77  }
78 
79  // These methods are deprecated and can be removed in the future:
80  void addExitCallback(InterpreterObject callback)
81  { self->addOpaqueCloseCallback(callback); }
82  void removeExitCallback(InterpreterObject callback)
83  { self->removeOpaqueCloseCallback(callback); }
84  std::vector<InterpreterObject> exitCallbacks()
85  {
86  std::vector<void *> opaque_callbacks(self->opaqueCloseCallbacks());
87 
88  std::vector<InterpreterObject> callbacks;
89  for (int i=0; i < opaque_callbacks.size(); ++i)
90  callbacks.push_back((InterpreterObject)opaque_callbacks[i]);
91  return callbacks;
92  }
93 }
94 #endif
95 
96  // readlineWithKeyboardInterrupt() is not wrapped by swig. It is used
97  // to implement readline() so readline can return a null PyObject*
98  // if it got a KeyboardInterrupt exception.
99  SWIGOUT(%ignore readlineWithKeyboardInterrupt;)
101  readlineWithKeyboardInterrupt(int size) = 0;
102 
103  SWIGOUT(%ignore addOpaqueCloseCallback;)
104  virtual void addOpaqueCloseCallback(void *callback) = 0;
105  SWIGOUT(%ignore removeOpaqueCloseCallback;)
106  virtual void removeOpaqueCloseCallback(void *callback) = 0;
107  SWIGOUT(%ignore opaqueCloseCallbacks;)
108  virtual std::vector<void *> opaqueCloseCallbacks() = 0;
109  SWIGOUT(%ignore executeCloseCallbacks;)
110  virtual void executeCloseCallbacks() = 0;
111 
112  // When this object is set to stdout/stderr, python will call write().
113  virtual void write(const std::string &data) = 0;
114 
115  // Note that this method is not wrapped by swig. It is called from
116  // SI_PythonShell to determine if it should generate UI events to
117  // update the shell with the new data.
118  SWIGOUT(%ignore hasWrittenData;)
119  virtual bool hasWrittenData() = 0;
120 
121  // Note that this method is not werapped by swig.
122  // It is called from HOMF_RopNode and used to
123  // output verbose render messages to the Python shell.
124  SWIGOUT(%ignore getDataStream;)
125  virtual std::stringstream &getDataStream() = 0;
126 
127  // getAndClearWrittenData() is called by the shell window to display
128  // information written by python.
129  virtual std::string getAndClearWrittenData() = 0;
130 
131  // addDataForReading() is called by the shell window when the user types
132  // something there.
133  virtual void addDataForReading(const char *data) = 0;
134 
135  // addEOFForReading() is used to signal readline() that it should return,
136  // even if no readline() was read. It's called by the shell window when
137  // the user presses Ctrl+d and python isn't waiting for commands.
138  virtual void addEOFForReading() = 0;
139 
140  // interruptShellThread() is called by the shell window to raise a
141  // KeyboardInterrupt exception in the shell thread. It properly interrupts
142  // the python thread if it is currently calling readline().
143  virtual void interruptShellThread() = 0;
144 
145  // isWaitingForCommand() is called by the shell window to decide if
146  // a Ctrl+d should close the shell window or send an EOF.
147  // setIsWaitingForCommand() is called by the houdiniInterpreter module
148  // to indicate that it's waiting for a command.
149  virtual bool isWaitingForCommand() = 0;
150  virtual void setIsWaitingForCommand(bool on) = 0;
151 
152  // Note that this method is not wrapped by swig.
153  // It is called from SI_PythonShell for synchronization purposes.
154  SWIGOUT(%ignore ensureIsReady;)
155  virtual void ensureIsReady() = 0;
156 
157  virtual bool isatty() = 0;
158  virtual void flush() = 0;
159 
160  // Note that this method is not wrapped by swig.
161  // It is called from SI_PythonShell for silently quitting readline
162  SWIGOUT(%ignore quitShell;)
163  virtual void quitShell() = 0;
164 };
165 
166 #endif
virtual ~HOM_ShellIO()
Definition: HOM_ShellIO.h:26
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1303
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
std::tuple< Types...> UT_Tuple
Definition: UT_Tuple.h:53
**But if you need a result
Definition: thread.h:613
#define HOM_API
Definition: HOM_API.h:13
void ignore(T const &) VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6508
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1302
HOM_ShellIO(const HOM_ShellIO &)
Definition: HOM_ShellIO.h:24
GLsizeiptr size
Definition: glcorearb.h:664
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
void write(T &out, bool v)
Definition: ImfXdr.h:212
Definition: format.h:895