EigerStream.h 3.55 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
47
      enum State {Init,Idle,Starting,Connected,Failed,Armed,Running,
		  Stopped,Aborting,Quitting};
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
48

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

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

      void start();
      void stop();
61
      void abort();
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
62
      bool isRunning() const;
63
      void waitArmed(double timeout);
64

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

      HwBufferCtrlObj* getBufferCtrlObj();
72

73
      ImageData get_msg(void* aDataBuffer);
74
      void release_all_msgs();
75
76
77

      void getLastStreamInfo(StreamInfo& info);

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

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

      bool _isRunning() const;
87

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
88
89
      static void* _runFunc(void*);
      void _run();
90
91
92
93
      void _run_sequence();
      Json::Value _get_global_header(const Json::Value& stream_header,
				     MessageList& pending_messages);
      Json::Value _get_json_header(MessagePtr &msg);
94
      bool _read_zmq_messages(void *stream_socket);
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
95
      void _send_synchro();
96
      void _abort();
97
      void _checkCompression(const StreamInfo& info);
98

99
100
101
      void _setStreamMode(bool enabled);
      bool _getStreamMode();

Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
102
      Camera&		m_cam;
103
      char		m_endianess;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
104
105
      bool		m_active;
      HeaderDetail	m_header_detail;
106
      std::string	m_header_detail_str;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
107
      bool		m_dirty_flag;
108
      State		m_state;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
109
110
111
112
113
114

      mutable Cond	m_cond;

      pthread_t		m_thread_id;
      void*		m_zmq_context;
      int		m_pipes[2];
115
      Data2Message	m_data_2_msg;
116
      StreamInfo	m_last_info;
117
      bool		m_ext_trigger;
118
      CompressionType	m_comp_type;
119

120
      std::unique_ptr<_BufferCtrlObj>	m_buffer_ctrl_obj;
121
      StdBufferCbMgr*			m_buffer_mgr;
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
122
    };
123

124
    std::ostream& operator <<(std::ostream& os, Stream::State state);
125
126
    std::ostream& operator <<(std::ostream& os,
			      const Stream::ImageData& img_data);
Sebastien Petitdemange's avatar
Sebastien Petitdemange committed
127
128
129
  }
}
#endif	// EIGERSTREAM_H