Commit 9d3197fa authored by Laurent Claustre's avatar Laurent Claustre

Merge branch 'core_fixes' into 'master'

Core fixes and modifications

See merge request !21
parents 218cb1a4 2b50c618
......@@ -75,7 +75,7 @@ void Camera::SimuThread::execStartAcq()
buffer_mgr.setStartTimestamp(Timestamp::now());
FrameBuilder& frame_builder = m_simu->m_frame_builder;
frame_builder.resetFrameNr();
frame_builder.resetFrameNr(m_acq_frame_nb);
int nb_frames = m_simu->m_trig_mode == IntTrig ? m_simu->m_nb_frames : m_acq_frame_nb + 1;
int& frame_nb = m_acq_frame_nb;
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// 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 SIMPLEPIPE_H
#define SIMPLEPIPE_H
#include <string>
class Pipe
{
public:
enum {
ReadFd = 0, WriteFd = 1,
};
Pipe(int buff_size = 0);
~Pipe();
void write(std::string s);
std::string read(int len, double timeout = -1);
std::string readLine(int len, std::string term, double timeout = -1);
void close(int which);
private:
bool waitForInput(double timeout);
int m_fd[2];
int m_buff_size;
static const int DefBuffSize;
};
#endif // SIMPLEPIPE_H
......@@ -26,7 +26,7 @@ include $(LIMA_DIR)/control/control.inc
common-objs := Constants.o SizeUtils.o Timestamp.o ThreadUtils.o Exceptions.o \
MemUtils.o RegExUtils.o AcqState.o Debug.o VideoUtils.o Event.o \
Timer.o DirectoryEventUtils.o
Timer.o DirectoryEventUtils.o SimplePipe.o
has_not_inotify = $(shell grep INOTIFY_USER /boot/config-$(shell uname -r) >/dev/null 2>&1; echo $$?)
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// 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/>.
//###########################################################################
#include "lima/SimplePipe.h"
#include <sys/select.h>
#include <iostream>
#include <cmath>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
using namespace std;
//-------------------------------------------------------------
// SimpePipe
//-------------------------------------------------------------
const int Pipe::DefBuffSize = 4096;
Pipe::Pipe(int buff_size)
: m_buff_size(buff_size ? buff_size : DefBuffSize)
{
if (::pipe(m_fd) < 0) {
cerr << "Error creating pipe" << endl;
throw exception();
}
}
Pipe::~Pipe()
{
close(ReadFd);
close(WriteFd);
}
void Pipe::close(int which)
{
int& fd = m_fd[which];
if (fd)
::close(fd);
fd = 0;
}
void Pipe::write(string s)
{
if (::write(m_fd[WriteFd], s.c_str(), s.size()) < 0) {
cerr << "Error writing to pipe" << endl;
throw exception();
}
}
string Pipe::read(int len, double timeout)
{
char buffer[m_buff_size];
string s;
while (int(s.size()) < len) {
if (!waitForInput(timeout))
break;
ssize_t req_read = len - s.size();
if (req_read > m_buff_size)
req_read = m_buff_size;
ssize_t read_bytes = ::read(m_fd[ReadFd], buffer, req_read);
if (read_bytes < 0) {
cerr << "Error reading from pipe" << endl;
throw exception();
} else if (read_bytes == 0)
break;
s.append(buffer, read_bytes);
}
return s;
}
std::string Pipe::readLine(int len, string term, double timeout)
{
if (term.size() == 0)
return read(len, timeout);
string s;
while ((s.size() == 0) || (s.find(term) == s.npos)) {
string r = read(1, timeout);
if (r.size() == 0)
break;
s.append(r);
}
return s;
}
bool Pipe::waitForInput(double timeout)
{
int fd = m_fd[ReadFd];
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
struct timeval tout_ts = {0, 0};
if (timeout > 0) {
tout_ts.tv_sec = long(floor(timeout));
tout_ts.tv_usec = long((timeout - tout_ts.tv_sec) * 1e6);
}
struct timeval *tout_ptr = (timeout >= 0) ? &tout_ts : NULL;
int ret = select(fd + 1, &rfds, NULL, NULL, tout_ptr);
if (ret < 0) {
cerr << "Error in select-read pipe "
<< "(timeout=" << timeout << ")"
<< ": " << strerror(errno) << endl;
throw exception();
}
return (ret > 0);
}
......@@ -324,6 +324,9 @@ CtControl::CtControl(HwInterface *hw) :
{
DEB_CONSTRUCTOR();
// Forces initialisation of PoolThreadMgr (pthread_atfork)
PoolThreadMgr::get();
m_ct_acq= new CtAcquisition(hw);
m_ct_image= new CtImage(hw,*this);
m_ct_buffer= new CtBuffer(hw);
......
Subproject commit 2e73791fc23e95d0aec96fadca998784499a9e48
Subproject commit 0fb65c45b4dee5367a2e26d963c6821900bd4abb
Subproject commit 54b9bda60cd7151af9753054bd0c2472a79a2679
Subproject commit 60ed3a717191fb9bb3aa4d196ed98472f8b9b977
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment