w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RlinkPortCuff.hpp
Go to the documentation of this file.
1// $Id: RlinkPortCuff.hpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2012-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-17 1088 1.0.2 use std::thread instead of boost
8// 2013-01-02 467 1.0.1 get cleanup code right; add USBErrorName()
9// 2012-12-26 465 1.0 Initial version
10// ---------------------------------------------------------------------------
11
12
17#ifndef included_Retro_RlinkPortCuff
18#define included_Retro_RlinkPortCuff 1
19
20#include "RlinkPort.hpp"
21
22#include <poll.h>
23#include <libusb-1.0/libusb.h>
24
25#include <vector>
26#include <deque>
27#include <thread>
28
29namespace Retro {
30
31 class RlinkPortCuff : public RlinkPort {
32 public:
33
35 virtual ~RlinkPortCuff();
36
37 virtual bool Open(const std::string& url, RerrMsg& emsg);
38 virtual void Close();
39
40 // some constants (also defined in cpp)
41 static const size_t kUSBBufferSize = 4096;
42 static const int kUSBWriteEP = 4 ;
43 static const int kUSBReadEP = 6 ;
44 static const size_t kUSBReadQueue = 2 ;
45
46 // statistics counter indices
47 enum stats {
53 };
54
55 // event loop states
56 enum loopState {
60 };
61
62 protected:
65 std::thread fDriverThread;
66 libusb_context* fpUsbContext;
67 libusb_device** fpUsbDevList;
68 ssize_t fUsbDevCount;
69 libusb_device_handle* fpUsbDevHdl;
71 std::vector<pollfd> fPollFds;
72 std::deque<libusb_transfer*> fWriteQueueFree;
73 std::deque<libusb_transfer*> fWriteQueuePending;
74 std::deque<libusb_transfer*> fReadQueuePending;
75
76 private:
77 void Cleanup();
78 bool OpenPipe(int& fdread, int& fdwrite, RerrMsg& emsg);
79 void Driver();
81 void DriverEventUSB();
82 libusb_transfer* NewWriteTransfer();
83 bool TraceOn();
84 [[noreturn]] void BadSysCall(const char* meth, const char* text, int rc);
85 [[noreturn]] void BadUSBCall(const char* meth, const char* text, int rc);
86 void CheckUSBTransfer(const char* meth, libusb_transfer *t);
87 const char* USBErrorName(int rc);
88
89 void PollfdAdd(int fd, short events);
90 void PollfdRemove(int fd);
91 void USBWriteDone(libusb_transfer* t);
92 void USBReadDone(libusb_transfer* t);
93
94 static void ThunkPollfdAdd(int fd, short events, void* udata);
95 static void ThunkPollfdRemove(int fd, void* udata);
96 static void ThunkUSBWriteDone(libusb_transfer* t);
97 static void ThunkUSBReadDone(libusb_transfer* t);
98
99 };
100
101} // end namespace Retro
102
103//#include "RlinkPortCuff.ipp"
104
105#endif
FIXME_docs.
Definition: RerrMsg.hpp:25
static const int kUSBWriteEP
USB write endpoint.
void PollfdRemove(int fd)
FIXME_docs.
void Cleanup()
FIXME_docs.
int fFdWriteDriver
fd for write (driver end)
static void ThunkPollfdRemove(int fd, void *udata)
FIXME_docs.
virtual void Close()
FIXME_docs.
void Driver()
FIXME_docs.
void USBWriteDone(libusb_transfer *t)
FIXME_docs.
bool OpenPipe(int &fdread, int &fdwrite, RerrMsg &emsg)
FIXME_docs.
libusb_device_handle * fpUsbDevHdl
void DriverEventWritePipe()
FIXME_docs.
void BadUSBCall(const char *meth, const char *text, int rc)
FIXME_docs.
static const size_t kUSBBufferSize
USB buffer size.
void DriverEventUSB()
FIXME_docs.
const char * USBErrorName(int rc)
FIXME_docs.
bool TraceOn()
FIXME_docs.
void USBReadDone(libusb_transfer *t)
FIXME_docs.
void BadSysCall(const char *meth, const char *text, int rc)
FIXME_docs.
std::thread fDriverThread
driver thread
std::deque< libusb_transfer * > fReadQueuePending
std::vector< pollfd > fPollFds
void CheckUSBTransfer(const char *meth, libusb_transfer *t)
FIXME_docs.
std::deque< libusb_transfer * > fWriteQueueFree
RlinkPortCuff()
Default constructor.
virtual ~RlinkPortCuff()
Destructor.
void PollfdAdd(int fd, short events)
FIXME_docs.
libusb_context * fpUsbContext
static void ThunkPollfdAdd(int fd, short events, void *udata)
FIXME_docs.
libusb_device ** fpUsbDevList
static void ThunkUSBWriteDone(libusb_transfer *t)
FIXME_docs.
libusb_transfer * NewWriteTransfer()
FIXME_docs.
std::deque< libusb_transfer * > fWriteQueuePending
static void ThunkUSBReadDone(libusb_transfer *t)
FIXME_docs.
static const size_t kUSBReadQueue
USB read queue length.
static const int kUSBReadEP
USB read endpoint.
virtual bool Open(const std::string &url, RerrMsg &emsg)
FIXME_docs.
int fFdReadDriver
fd for read (driver end)
FIXME_docs.
Definition: RlinkPort.hpp:45
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47