ollie/kde/gui/lib9pclient.h

64 lines
1.9 KiB
C++

#ifndef LIB9PCLIENT_H
#define LIB9PCLIENT_H
#include <QObject>
#include <QString>
#include <QByteArray>
#include <libollie9p.h>
// Qt wrapper for libollie9p - provides a clean C++ interface to the Go 9P library.
// Single persistent connection, thread-safe (Go handles internal locking).
class Lib9pClient : public QObject
{
Q_OBJECT
public:
explicit Lib9pClient(QObject *parent = nullptr);
~Lib9pClient() override;
// Connection management
bool connect(const QString &addr, const QString &user, const QString &aname);
bool connectDefault(); // Uses NAMESPACE and USER env vars
void disconnect();
bool isConnected() const { return m_handle > 0; }
// File operations - all return empty/false on error, check lastError()
QByteArray read(const QString &path);
bool write(const QString &path, const QByteArray &data);
QByteArray rdwr(const QString &path, const QByteArray &data); // Write then read
// Directory operations
QStringList ls(const QString &path);
// Metadata
struct StatResult {
QString mode;
qint64 size;
qint64 mtime;
QString name;
bool valid = false;
};
StatResult stat(const QString &path);
// File management
bool remove(const QString &path);
bool create(const QString &path, uint perm = 0666);
bool mkdir(const QString &path);
bool rename(const QString &oldPath, const QString &newName);
// Streaming API - for continuous reads (chat, statewait, etc.)
int open(const QString &path); // Returns fid handle, -1 on error
int readFid(int fid, char *buf, int bufLen); // Returns bytes read, 0 on EOF, -1 on error
void closeFid(int fid);
// Error handling
QString lastError() const { return m_lastError; }
private:
void updateLastError();
int m_handle = -1;
QString m_lastError;
};
#endif // LIB9PCLIENT_H