ParaView
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 vtkClientServerInterpreterCommand;
33 class vtkClientServerInterpreterInternals;
35 
41 typedef int (*vtkClientServerCommandFunction)(vtkClientServerInterpreter*, vtkObjectBase* ptr,
42  const char* method, const vtkClientServerStream& msg, vtkClientServerStream& result, void* ctx);
43 
47 typedef vtkObjectBase* (*vtkClientServerNewInstanceFunction)(void* ctx);
48 
49 typedef void (*vtkContextFreeFunction)(void* ctx);
50 
56 {
57  // The stream containing the message causing the error.
59 
60  // The message index with in the stream that caused the error.
61  int message;
62 };
63 
64 class VTKCLIENTSERVER_EXPORT vtkClientServerInterpreter : public vtkObject
65 {
66 public:
67  static vtkClientServerInterpreter* New();
68  vtkTypeMacro(vtkClientServerInterpreter, vtkObject);
69  void PrintSelf(ostream&, vtkIndent);
70 
72 
76  int ProcessStream(const unsigned char* msg, size_t msgLength);
77  int ProcessStream(const vtkClientServerStream& css);
79 
84  int ProcessOneMessage(const vtkClientServerStream& css, int message);
85 
89  const vtkClientServerStream* GetMessageFromID(vtkClientServerID id);
90 
94  const vtkClientServerStream& GetLastResult() const;
95 
100  vtkObjectBase* GetObjectFromID(vtkClientServerID id) { return this->GetObjectFromID(id, 0); }
101  vtkObjectBase* GetObjectFromID(vtkClientServerID id, int noerror);
102 
107  vtkClientServerID GetIDFromObject(vtkObjectBase* key);
108 
110 
113  void SetLogFile(const char* name);
114  virtual void SetLogStream(ostream* ostr);
115  vtkGetMacro(LogStream, ostream*);
117 
122  int NewInstance(vtkObjectBase* obj, vtkClientServerID id);
123 
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
196 
197  // A stream to which a log is written.
198  ostream* LogStream;
199  ofstream* 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 from an alternate backend implementation.
213  int LoadImpl(const char* moduleName);
214  // Load a module dynamically given the full path to it.
215  int LoadInternal(const char* moduleName, const char* fullPath);
216 
217 private:
218  // Message containing the result of the last command.
219  vtkClientServerStream* LastResultMessage;
220 
221  // Internal implementation details.
222  vtkClientServerInterpreterInternals* Internal;
223 
224  friend class vtkClientServerInterpreterCommand;
225 
226 private:
227  vtkClientServerInterpreter(const vtkClientServerInterpreter&) VTK_DELETE_FUNCTION;
228  void operator=(const vtkClientServerInterpreter&) VTK_DELETE_FUNCTION;
229  int NextAvailableId;
230 };
231 
232 #endif
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.
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...
void(* vtkContextFreeFunction)(void *ctx)
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...