OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librlink/] [RlinkPortFifo.cpp] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 wfjm
// $Id: RlinkPortFifo.cpp 516 2013-05-05 21:24:52Z mueller $
2 10 wfjm
//
3 19 wfjm
// Copyright 2011-2013 y Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 10 wfjm
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16 19 wfjm
// 2013-02-23   492   1.1    use RparseUrl
17 10 wfjm
// 2011-03-27   374   1.0    Initial version
18
// 2011-01-15   356   0.1    First draft
19
// ---------------------------------------------------------------------------
20
 
21
/*!
22
  \file
23 21 wfjm
  \version $Id: RlinkPortFifo.cpp 516 2013-05-05 21:24:52Z mueller $
24 10 wfjm
  \brief   Implemenation of RlinkPortFifo.
25
*/
26
 
27
#include <sys/types.h>
28
#include <sys/stat.h>
29
#include <fcntl.h>
30
#include <errno.h>
31
 
32
#include "RlinkPortFifo.hpp"
33
 
34
using namespace std;
35
 
36
/*!
37
  \class Retro::RlinkPortFifo
38 19 wfjm
  \brief FIXME_docs
39 10 wfjm
*/
40
 
41 19 wfjm
// all method definitions in namespace Retro
42
namespace Retro {
43
 
44 10 wfjm
//------------------------------------------+-----------------------------------
45
//! Default constructor
46
 
47
RlinkPortFifo::RlinkPortFifo()
48
  : RlinkPort()
49
{}
50
 
51
//------------------------------------------+-----------------------------------
52
//! Destructor
53
 
54
RlinkPortFifo::~RlinkPortFifo()
55 17 wfjm
{
56
  // no need to call Close() here, no RlinkPortFifo::Close()
57
  // cleanup will be done by ~RlinkPort()
58
}
59 10 wfjm
 
60
//------------------------------------------+-----------------------------------
61 19 wfjm
//! FIXME_docs
62 10 wfjm
 
63
bool RlinkPortFifo::Open(const std::string& url, RerrMsg& emsg)
64
{
65
  if (IsOpen()) Close();
66
 
67 19 wfjm
  if (!fUrl.Set(url, "|keep|", emsg)) return false;
68 10 wfjm
 
69
  // Note: _rx fifo must be opened before the _tx fifo, otherwise the test
70
  //       bench might close with EOF on read prematurely (is a race condition).
71
 
72 19 wfjm
  fFdWrite = OpenFifo(fUrl.Path() + "_rx", true, emsg);
73 10 wfjm
  if (fFdWrite < 0) return false;
74
 
75 19 wfjm
  fFdRead = OpenFifo(fUrl.Path() + "_tx", false, emsg);
76 10 wfjm
  if (fFdRead < 0) {
77
    close(fFdWrite);
78
    fFdWrite = -1;
79
    return false;
80
  }
81
 
82
  fIsOpen  = true;
83
 
84
  return true;
85
}
86
 
87
//------------------------------------------+-----------------------------------
88 19 wfjm
//! FIXME_docs
89 10 wfjm
 
90
int RlinkPortFifo::OpenFifo(const std::string& name, bool snd, RerrMsg& emsg)
91
{
92
  struct stat stat_fifo;
93
 
94
  int irc;
95
 
96
  irc = stat(name.c_str(), &stat_fifo);
97
  if (irc == 0) {
98
    if ((stat_fifo.st_mode & S_IFIFO) == 0) {
99
      emsg.Init("RlinkPortFifo::OpenFiFo()",
100 21 wfjm
                string("'") + name + "' exists but is not a pipe");
101 10 wfjm
      return -1;
102
    }
103
  } else {
104
    mode_t mode = S_IRUSR | S_IWUSR;        // user read and write allowed
105
    irc = mkfifo(name.c_str(), mode);
106
    if (irc != 0) {
107
      emsg.InitErrno("RlinkPortFifo::OpenFifo()",
108 21 wfjm
                     string("mkfifo() for '") + name + "' failed: ",
109 10 wfjm
                     errno);
110
      return -1;
111
    }
112
  }
113
 
114
  irc = open(name.c_str(), snd ? O_WRONLY : O_RDONLY);
115
  if (irc < 0) {
116
    emsg.InitErrno("RlinkPortFifo::OpenFifo()",
117 21 wfjm
                   string("open() for '") + name + "' failed: ",
118 10 wfjm
                   errno);
119
    return -1;
120
  }
121
 
122
  return irc;
123
}
124
 
125 19 wfjm
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.