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&, vtkIndent) override;
69 
71 
75  int ProcessStream(const unsigned char* msg, size_t msgLength);
76  int ProcessStream(const vtkClientServerStream& css);
78 
83  int ProcessOneMessage(const vtkClientServerStream& css, int message);
84 
88  const vtkClientServerStream* GetMessageFromID(vtkClientServerID id);
89 
93  const vtkClientServerStream& GetLastResult() const;
94 
100  vtkObjectBase* GetObjectFromID(vtkClientServerID id, int noerror);
101 
106  vtkClientServerID GetIDFromObject(vtkObjectBase* key);
107 
109 
112  void SetLogFile(const char* name);
113  virtual void SetLogStream(ostream* ostr);
114  vtkGetMacro(LogStream, ostream*);
116 
121  int NewInstance(vtkObjectBase* obj, vtkClientServerID id);
122 
127  vtkObjectBase* NewInstance(const char* classname);
128 
133  int NewObserver(vtkObject* obj, const char* event, const vtkClientServerStream& css);
134 
138  void AddCommandFunction(const char* cname, vtkClientServerCommandFunction func, void* ctx = NULL,
139  vtkContextFreeFunction ctx_free = NULL);
140 
144  bool HasCommandFunction(const char* cname);
145 
149  int CallCommandFunction(const char* classname, vtkObjectBase* ptr, const char* method,
150  const vtkClientServerStream& msg, vtkClientServerStream& result);
151 
155  void AddNewInstanceFunction(const char* cname, vtkClientServerNewInstanceFunction f,
156  void* ctx = NULL, vtkContextFreeFunction ctx_free = NULL);
157 
159 
164  {
165  const char* Type;
166  unsigned long ID;
167  };
169 
173  void ClearLastResult();
174 
176 
180  int Load(const char* moduleName);
181  int Load(const char* moduleName, const char* const* optionalPaths);
183 
190  vtkClientServerID GetNextAvailableId();
191 
192 protected:
193  // constructor and destructor
195  ~vtkClientServerInterpreter() override;
196 
197  // A stream to which a log is written.
198  ostream* LogStream;
199  ostream* LogFileStream;
200 
201  // Internal message processing functions.
202  int ProcessCommandNew(const vtkClientServerStream& css, int midx);
203  int ProcessCommandInvoke(const vtkClientServerStream& css, int midx);
204  int ProcessCommandDelete(const vtkClientServerStream& css, int midx);
205  int ProcessCommandAssign(const vtkClientServerStream& css, int midx);
206 
207  // Expand all the id_value arguments of a message starting with the
208  // given argument index.
209  int ExpandMessage(
210  const vtkClientServerStream& in, int inIndex, int startArgument, vtkClientServerStream& out);
211 
212  // Load a module dynamically given the full path to it.
213  int LoadInternal(const char* moduleName, const char* fullPath);
214 
215 private:
216  // Message containing the result of the last command.
217  vtkClientServerStream* LastResultMessage;
218 
219  // Internal implementation details.
220  vtkClientServerInterpreterInternals* Internal;
221 
222 private:
224  void operator=(const vtkClientServerInterpreter&) = delete;
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