vtkClientServerInterpreter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkClientServerInterpreter.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
24 #ifndef vtkClientServerInterpreter_h
25 #define vtkClientServerInterpreter_h
26 
27 #include "vtkObject.h"
28 
29 #include "vtkClientServerID.h" // Needed for vtkClientServerID.
30 
32 class vtkClientServerInterpreterInternals;
34 
41  const char* method, const vtkClientServerStream& msg, vtkClientServerStream& result, void* ctx);
42 
46 typedef vtkObjectBase* (*vtkClientServerNewInstanceFunction)(void* ctx);
47 
48 typedef void (*vtkContextFreeFunction)(void* ctx);
49 
55 {
56  // The stream containing the message causing the error.
58 
59  // The message index with in the stream that caused the error.
60  int message;
61 };
62 
64 {
65 public:
66  static vtkClientServerInterpreter* New();
68  void PrintSelf(ostream& os, vtkIndent indent) override;
69 
71  vtkClientServerInterpreter& operator=(const vtkClientServerInterpreter&) = delete;
72 
74 
78  int ProcessStream(const unsigned char* msg, size_t msgLength);
79  int ProcessStream(const vtkClientServerStream& css);
81 
86  int ProcessOneMessage(const vtkClientServerStream& css, int message);
87 
91  const vtkClientServerStream* GetMessageFromID(vtkClientServerID id);
92 
96  const vtkClientServerStream& GetLastResult() const;
97 
103  vtkObjectBase* GetObjectFromID(vtkClientServerID id, int noerror);
104 
109  vtkClientServerID GetIDFromObject(vtkObjectBase* key);
110 
112 
115  void SetLogFile(const char* name);
116  virtual void SetLogStream(ostream* ostr);
117  vtkGetMacro(LogStream, ostream*);
119 
124  int NewInstance(vtkObjectBase* obj, vtkClientServerID id);
125 
130  vtkObjectBase* NewInstance(const char* classname);
131 
136  int NewObserver(vtkObject* obj, const char* event, const vtkClientServerStream& css);
137 
141  void AddCommandFunction(const char* cname, vtkClientServerCommandFunction func,
142  void* ctx = nullptr, vtkContextFreeFunction ctx_free = nullptr);
143 
147  bool HasCommandFunction(const char* cname);
148 
152  int CallCommandFunction(const char* classname, vtkObjectBase* ptr, const char* method,
153  const vtkClientServerStream& msg, vtkClientServerStream& result);
154 
158  void AddNewInstanceFunction(const char* cname, vtkClientServerNewInstanceFunction f,
159  void* ctx = nullptr, vtkContextFreeFunction ctx_free = nullptr);
160 
162 
167  {
168  const char* Type;
169  unsigned long ID;
170  };
172 
176  void ClearLastResult();
177 
179 
183  int Load(const char* moduleName);
184  int Load(const char* moduleName, const char* const* optionalPaths);
186 
193  vtkClientServerID GetNextAvailableId();
194 
195 protected:
196  // constructor and destructor
198  ~vtkClientServerInterpreter() override;
199 
200  // A stream to which a log is written.
201  ostream* LogStream;
202  ostream* LogFileStream;
203 
204  // Internal message processing functions.
205  int ProcessCommandNew(const vtkClientServerStream& css, int midx);
206  int ProcessCommandInvoke(const vtkClientServerStream& css, int midx);
207  int ProcessCommandDelete(const vtkClientServerStream& css, int midx);
208  int ProcessCommandAssign(const vtkClientServerStream& css, int midx);
209 
210  // Expand all the id_value arguments of a message starting with the
211  // given argument index.
212  int ExpandMessage(
213  const vtkClientServerStream& in, int inIndex, int startArgument, vtkClientServerStream& out);
214 
215  // Load a module dynamically given the full path to it.
216  int LoadInternal(const char* moduleName, const char* fullPath);
217 
218 private:
219  // Message containing the result of the last command.
220  vtkClientServerStream* LastResultMessage;
221 
222  // Internal implementation details.
223  vtkClientServerInterpreterInternals* Internal;
224 
225  int NextAvailableId;
226 };
227 
228 #endif
int
int(* vtkClientServerCommandFunction)(vtkClientServerInterpreter *, vtkObjectBase *ptr, const char *method, const vtkClientServerStream &msg, vtkClientServerStream &result, void *ctx)
The type of a command function.
Store messages for the interpreter.
name
A pointer to this struct is sent as call data when an ErrorEvent is invoked by the interpreter...
Run-time VTK interpreter.
vtkObjectBase *(* vtkClientServerNewInstanceFunction)(void *ctx)
The type of a new-instance function.
The callback data structure passed to observers looking for VTK object creation and deletion events...
#define VTK_NEWINSTANCE
void(* vtkContextFreeFunction)(void *ctx)
#define VTKREMOTINGCLIENTSERVERSTREAM_EXPORT
Identifier for a ClientServer object.
vtkObjectBase * GetObjectFromID(vtkClientServerID id)
Return a pointer to a vtkObjectBase for an ID whose message contains only the one object...
key