63 #ifndef GADGETRON_CLIENT
64 #define GADGETRON_CLIENT
66 #ifndef WIN32_LEAN_AND_MEAN
67 #define WIN32_LEAN_AND_MEAN
71 #include <condition_variable>
80 #include <boost/asio.hpp>
81 #include <boost/thread/thread.hpp>
83 #include <ismrmrd/dataset.h>
84 #include <ismrmrd/ismrmrd.h>
85 #include <ismrmrd/meta.h>
87 #include "sirf/Gadgetron/cgadgetron_shared_ptr.h"
90 enum GadgetronMessageID {
91 GADGET_MESSAGE_INT_ID_MIN = 0,
92 GADGET_MESSAGE_CONFIG_FILE = 1,
93 GADGET_MESSAGE_CONFIG_SCRIPT = 2,
94 GADGET_MESSAGE_PARAMETER_SCRIPT = 3,
95 GADGET_MESSAGE_CLOSE = 4,
96 GADGET_MESSAGE_TEXT = 5,
97 GADGET_MESSAGE_INT_ID_MAX = 999,
98 GADGET_MESSAGE_EXT_ID_MIN = 1000,
99 GADGET_MESSAGE_ISMRMRD_ACQUISITION = 1008,
100 GADGET_MESSAGE_CLOUD_JOB = 1013,
101 GADGET_MESSAGE_GADGETCLOUD_JOB = 1014,
102 GADGET_MESSAGE_DICOM_WITHNAME = 1018,
103 GADGET_MESSAGE_DEPENDENCY_QUERY = 1019,
104 GADGET_MESSAGE_ISMRMRD_IMAGE = 1022,
105 GADGET_MESSAGE_RECONDATA = 1023,
106 GADGET_MESSAGE_EXT_ID_MAX = 4096
109 #define MAX_BLOBS_LOG_10 6
118 char configuration_file[1024];
122 uint32_t script_length;
129 virtual const char* what()
const throw()
146 virtual void read(boost::asio::ip::tcp::socket* s) = 0;
156 (gadgetron::shared_ptr<MRAcquisitionData> ptr_acqs) : ptr_acqs_(ptr_acqs) {}
159 virtual void read(boost::asio::ip::tcp::socket* stream);
162 gadgetron::shared_ptr<MRAcquisitionData> ptr_acqs_;
172 (gadgetron::shared_ptr<GadgetronImageData> ptr_images) : ptr_images_(ptr_images) {}
175 template <
typename T>
176 void read_data_attributes
177 (ISMRMRD::Image<T>* ptr,
const ISMRMRD::ImageHeader& h,
void** ptr_ptr,
178 boost::asio::ip::tcp::socket* stream)
180 ISMRMRD::Image < T >* ptr_im =
new ISMRMRD::Image < T > ;
181 *ptr_ptr = (
void*)ptr_im;
182 ISMRMRD::Image<T>& im = *ptr_im;
187 typedef unsigned long long size_t_type;
188 size_t_type meta_attrib_length;
190 (*stream, boost::asio::buffer(&meta_attrib_length,
sizeof(size_t_type)));
191 if (meta_attrib_length > 0) {
192 std::string meta_attrib(meta_attrib_length, 0);
193 boost::asio::read(*stream, boost::asio::buffer(
const_cast < char*
>
194 (meta_attrib.c_str()), meta_attrib_length));
195 im.setAttributeString(meta_attrib);
199 (*stream, boost::asio::buffer(im.getDataPtr(), im.getDataSize()));
202 virtual void read(boost::asio::ip::tcp::socket* stream);
205 gadgetron::shared_ptr<GadgetronImageData> ptr_images_;
212 : number_of_calls_(0)
213 , file_prefix(fileprefix)
214 , file_suffix(filesuffix)
221 virtual void read(boost::asio::ip::tcp::socket* socket)
226 boost::asio::read(*socket, boost::asio::buffer(&nbytes,
sizeof(uint32_t)));
228 std::vector<char> data(nbytes, 0);
229 boost::asio::read(*socket, boost::asio::buffer(&data[0], nbytes));
231 unsigned long long fileNameLen;
232 boost::asio::read(*socket, boost::asio::buffer(&fileNameLen,
sizeof(
unsigned long long)));
234 std::string filenameBuf(fileNameLen, 0);
235 boost::asio::read(*socket, boost::asio::buffer(
const_cast<char*
>
236 (filenameBuf.c_str()), fileNameLen));
238 typedef unsigned long long size_t_type;
240 size_t_type meta_attrib_length;
241 boost::asio::read(*socket, boost::asio::buffer(&meta_attrib_length,
sizeof(size_t_type)));
243 std::string meta_attrib;
244 if (meta_attrib_length > 0) {
245 std::string meta_attrib_socket(meta_attrib_length, 0);
246 boost::asio::read(*socket, boost::asio::buffer(
const_cast<char*
>(meta_attrib_socket.c_str()), meta_attrib_length));
247 meta_attrib = meta_attrib_socket;
250 std::stringstream filename;
251 std::string filename_attrib;
254 filename << file_prefix <<
"_";
255 filename << std::setfill(
'0') << std::setw(MAX_BLOBS_LOG_10) << number_of_calls_;
256 filename_attrib = filename.str();
257 filename <<
"." << file_suffix;
258 filename_attrib.append(
"_attrib.xml");
262 std::ofstream outfile;
263 outfile.open(filename.str().c_str(), std::ios::out | std::ios::binary);
265 std::ofstream outfile_attrib;
266 if (meta_attrib_length > 0) {
267 outfile_attrib.open(filename_attrib.c_str(), std::ios::out | std::ios::binary);
270 if (outfile.good()) {
272 outfile.write(&data[0], nbytes);
274 if (meta_attrib_length > 0) {
275 outfile_attrib.write(meta_attrib.c_str(), meta_attrib.length());
276 outfile_attrib.close();
286 size_t number_of_calls_;
287 std::string file_prefix;
288 std::string file_suffix;
306 void set_timeout(
unsigned int t)
315 reader_thread_.join();
318 void connect(std::string hostname, std::string port);
320 void send_gadgetron_close();
322 void send_gadgetron_configuration_file(std::string config_xml_name);
324 void send_gadgetron_configuration_script(std::string xml_string);
326 void send_gadgetron_parameters(std::string xml_string);
328 void send_ismrmrd_acquisition(ISMRMRD::Acquisition& acq);
331 void send_ismrmrd_image(ISMRMRD::Image<T>* ptr_im)
333 ISMRMRD::Image<T>& im = *ptr_im;
338 id.id = GADGET_MESSAGE_ISMRMRD_IMAGE;
344 boost::asio::buffer(&im.getHead(),
sizeof(ISMRMRD::ImageHeader)));
346 size_t meta_attrib_length = im.getAttributeStringLength();
347 std::string meta_attrib(meta_attrib_length + 1, 0);
348 im.getAttributeString(meta_attrib);
351 (*socket_, boost::asio::buffer(&meta_attrib_length,
sizeof(
size_t)));
353 (*socket_, boost::asio::buffer(meta_attrib.c_str(), meta_attrib_length));
356 (*socket_, boost::asio::buffer(im.getDataPtr(), im.getDataSize()));
359 void send_wrapped_image(
const ImageWrap& iw)
361 IMAGE_PROCESSING_SWITCH(iw.type(), send_ismrmrd_image, iw.ptr_image());
365 (
unsigned short slot, gadgetron::shared_ptr<GadgetronClientMessageReader> r)
372 std::map < unsigned short, gadgetron::shared_ptr<GadgetronClientMessageReader> >
377 boost::asio::io_service io_service;
378 boost::asio::ip::tcp::socket* socket_;
379 boost::thread reader_thread_;
381 unsigned int timeout_ms_;
Class for accumulating acquisitions sent by Gadgetron server.
Definition: gadgetron_client.h:153
virtual void read(boost::asio::ip::tcp::socket *stream)
Definition: gadgetron_client.cpp:72
Definition: gadgetron_client.h:209
virtual void read(boost::asio::ip::tcp::socket *socket)
Definition: gadgetron_client.h:221
Class for communicating with Gadgetron server.
Definition: gadgetron_client.h:294
Definition: gadgetron_client.h:125
Class for accumulating ISMRMRD images sent by Gadgetron server.
Definition: gadgetron_client.h:169
virtual void read(boost::asio::ip::tcp::socket *stream)
Definition: gadgetron_client.cpp:100
Abstract base class for receiving messages from Gadgetron server.
Definition: gadgetron_client.h:140
virtual void read(boost::asio::ip::tcp::socket *s)=0
Wrapper for ISMRMRD::Image.
Definition: gadgetron_image_wrap.h:106
Specification file for data container classes for Gadgetron data.
Abstract data container.
Definition: GeometricalInfo.cpp:141
Definition: gadgetron_client.h:117
Definition: gadgetron_client.h:113
Definition: gadgetron_client.h:121