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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [src/] [librlinktpp/] [RtclRlinkPort.cpp] - Diff between revs 27 and 29

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 27 Rev 29
Line 1... Line 1...
// $Id: RtclRlinkPort.cpp 584 2014-08-22 19:38:12Z mueller $
// $Id: RtclRlinkPort.cpp 632 2015-01-11 12:30:03Z mueller $
//
//
// Copyright 2013-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2013-2015 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
//
// This program is free software; you may redistribute and/or modify it under
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 2, or at your option any later version.
// Software Foundation, either version 2, or at your option any later version.
//
//
Line 11... Line 11...
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for complete details.
// for complete details.
// 
// 
// Revision History: 
// Revision History: 
// Date         Rev Version  Comment
// Date         Rev Version  Comment
 
// 2015-01-09   632   1.0.4  add M_get, M_set, remove M_config
// 2014-08-22   584   1.0.3  use nullptr
// 2014-08-22   584   1.0.3  use nullptr
// 2013-02-23   492   1.0.2  use RlogFile.Name();
// 2013-02-23   492   1.0.2  use RlogFile.Name();
// 2013-02-22   491   1.0.1  use new RlogFile/RlogMsg interfaces
// 2013-02-22   491   1.0.1  use new RlogFile/RlogMsg interfaces
// 2013-01-27   478   1.0    Initial version
// 2013-01-27   478   1.0    Initial version
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
 
 
/*!
/*!
  \file
  \file
  \version $Id: RtclRlinkPort.cpp 584 2014-08-22 19:38:12Z mueller $
  \version $Id: RtclRlinkPort.cpp 632 2015-01-11 12:30:03Z mueller $
  \brief   Implemenation of class RtclRlinkPort.
  \brief   Implemenation of class RtclRlinkPort.
 */
 */
 
 
#include <ctype.h>
#include <ctype.h>
 
 
Line 54... Line 55...
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! Default constructor
//! Default constructor
 
 
RtclRlinkPort::RtclRlinkPort(Tcl_Interp* interp, const char* name)
RtclRlinkPort::RtclRlinkPort(Tcl_Interp* interp, const char* name)
  : RtclProxyBase("RlinkPort"),
  : RtclProxyBase("RlinkPort"),
    fpObj(0),
    fpObj(nullptr),
    fspLog(new RlogFile(&cout, "<cout>")),
    fspLog(new RlogFile(&cout)),
    fTraceLevel(0),
    fTraceLevel(0),
    fErrCnt(0)
    fErrCnt(0)
{
{
  CreateObjectCmd(interp, name);
  CreateObjectCmd(interp, name);
  AddMeth("open",     boost::bind(&RtclRlinkPort::M_open,    this, _1));
  AddMeth("open",     boost::bind(&RtclRlinkPort::M_open,    this, _1));
Line 67... Line 68...
  AddMeth("errcnt",   boost::bind(&RtclRlinkPort::M_errcnt,  this, _1));
  AddMeth("errcnt",   boost::bind(&RtclRlinkPort::M_errcnt,  this, _1));
  AddMeth("rawio",    boost::bind(&RtclRlinkPort::M_rawio,   this, _1));
  AddMeth("rawio",    boost::bind(&RtclRlinkPort::M_rawio,   this, _1));
  AddMeth("stats",    boost::bind(&RtclRlinkPort::M_stats,   this, _1));
  AddMeth("stats",    boost::bind(&RtclRlinkPort::M_stats,   this, _1));
  AddMeth("log",      boost::bind(&RtclRlinkPort::M_log,     this, _1));
  AddMeth("log",      boost::bind(&RtclRlinkPort::M_log,     this, _1));
  AddMeth("dump",     boost::bind(&RtclRlinkPort::M_dump,    this, _1));
  AddMeth("dump",     boost::bind(&RtclRlinkPort::M_dump,    this, _1));
  AddMeth("config",   boost::bind(&RtclRlinkPort::M_config,  this, _1));
  AddMeth("get",      boost::bind(&RtclRlinkPort::M_get,     this, _1));
 
  AddMeth("set",      boost::bind(&RtclRlinkPort::M_set,     this, _1));
  AddMeth("$default", boost::bind(&RtclRlinkPort::M_default, this, _1));
  AddMeth("$default", boost::bind(&RtclRlinkPort::M_default, this, _1));
 
 
 
  SetupGetSet();
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! Destructor
//! Destructor
 
 
Line 93... Line 97...
 
 
  RerrMsg emsg;
  RerrMsg emsg;
  if (args.NOptMiss() == 0) {               // open path
  if (args.NOptMiss() == 0) {               // open path
    delete fpObj;
    delete fpObj;
    fpObj = RlinkPortFactory::Open(path, emsg);
    fpObj = RlinkPortFactory::Open(path, emsg);
 
    SetupGetSet();
    if (!fpObj) return args.Quit(emsg);
    if (!fpObj) return args.Quit(emsg);
    fpObj->SetLogFile(fspLog);
    fpObj->SetLogFile(fspLog);
    fpObj->SetTraceLevel(fTraceLevel);
    fpObj->SetTraceLevel(fTraceLevel);
  } else {                                  // open
  } else {                                  // open
    string name = (fpObj && fpObj->IsOpen()) ? fpObj->Url().Url() : string();
    string name = (fpObj && fpObj->IsOpen()) ? fpObj->Url().Url() : string();
Line 111... Line 116...
int RtclRlinkPort::M_close(RtclArgs& args)
int RtclRlinkPort::M_close(RtclArgs& args)
{
{
  if (!args.AllDone()) return kERR;
  if (!args.AllDone()) return kERR;
  if (!TestOpen(args)) return kERR;
  if (!TestOpen(args)) return kERR;
  delete fpObj;
  delete fpObj;
 
  fpObj = nullptr;
 
  SetupGetSet();
  return kOK;
  return kOK;
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
Line 184... Line 191...
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
int RtclRlinkPort::M_config(RtclArgs& args)
int RtclRlinkPort::M_get(RtclArgs& args)
{
{
  static RtclNameSet optset("-logfile|-logtracelevel");
  return fGets.M_get(args);
 
 
  if (args.NDone() == (size_t)args.Objc()) {
 
    ostringstream sos;
 
    sos << " -logfile {" << fspLog->Name() << "}"
 
        << " -logtracelevel " << RosPrintf(fTraceLevel, "d");
 
    args.AppendResult(sos);
 
    return kOK;
 
  }
  }
 
 
  string opt;
//------------------------------------------+-----------------------------------
  while (args.NextOpt(opt, optset)) {
//! FIXME_docs
    if        (opt == "-logfile") {         // -logfile ?name ------------------
 
      string name;
 
      if (!args.Config("??name", name)) return false;
 
      if (args.NOptMiss() == 0) {             // new filename ?
 
        if (name == "-" || name == "<cout>") {
 
          fspLog->UseStream(&cout, "<cout>");
 
        } else {
 
          if (!fspLog->Open(name)) {
 
            fspLog->UseStream(&cout, "<cout>");
 
            return args.Quit(string("-E: open failed for '") + name +
 
                             "', using stdout");
 
          }
 
        }
 
      }
 
    } else if (opt == "-logtracelevel") {   // -logtracelevel ?loglevel --------
 
      if (!args.Config("??loglevel", fTraceLevel, 3)) return false;
 
      if (fpObj) fpObj->SetTraceLevel(fTraceLevel);
 
    }
 
  }
 
 
 
  if (!args.AllDone()) return kERR;
int RtclRlinkPort::M_set(RtclArgs& args)
  return kOK;
{
 
  return fSets.M_set(args);
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
Line 240... Line 222...
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
 
void RtclRlinkPort::SetupGetSet()
 
{
 
  fGets.Clear();
 
  fSets.Clear();
 
 
 
  fGets.Add<const string&>  ("logfile",
 
                        boost::bind(&RtclRlinkPort::LogFileName, this));
 
  fSets.Add<const string&>  ("logfile",
 
                        boost::bind(&RtclRlinkPort::SetLogFileName, this, _1));
 
 
 
  if (fpObj == nullptr) return;
 
 
 
  fGets.Add<uint32_t>  ("tracelevel",
 
                        boost::bind(&RlinkPort::TraceLevel, fpObj));
 
  fSets.Add<uint32_t>  ("tracelevel",
 
                        boost::bind(&RlinkPort::SetTraceLevel, fpObj, _1));
 
}
 
 
 
//------------------------------------------+-----------------------------------
 
//! FIXME_docs
 
 
bool RtclRlinkPort::TestOpen(RtclArgs& args)
bool RtclRlinkPort::TestOpen(RtclArgs& args)
{
{
  if (fpObj) return true;
  if (fpObj) return true;
  args.AppendResult("-E: port not open", nullptr);
  args.AppendResult("-E: port not open", nullptr);
  return false;
  return false;
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
 
void RtclRlinkPort::SetLogFileName(const std::string& name)
 
{
 
  RerrMsg emsg;
 
  if (!fspLog->Open(name, emsg)) {
 
    fspLog->UseStream(&cout);
 
    throw Rexception("RtclRlinkPort::SetLogFile",
 
                     emsg.Text() + "', using stdout");
 
  }
 
  return;
 
}
 
 
 
//------------------------------------------+-----------------------------------
 
//! FIXME_docs
 
 
 
inline std::string RtclRlinkPort::LogFileName() const
 
{
 
  return fspLog->Name();
 
}
 
 
 
//------------------------------------------+-----------------------------------
 
//! FIXME_docs
 
 
int RtclRlinkPort::DoRawio(RtclArgs& args, RlinkPort* pport, size_t& errcnt)
int RtclRlinkPort::DoRawio(RtclArgs& args, RlinkPort* pport, size_t& errcnt)
{
{
  static RtclNameSet optset("-rblk|-wblk|-edata|-timeout");
  static RtclNameSet optset("-rblk|-wblk|-edata|-timeout");
 
 
  if (!pport || !pport->IsOpen()) args.Quit("-E: port not open");
  if (!pport || !pport->IsOpen()) args.Quit("-E: port not open");

powered by: WebSVN 2.1.0

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