PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusCommandProcessor.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef __vtkPlusCommandProcessor_h
8 #define __vtkPlusCommandProcessor_h
9 
10 #include "vtkPlusServerExport.h"
11 
12 #include "vtkMultiThreader.h"
13 #include "vtkObject.h"
14 #include "vtkPlusCommand.h"
15 #include "vtkPlusCommandResponse.h"
17 #include <string>
18 
19 class vtkImageData;
20 class vtkMatrix4x4;
21 
31 class vtkPlusServerExport vtkPlusCommandProcessor : public vtkObject
32 {
33 public:
34  static vtkPlusCommandProcessor* New();
35  vtkTypeMacro(vtkPlusCommandProcessor, vtkObject);
36  virtual void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
37 
42  int ExecuteCommands();
43 
45  virtual PlusStatus Start();
46 
48  virtual PlusStatus Stop();
49 
51  virtual bool IsRunning();
52 
57  virtual PlusStatus RegisterPlusCommand(vtkPlusCommand* cmd);
58 
60  virtual PlusStatus QueueCommand(bool respondUsingIGTLCommand, unsigned int clientId, const std::string& commandName, const std::string& commandString, const std::string& deviceName, uint32_t uid, const igtl::MessageBase::MetaDataMap& metaData);
61 
66  virtual PlusStatus QueueStringResponse(PlusStatus status, const std::string& deviceName, unsigned int clientId, const std::string& replyString);
67 
72  virtual PlusStatus QueueCommandResponse(PlusStatus status, const std::string& deviceName, unsigned int clientId, const std::string& commandName, uint32_t uid, const std::string& replyString, const std::string& errorString);
73 
77  PlusStatus QueueGetImageMetaData(unsigned int clientId, const std::string& deviceName);
78 
82  PlusStatus QueueGetImage(unsigned int clientId, const std::string& deviceName);
83 
89  virtual void PopCommandResponses(PlusCommandResponseList& responses);
90 
91  vtkGetObjectMacro(PlusServer, vtkPlusOpenIGTLinkServer);
92  vtkSetObjectMacro(PlusServer, vtkPlusOpenIGTLinkServer);
93 
94 protected:
95  vtkPlusCommand* CreatePlusCommand(const std::string& commandName, const std::string& commandStr, const igtl::MessageBase::MetaDataMap& metaData);
96 
98  static void* CommandExecutionThread(vtkMultiThreader::ThreadInfo* data);
99 
101  virtual ~vtkPlusCommandProcessor();
102 
103 private:
105  vtkPlusOpenIGTLinkServer* PlusServer;
106 
108  vtkSmartPointer<vtkMultiThreader> Threader;
109 
111  vtkSmartPointer<vtkIGSIORecursiveCriticalSection> Mutex;
112 
113  // Active flag for threads (first: request, second: respond )
114  std::pair<bool, bool> CommandExecutionActive;
115 
116  // Thread identifier
117  int CommandExecutionThreadId;
118 
120  std::map<std::string, vtkPlusCommand*> RegisteredCommands;
121 
127  //std::list<vtkPlusCommand*> CommandQueue;
128  typedef std::list< vtkSmartPointer<vtkPlusCommand> > PlusCommandList;
129  PlusCommandList CommandQueue;
130  PlusCommandResponseList CommandResponseQueue;
131 
132  vtkPlusCommandProcessor(const vtkPlusCommandProcessor&); // Not implemented.
133  void operator=(const vtkPlusCommandProcessor&); // Not implemented.
134 };
135 
136 #endif
const uint32_t * data
Definition: phidget22.h:3971
This is an abstract superclass for commands in the OpenIGTLink network interface for Plus.
const char ** errorString
Definition: phidget22.h:1270
igsioStatus PlusStatus
Definition: PlusCommon.h:40
Creates a PlusCommand from a string. If the commands are to be executed on the main thread then call ...
#define VTK_OVERRIDE
Definition: PlusCommon.h:49
const char ** deviceName
Definition: phidget22.h:1316
This class provides a network interface for data acquired by Plus as an OpenIGTLink server.
std::list< vtkSmartPointer< vtkPlusCommandResponse > > PlusCommandResponseList