EigerStream.h 3.44 KB
Newer Older
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2015
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef EIGERSTREAM_H
#define EIGERSTREAM_H

#include "lima/Debug.h"

#include "EigerCamera.h"
28
#include "EigerStreamInfo.h"
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
29
30
#include "lima/HwBufferMgr.h"

31
32
#include <json/json.h>

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
33
34
35
36
37
38
39
40
41
namespace lima
{
  namespace Eiger
  {
    class Stream
    {
      DEB_CLASS_NAMESPC(DebModCamera,"Stream","Eiger");
    public:
      class Message;
42
      typedef std::shared_ptr<Message> MessagePtr;
43
      typedef Camera::CompressionType CompressionType;
44

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
45
      enum HeaderDetail {ALL,BASIC,OFF};
46
      enum State {Init,Idle,Connected,Armed,Running,Failed,Stopped,Aborted};
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
47

48
49
50
51
52
53
54
      struct ImageData {
	MessagePtr msg;
	int depth;
	CompressionType comp_type;
	void getMsgDataNSize(void*& data, size_t& size) const;
      };

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
55
56
57
58
59
60
      Stream(Camera&);
      ~Stream();

      void start();
      void stop();
      bool isRunning() const;
61
      void waitArmed(double timeout);
62

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
63
64
65
66
67
68
69
      void getHeaderDetail(HeaderDetail&) const;
      void setHeaderDetail(HeaderDetail);
      
      void setActive(bool);
      bool isActive() const;

      HwBufferCtrlObj* getBufferCtrlObj();
70

71
      ImageData get_msg(void* aDataBuffer);
72
      void release_all_msgs();
73
74
75

      void getLastStreamInfo(StreamInfo& info);

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
76
77
78
    private:
      class _BufferCtrlObj;
      friend class _BufferCtrlObj;
79
      friend class ImageDataPtr;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
80

81
      typedef std::map<void*,ImageData> Data2Message;
82
83
84
      typedef std::vector<MessagePtr> MessageList;

      bool _isRunning() const;
85

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
86
87
      static void* _runFunc(void*);
      void _run();
88
89
90
91
      void _run_sequence();
      Json::Value _get_global_header(const Json::Value& stream_header,
				     MessageList& pending_messages);
      Json::Value _get_json_header(MessagePtr &msg);
92
      bool _read_zmq_messages(void *stream_socket);
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
93
      void _send_synchro();
94

95
      void _checkCompression(const StreamInfo& info);
96

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
97
      Camera&		m_cam;
98
      char		m_endianess;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
99
100
      bool		m_active;
      HeaderDetail	m_header_detail;
101
      std::string	m_header_detail_str;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
102
      bool		m_dirty_flag;
103
      State		m_state;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
104
105

      mutable Cond	m_cond;
106
      bool		m_quit;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
107
108
109
110

      pthread_t		m_thread_id;
      void*		m_zmq_context;
      int		m_pipes[2];
111
      Data2Message	m_data_2_msg;
112
      StreamInfo	m_last_info;
113
      bool		m_ext_trigger;
114
      CompressionType	m_comp_type;
115

116
      std::unique_ptr<_BufferCtrlObj>	m_buffer_ctrl_obj;
117
      StdBufferCbMgr*			m_buffer_mgr;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
118
    };
119

120
    std::ostream& operator <<(std::ostream& os, Stream::State state);
121
122
    std::ostream& operator <<(std::ostream& os,
			      const Stream::ImageData& img_data);
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
123
124
125
  }
}
#endif	// EIGERSTREAM_H