vtkClientServerInterpreter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
12 #ifndef vtkClientServerInterpreter_h
13 #define vtkClientServerInterpreter_h
14 
15 #include "vtkObject.h"
16 
17 #include "vtkClientServerID.h" // Needed for vtkClientServerID.
18 
20 class vtkClientServerInterpreterInternals;
22 
29  const char* method, const vtkClientServerStream& msg, vtkClientServerStream& result, void* ctx);
30 
34 typedef vtkObjectBase* (*vtkClientServerNewInstanceFunction)(void* ctx);
35 
36 typedef void (*vtkContextFreeFunction)(void* ctx);
37 
43 {
44  // The stream containing the message causing the error.
46 
47  // The message index with in the stream that caused the error.
48  int message;
49 };
50 
52 {
53 public:
54  static vtkClientServerInterpreter* New();
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
59  vtkClientServerInterpreter& operator=(const vtkClientServerInterpreter&) = delete;
60 
62 
66  int ProcessStream(const unsigned char* msg, size_t msgLength);
67  int ProcessStream(const vtkClientServerStream& css);
69 
74  int ProcessOneMessage(const vtkClientServerStream& css, int message);
75 
79  const vtkClientServerStream* GetMessageFromID(vtkClientServerID id);
80 
84  const vtkClientServerStream& GetLastResult() const;
85 
91  vtkObjectBase* GetObjectFromID(vtkClientServerID id, int noerror);
92 
97  vtkClientServerID GetIDFromObject(vtkObjectBase* key);
98 
100 
103  void SetLogFile(const char* name);
104  virtual void SetLogStream(ostream* ostr);
105  vtkGetMacro(LogStream, ostream*);
107 
112  int NewInstance(vtkObjectBase* obj, vtkClientServerID id);
113 
118  vtkObjectBase* NewInstance(const char* classname);
119 
124  int NewObserver(vtkObject* obj, const char* event, const vtkClientServerStream& css);
125 
129  void AddCommandFunction(const char* cname, vtkClientServerCommandFunction func,
130  void* ctx = nullptr, vtkContextFreeFunction ctx_free = nullptr);
131 
135  bool HasCommandFunction(const char* cname);
136 
140  int CallCommandFunction(const char* classname, vtkObjectBase* ptr, const char* method,
141  const vtkClientServerStream& msg, vtkClientServerStream& result);
142 
146  void AddNewInstanceFunction(const char* cname, vtkClientServerNewInstanceFunction f,
147  void* ctx = nullptr, vtkContextFreeFunction ctx_free = nullptr);
148 
150 
155  {
156  const char* Type;
157  unsigned long ID;
158  };
160 
164  void ClearLastResult();
165 
167 
171  int Load(const char* moduleName);
172  int Load(const char* moduleName, const char* const* optionalPaths);
174 
181  vtkClientServerID GetNextAvailableId();
182 
183 protected:
184  // constructor and destructor
186  ~vtkClientServerInterpreter() override;
187 
188  // A stream to which a log is written.
189  ostream* LogStream;
190  ostream* LogFileStream;
191 
192  // Internal message processing functions.
193  int ProcessCommandNew(const vtkClientServerStream& css, int midx);
194  int ProcessCommandInvoke(const vtkClientServerStream& css, int midx);
195  int ProcessCommandDelete(const vtkClientServerStream& css, int midx);
196  int ProcessCommandAssign(const vtkClientServerStream& css, int midx);
197 
198  // Expand all the id_value arguments of a message starting with the
199  // given argument index.
200  int ExpandMessage(
201  const vtkClientServerStream& in, int inIndex, int startArgument, vtkClientServerStream& out);
202 
203  // Load a module dynamically given the full path to it.
204  int LoadInternal(const char* moduleName, const char* fullPath);
205 
206 private:
207  // Message containing the result of the last command.
208  vtkClientServerStream* LastResultMessage;
209 
210  // Internal implementation details.
211  vtkClientServerInterpreterInternals* Internal;
212 
213  int NextAvailableId;
214 };
215 
216 #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