Small changes
This commit is contained in:
parent
8c600a1cdb
commit
e50cb9f0e2
7 changed files with 131 additions and 79 deletions
|
|
@ -4,4 +4,62 @@
|
|||
|
||||
namespace tp {
|
||||
extern ModuleManifest gModuleConnection;
|
||||
};
|
||||
|
||||
class Connection {
|
||||
public:
|
||||
typedef ualni SizeBytes;
|
||||
typedef ualni BytePointer;
|
||||
typedef int1 Byte;
|
||||
|
||||
class Status {
|
||||
public:
|
||||
enum State {
|
||||
NONE,
|
||||
OPENED,
|
||||
CLOSED,
|
||||
DENIED,
|
||||
INVALID,
|
||||
};
|
||||
|
||||
private:
|
||||
State mStatus = NONE;
|
||||
|
||||
public:
|
||||
Status() = default;
|
||||
[[nodiscard]] State getStatus() const { return mStatus; }
|
||||
void setStatus(State status) { mStatus = status; }
|
||||
[[nodiscard]] bool isOpened() const { return mStatus == OPENED; }
|
||||
};
|
||||
|
||||
class Type {
|
||||
public:
|
||||
enum State {
|
||||
READ,
|
||||
WRITE,
|
||||
READ_WRITE,
|
||||
NONE,
|
||||
};
|
||||
|
||||
private:
|
||||
State mHandleType = NONE;
|
||||
|
||||
public:
|
||||
Type() = default;
|
||||
explicit Type(bool read) : mHandleType((State) read) {}
|
||||
explicit Type(State handleType) : mHandleType(handleType) {}
|
||||
[[nodiscard]] State getType() const { return mHandleType; }
|
||||
[[nodiscard]] bool isRead() const { return mHandleType == READ; }
|
||||
[[nodiscard]] bool isWrite() const { return mHandleType == WRITE; }
|
||||
};
|
||||
|
||||
protected:
|
||||
Status mStatus;
|
||||
Type mConnectionType;
|
||||
|
||||
public:
|
||||
Connection() = default;
|
||||
|
||||
virtual const Status& getConnectionStatus() { return mStatus; }
|
||||
virtual const Type& getConnectionType() { return mConnectionType; }
|
||||
};
|
||||
}
|
||||
|
|
@ -3,73 +3,20 @@
|
|||
#include "ConnectionCommon.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
class LocalConnectionContext;
|
||||
|
||||
class LocalConnectionLocation {
|
||||
String mLocation;
|
||||
class LocalConnection : public Connection {
|
||||
public:
|
||||
LocalConnectionLocation() : mLocation("tmp") {};
|
||||
explicit LocalConnectionLocation(const String& location) : mLocation(location) {}
|
||||
void setLocation(const String& location) { mLocation = location; }
|
||||
[[nodiscard]] const String& getLocation() const { return mLocation; }
|
||||
[[nodiscard]] bool exists() const;
|
||||
};
|
||||
|
||||
class LocalConnectionType {
|
||||
public:
|
||||
enum HandleType {
|
||||
READ,
|
||||
WRITE,
|
||||
NONE,
|
||||
class Location {
|
||||
String mLocation;
|
||||
public:
|
||||
Location() : mLocation("tmp") {};
|
||||
explicit Location(const String& location) : mLocation(location) {}
|
||||
void setLocation(const String& location) { mLocation = location; }
|
||||
[[nodiscard]] const String& getLocation() const { return mLocation; }
|
||||
[[nodiscard]] bool exists() const;
|
||||
};
|
||||
|
||||
private:
|
||||
HandleType mHandleType;
|
||||
|
||||
public:
|
||||
LocalConnectionType() : mHandleType(NONE) {}
|
||||
explicit LocalConnectionType(bool read) : mHandleType((HandleType) read) {}
|
||||
explicit LocalConnectionType(HandleType handleType) : mHandleType(handleType) {}
|
||||
[[nodiscard]] HandleType getType() const { return mHandleType; }
|
||||
[[nodiscard]] bool isRead() const { return mHandleType == READ; }
|
||||
[[nodiscard]] bool isWrite() const { return mHandleType == WRITE; }
|
||||
};
|
||||
|
||||
class LocalConnectionStatus {
|
||||
public:
|
||||
enum Status {
|
||||
NONE,
|
||||
OPENED,
|
||||
CLOSED,
|
||||
DENIED,
|
||||
INVALID,
|
||||
};
|
||||
|
||||
private:
|
||||
Status mStatus = NONE;
|
||||
|
||||
public:
|
||||
LocalConnectionStatus() = default;
|
||||
[[nodiscard]] Status getStatus() const { return mStatus; }
|
||||
void setStatus(Status status) { mStatus = status; }
|
||||
[[nodiscard]] bool isOpened() const { return mStatus == OPENED; }
|
||||
};
|
||||
|
||||
class LocalConnection {
|
||||
typedef ualni SizeBytes;
|
||||
typedef ualni BytePointer;
|
||||
typedef int1 Byte;
|
||||
|
||||
private:
|
||||
LocalConnectionContext* mHandle = nullptr;
|
||||
|
||||
LocalConnectionLocation mLocation;
|
||||
LocalConnectionType mConnectionType;
|
||||
LocalConnectionStatus mStatus;
|
||||
|
||||
BytePointer mPointer = 0;
|
||||
|
||||
public:
|
||||
LocalConnection() {
|
||||
MODULE_SANITY_CHECK(gModuleConnection)
|
||||
|
|
@ -80,13 +27,13 @@ namespace tp {
|
|||
}
|
||||
|
||||
public:
|
||||
virtual bool connect(const LocalConnectionLocation& location, const LocalConnectionType& connectionInfo);
|
||||
virtual bool connect(const Location& location, const Type& connectionInfo);
|
||||
virtual bool disconnect();
|
||||
|
||||
public:
|
||||
virtual const LocalConnectionStatus& getConnectionStatus() { return mStatus; }
|
||||
virtual const LocalConnectionType& getConnectionType() { return mConnectionType; }
|
||||
virtual const LocalConnectionLocation& getLocation() { return mLocation; }
|
||||
virtual const Status& getConnectionStatus() { return mStatus; }
|
||||
virtual const Type& getConnectionType() { return mConnectionType; }
|
||||
virtual const Location& getLocation() { return mLocation; }
|
||||
|
||||
public:
|
||||
virtual bool setPointer(BytePointer pointer);
|
||||
|
|
@ -95,5 +42,10 @@ namespace tp {
|
|||
|
||||
public:
|
||||
virtual SizeBytes size();
|
||||
|
||||
private:
|
||||
LocalConnectionContext* mHandle = nullptr;
|
||||
Location mLocation;
|
||||
BytePointer mPointer = 0;
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
|
||||
#include "ConnectionCommon.hpp"
|
||||
#include "List.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
class RemoteConnectionContext;
|
||||
|
||||
class RemoteConnection : public Connection {
|
||||
public:
|
||||
class Location {
|
||||
ualni mId = 0;
|
||||
public:
|
||||
Location() = default;
|
||||
};
|
||||
|
||||
public:
|
||||
RemoteConnection() {
|
||||
MODULE_SANITY_CHECK(gModuleConnection)
|
||||
};
|
||||
|
||||
virtual ~RemoteConnection() {
|
||||
if (mStatus.isOpened()) RemoteConnection::disconnect();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual bool connect(const Location& location, const Type& connectionInfo);
|
||||
virtual bool disconnect();
|
||||
|
||||
public:
|
||||
virtual const Location& getLocation() { return mLocation; }
|
||||
|
||||
public:
|
||||
virtual bool readBytes(Byte* bytes, SizeBytes size);
|
||||
virtual bool writeBytes(const Byte* bytes, SizeBytes size);
|
||||
|
||||
private:
|
||||
RemoteConnectionContext* mHandle = nullptr;
|
||||
Location mLocation;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue