00001 /*========================================================================== 00002 00003 Portions (c) Copyright 2008 Brigham and Women's Hospital (BWH) All Rights Reserved. 00004 00005 See Doc/copyright/copyright.txt 00006 or http://www.slicer.org/copyright/copyright.txt for details. 00007 00008 Program: 3D Slicer 00009 Module: $HeadURL: $ 00010 Date: $Date: $ 00011 Version: $Revision: $ 00012 00013 ==========================================================================*/ 00014 00015 #ifndef __vtkUDPServerLogic_h 00016 #define __vtkUDPServerLogic_h 00017 00018 #include "vtkUDPServerWin32Header.h" 00019 00020 #include "vtkSlicerBaseLogic.h" 00021 #include "vtkSlicerModuleLogic.h" 00022 #include "vtkSlicerApplication.h" 00023 #include "vtkCallbackCommand.h" 00024 00025 #include "vtkMRMLSliceNode.h" 00026 00027 #include <stdio.h> 00028 #include <sys/socket.h> 00029 #include <arpa/inet.h> 00030 #include <stdlib.h> 00031 #include <string.h> 00032 #include <unistd.h> 00033 #include <netinet/in.h> 00034 #include <iostream> 00035 #include <fcntl.h> 00036 00037 class vtkMultiThreader; 00038 00039 class VTK_UDPServer_EXPORT vtkUDPServerLogic : public vtkSlicerModuleLogic 00040 { 00041 public: 00042 //BTX 00043 enum { // Events 00044 //LocatorUpdateEvent = 50000, 00045 StatusUpdateEvent = 50001, 00046 }; 00047 //ETX 00048 00049 public: 00050 00051 static vtkUDPServerLogic *New(); 00052 00053 vtkTypeRevisionMacro(vtkUDPServerLogic,vtkObject); 00054 void PrintSelf(ostream&, vtkIndent); 00055 00056 //---------------------------------- 00057 //Data Handlers 00058 int StartServerConnection(); 00059 void ImportData(); 00060 int Start(int p); 00061 int Stop(); 00062 bool GetServerStopFlag() {return this->ServerStopFlag;}; 00063 char* GetImportedData(){return this->ImportedData;}; 00064 int GetBytesReceived(){return this->received;}; 00065 void SetPort(int p) {this->port = p;}; 00066 00067 int ProbeType; //Probe Type 0 for rejection probe and 1 for single probe 00068 00069 //----------------------------------- 00070 //Thread Control 00071 00072 static void* ThreadFunction(void* ptr); 00073 00074 protected: 00075 00076 vtkUDPServerLogic(); 00077 ~vtkUDPServerLogic(); 00078 00079 void operator=(const vtkUDPServerLogic&); 00080 vtkUDPServerLogic(const vtkUDPServerLogic&); 00081 00082 static void DataCallback(vtkObject*, unsigned long, void *, void *); 00083 void UpdateAll(); 00084 00085 vtkCallbackCommand *DataCallbackCommand; 00086 00087 //----------------------------------------------------------------- 00088 // Server Connection 00089 //----------------------------------------------------------------- 00090 00091 //BTX 00092 int sock; 00093 int port; 00094 int received; 00095 static const int BUFFSIZE = 255; 00096 char buffer[BUFFSIZE]; 00097 struct sockaddr_in echoserver; 00098 struct sockaddr_in echoclient; 00099 unsigned int echolen, clientlen, serverlen; 00100 int ThreadID; 00101 bool ServerStopFlag; 00102 char* ImportedData; 00103 //ETX 00104 00105 private: 00106 00107 vtkMultiThreader* Thread; 00108 00109 }; 00110 00111 #endif
1.6.1