debug:调试了一下filehandle,大致了解了使用原理。
This commit is contained in:
parent
ecce50d58f
commit
7a1deaba1d
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@ -96,6 +96,14 @@
|
||||
"xutility": "cpp",
|
||||
"mutex": "cpp",
|
||||
"array": "cpp",
|
||||
"chrono": "cpp"
|
||||
"chrono": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"ratio": "cpp",
|
||||
"shared_mutex": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"thread": "cpp"
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@ mainpanel.h
|
||||
mainpanel.cxx
|
||||
modeDirCtrl.h
|
||||
modeDirCtrl.cxx
|
||||
transmhandler.h
|
||||
transmhandler.cxx
|
||||
)
|
||||
|
||||
add_executable(gtransm ${PSOURCES})
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
CModeDirCtrl::CModeDirCtrl(wxWindow* parent, wxWindowID id) : wxGenericDirCtrl(parent, id)
|
||||
{
|
||||
wxFileSystem::AddHandler(new CTransmHandler());
|
||||
wxFileSystem::AddHandler(new wxLocalFSHandler());
|
||||
wxFileSystem fs;
|
||||
wxFSFile* f = fs.OpenFile("transm://D:/test.txt");
|
||||
if (f == nullptr) {
|
||||
wxLogError("Cannot open file");
|
||||
}
|
||||
}
|
||||
|
||||
CModeDirCtrl::~CModeDirCtrl()
|
||||
|
@ -1,13 +1,18 @@
|
||||
#ifndef MODEDIRCTRL_H
|
||||
#define MODEDIRCTRL_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include "transmhandler.h"
|
||||
#include <wx/dirctrl.h>
|
||||
#include <wx/wx.h>
|
||||
|
||||
class CModeDirCtrl : public wxGenericDirCtrl {
|
||||
class CModeDirCtrl : public wxGenericDirCtrl
|
||||
{
|
||||
public:
|
||||
CModeDirCtrl(wxWindow* parent, wxWindowID id = wxID_ANY);
|
||||
~CModeDirCtrl();
|
||||
|
||||
protected:
|
||||
// void OnExpandItem(wxTreeEvent& event) override;
|
||||
};
|
||||
|
||||
#endif // MODEDIRCTRL_H
|
22
gui/transmhandler.cxx
Normal file
22
gui/transmhandler.cxx
Normal file
@ -0,0 +1,22 @@
|
||||
#include "transmhandler.h"
|
||||
|
||||
CTransmHandler::CTransmHandler()
|
||||
{
|
||||
file_ = std::make_shared<CTransmFile>();
|
||||
}
|
||||
|
||||
wxFSFile* CTransmHandler::OpenFile(wxFileSystem& fs, const wxString& name)
|
||||
{
|
||||
int a = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CTransmHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
return location.StartsWith(wxT("transm://"));
|
||||
}
|
||||
|
||||
wxString CTransmHandler::FindFirst(const wxString& spec, int flags)
|
||||
{
|
||||
return wxString();
|
||||
}
|
22
gui/transmhandler.h
Normal file
22
gui/transmhandler.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef FILEHANDLER_H
|
||||
#define FILEHANDLER_H
|
||||
|
||||
#include <transmfile.h>
|
||||
#include <wx/filesys.h>
|
||||
#include <wx/wx.h>
|
||||
|
||||
class CTransmHandler : public wxFileSystemHandler
|
||||
{
|
||||
public:
|
||||
CTransmHandler();
|
||||
|
||||
public:
|
||||
wxFSFile* OpenFile(wxFileSystem& fs, const wxString& name) override;
|
||||
bool CanOpen(const wxString& location) override;
|
||||
wxString FindFirst(const wxString& spec, int flags = 0) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<CTransmFile> file_;
|
||||
};
|
||||
|
||||
#endif // FILEHANDLER_H
|
@ -4,16 +4,15 @@ project(protocol LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(wxWidgets CONFIG REQUIRED)
|
||||
|
||||
set(PSOURCES
|
||||
filebase.h
|
||||
filebase.cxx
|
||||
transmfile.h
|
||||
transmfile.cxx
|
||||
communicate.h
|
||||
communicate.cxx
|
||||
fileimp/localfile.h
|
||||
fileimp/localfile.cxx
|
||||
fileimp/remotefile.h
|
||||
fileimp/remotefile.cxx
|
||||
)
|
||||
|
||||
add_library(protocol STATIC ${PSOURCES})
|
||||
target_link_libraries(protocol PRIVATE wx::base)
|
||||
target_include_directories(protocol PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
@ -1,27 +0,0 @@
|
||||
#include "filebase.h"
|
||||
#include "fileimp/localfile.h"
|
||||
#include "fileimp/remotefile.h"
|
||||
|
||||
CFileBase::CFileBase()
|
||||
{
|
||||
}
|
||||
|
||||
CFileBase::~CFileBase()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<CFileBase> CFileBase::Instance(FileOperType type)
|
||||
{
|
||||
std::shared_ptr<CFileBase> ret = nullptr;
|
||||
switch (type) {
|
||||
case TYPE_LOCAL:
|
||||
ret = std::make_shared<CLocalFile>();
|
||||
break;
|
||||
case TYPE_REMOTE:
|
||||
ret = std::make_shared<CRemoteFile>();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#ifndef FILEBASE_H
|
||||
#define FILEBASE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
enum FileOperType {
|
||||
TYPE_LOCAL,
|
||||
TYPE_REMOTE
|
||||
};
|
||||
|
||||
class CFileBase
|
||||
{
|
||||
public:
|
||||
CFileBase();
|
||||
virtual ~CFileBase();
|
||||
|
||||
public:
|
||||
virtual bool Open(const char* filename) = 0;
|
||||
|
||||
public:
|
||||
static std::shared_ptr<CFileBase> Instance(FileOperType type);
|
||||
};
|
||||
|
||||
#endif // FILEBASE_H
|
@ -1,14 +0,0 @@
|
||||
#include "localfile.h"
|
||||
|
||||
CLocalFile::CLocalFile()
|
||||
{
|
||||
}
|
||||
|
||||
CLocalFile::~CLocalFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool CLocalFile::Open(const char* filename)
|
||||
{
|
||||
return false;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#ifndef LOCALFILE_H
|
||||
#define LOCALFILE_H
|
||||
|
||||
#include "../filebase.h"
|
||||
|
||||
class CLocalFile : public CFileBase
|
||||
{
|
||||
public:
|
||||
CLocalFile();
|
||||
~CLocalFile();
|
||||
|
||||
public:
|
||||
bool Open(const char* filename) override;
|
||||
};
|
||||
|
||||
#endif // LOCALFILE_H
|
@ -1,14 +0,0 @@
|
||||
#include "remotefile.h"
|
||||
|
||||
CRemoteFile::CRemoteFile()
|
||||
{
|
||||
}
|
||||
|
||||
CRemoteFile::~CRemoteFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool CRemoteFile::Open(const char* filename)
|
||||
{
|
||||
return false;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#ifndef REMOTE_H
|
||||
#define REMOTE_H
|
||||
|
||||
#include "../filebase.h"
|
||||
|
||||
class CRemoteFile : public CFileBase
|
||||
{
|
||||
public:
|
||||
CRemoteFile();
|
||||
~CRemoteFile();
|
||||
|
||||
public:
|
||||
bool Open(const char* filename) override;
|
||||
};
|
||||
|
||||
#endif // REMOTE_H
|
13
protocol/transmfile.cxx
Normal file
13
protocol/transmfile.cxx
Normal file
@ -0,0 +1,13 @@
|
||||
#include "transmfile.h"
|
||||
|
||||
CTransmFile::CTransmFile()
|
||||
{
|
||||
}
|
||||
|
||||
CTransmFile::~CTransmFile()
|
||||
{
|
||||
}
|
||||
|
||||
void CTransmFile::SetRemoteIpPort(const wxString& remote_ip, int remote_port)
|
||||
{
|
||||
}
|
22
protocol/transmfile.h
Normal file
22
protocol/transmfile.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef FILEBASE_H
|
||||
#define FILEBASE_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <wx/wx.h>
|
||||
|
||||
class CTransmFile
|
||||
{
|
||||
public:
|
||||
CTransmFile();
|
||||
~CTransmFile();
|
||||
|
||||
public:
|
||||
void SetRemoteIpPort(const wxString& remote_ip, int remote_port);
|
||||
|
||||
protected:
|
||||
wxString remote_ip_{};
|
||||
int remote_port_{9898};
|
||||
};
|
||||
|
||||
#endif // FILEBASE_Ha
|
Loading…
x
Reference in New Issue
Block a user