Started work on database handling.
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
#include "ehs/database/DVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
}
|
98
src/db/DbObject.cpp
Normal file
98
src/db/DbObject.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "ehs/db/DbObject.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
DbObject::DbObject()
|
||||
: id(0), loaded(false), parent(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DbObject::DbObject(DbObject&& obj) noexcept
|
||||
: id(obj.id), vars((Array<DbVar>&&)obj.vars), loaded(obj.loaded), parent(obj.parent)
|
||||
{
|
||||
obj.id = 0;
|
||||
obj.loaded = false;
|
||||
obj.parent = nullptr;
|
||||
}
|
||||
|
||||
DbObject::DbObject(const DbObject& obj)
|
||||
: id(obj.id), vars(obj.vars), loaded(obj.loaded), parent(obj.parent)
|
||||
{
|
||||
}
|
||||
|
||||
DbObject& DbObject::operator=(DbObject&& obj) noexcept
|
||||
{
|
||||
if (this == &obj)
|
||||
return *this;
|
||||
|
||||
id = obj.id;
|
||||
vars = (Array<DbVar>&&)obj.vars;
|
||||
loaded = obj.loaded;
|
||||
parent = obj.parent;
|
||||
|
||||
obj.id = 0;
|
||||
obj.loaded = false;
|
||||
obj.parent = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DbObject& DbObject::operator=(const DbObject& obj)
|
||||
{
|
||||
if (this == &obj)
|
||||
return *this;
|
||||
|
||||
id = obj.id;
|
||||
vars = obj.vars;
|
||||
loaded = obj.loaded;
|
||||
parent = obj.parent;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UInt_64 DbObject::GetId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
bool DbObject::HasVariable(UInt_64 hashId)
|
||||
{
|
||||
for (UInt_64 i = 0; i < vars.Size(); ++i)
|
||||
if (vars[i].GetHashId() == hashId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DbVar* DbObject::GetVariable(UInt_64 hashId) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < vars.Size(); ++i)
|
||||
if (vars[i].GetHashId() == hashId)
|
||||
return &vars[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DbObject::Save()
|
||||
{
|
||||
}
|
||||
|
||||
void DbObject::Load()
|
||||
{
|
||||
}
|
||||
|
||||
bool DbObject::IsLoaded() const
|
||||
{
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void DbObject::Free()
|
||||
{
|
||||
vars.Clear();
|
||||
}
|
||||
|
||||
DbTable* DbObject::GetParent() const
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
}
|
39
src/db/DbType.cpp
Normal file
39
src/db/DbType.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "ehs/db/DbType.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
constexpr UInt_8 DbTypeToSize(const DbType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DbType::SINT_64:
|
||||
return 8;
|
||||
case DbType::UINT_64:
|
||||
return 8;
|
||||
case DbType::SINT_32:
|
||||
return 4;
|
||||
case DbType::UINT_32:
|
||||
return 4;
|
||||
case DbType::SINT_16:
|
||||
return 2;
|
||||
case DbType::UINT_16:
|
||||
return 2;
|
||||
case DbType::SINT_8:
|
||||
return 1;
|
||||
case DbType::UINT_8:
|
||||
return 1;
|
||||
case DbType::FLOAT:
|
||||
return 4;
|
||||
case DbType::DOUBLE:
|
||||
return 8;
|
||||
case DbType::BOOLEAN:
|
||||
return 1;
|
||||
case DbType::CHAR_32:
|
||||
return 4;
|
||||
case DbType::CHAR_16:
|
||||
return 2;
|
||||
case DbType::CHAR_8:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
84
src/db/DbVar.cpp
Normal file
84
src/db/DbVar.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "ehs/db/DbVar.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
DbVar::~DbVar()
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
DbVar::DbVar()
|
||||
: hashId(0), size(0), data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DbVar::DbVar(UInt_64 hashId, UInt_64 size, Byte* data)
|
||||
: hashId(hashId), size(size), data(data)
|
||||
{
|
||||
}
|
||||
|
||||
DbVar::DbVar(DbVar&& var) noexcept
|
||||
: hashId(var.hashId), size(var.size), data(var.data)
|
||||
{
|
||||
var.hashId = 0;
|
||||
var.size = 0;
|
||||
var.data = nullptr;
|
||||
}
|
||||
|
||||
DbVar::DbVar(const DbVar& var)
|
||||
: hashId(0), size(0), data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DbVar& DbVar::operator=(DbVar&& var) noexcept
|
||||
{
|
||||
if (this == &var)
|
||||
return *this;
|
||||
|
||||
delete[] data;
|
||||
|
||||
hashId = var.hashId;
|
||||
size = var.size;
|
||||
data = var.data;
|
||||
|
||||
var.hashId = 0;
|
||||
var.size = 0;
|
||||
var.data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DbVar& DbVar::operator=(const DbVar& var)
|
||||
{
|
||||
if (this == &var)
|
||||
return *this;
|
||||
|
||||
delete[] data;
|
||||
|
||||
hashId = 0;
|
||||
size = 0;
|
||||
data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DbVar::operator Byte*() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
UInt_64 DbVar::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
UInt_64 DbVar::GetSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
Byte* DbVar::GetData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
93
src/db/DbVarTmpl.cpp
Normal file
93
src/db/DbVarTmpl.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "ehs/db/DbVarTmpl.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
DbVarTmpl::DbVarTmpl()
|
||||
: hashId(0), type(DbType::SINT_64), array(false)
|
||||
{
|
||||
}
|
||||
|
||||
DbVarTmpl::DbVarTmpl(Str_8 id, DbType type, bool array)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), type(type), array(array)
|
||||
{
|
||||
}
|
||||
|
||||
DbVarTmpl::DbVarTmpl(DbVarTmpl&& varTmpl) noexcept
|
||||
: hashId(varTmpl.hashId), id((Str_8&&)varTmpl.id), type(varTmpl.type), array(varTmpl.array)
|
||||
{
|
||||
varTmpl.hashId = 0;
|
||||
varTmpl.type = DbType::SINT_64;
|
||||
varTmpl.array = false;
|
||||
}
|
||||
|
||||
DbVarTmpl::DbVarTmpl(const DbVarTmpl& varTmpl)
|
||||
: hashId(varTmpl.hashId), id(varTmpl.id), type(varTmpl.type), array(varTmpl.array)
|
||||
{
|
||||
}
|
||||
|
||||
DbVarTmpl& DbVarTmpl::operator=(DbVarTmpl&& varTmpl) noexcept
|
||||
{
|
||||
if (this == &varTmpl)
|
||||
return *this;
|
||||
|
||||
hashId = varTmpl.hashId;
|
||||
id = (Str_8&&)varTmpl.id;
|
||||
type = varTmpl.type;
|
||||
array = varTmpl.array;
|
||||
|
||||
varTmpl.hashId = 0;
|
||||
varTmpl.type = DbType::SINT_64;
|
||||
varTmpl.array = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DbVarTmpl& DbVarTmpl::operator=(const DbVarTmpl& varTmpl)
|
||||
{
|
||||
if (this == &varTmpl)
|
||||
return *this;
|
||||
|
||||
hashId = varTmpl.hashId;
|
||||
id = varTmpl.id;
|
||||
type = varTmpl.type;
|
||||
array = varTmpl.array;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UInt_64 DbVarTmpl::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
void DbVarTmpl::SetId(Str_8 newId)
|
||||
{
|
||||
hashId = newId.Hash_64();
|
||||
id = (Str_8&&)newId;
|
||||
}
|
||||
|
||||
Str_8 DbVarTmpl::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void DbVarTmpl::SetType(DbType newType)
|
||||
{
|
||||
type = newType;
|
||||
}
|
||||
|
||||
DbType DbVarTmpl::GetType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void DbVarTmpl::SetIsArray(bool value)
|
||||
{
|
||||
array = value;
|
||||
}
|
||||
|
||||
bool DbVarTmpl::IsArray() const
|
||||
{
|
||||
return array;
|
||||
}
|
||||
}
|
97
src/io/UsbBase.cpp
Normal file
97
src/io/UsbBase.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "ehs/io/UsbBase.h"
|
||||
#include "ehs/Util.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
UsbBase::UsbBase()
|
||||
: bus(0), address(0)
|
||||
{
|
||||
}
|
||||
|
||||
UsbBase::UsbBase(const UInt_32 bus, const UInt_32 address)
|
||||
: bus(bus), address(address)
|
||||
{
|
||||
}
|
||||
|
||||
UsbBase::UsbBase(UsbBase&& usb) noexcept
|
||||
: bus(usb.bus), address(usb.address)
|
||||
{
|
||||
usb.bus = 0;
|
||||
usb.address = 0;
|
||||
}
|
||||
|
||||
UsbBase::UsbBase(const UsbBase& usb)
|
||||
: bus(usb.bus), address(usb.address)
|
||||
{
|
||||
}
|
||||
|
||||
UsbBase& UsbBase::operator=(UsbBase&& usb) noexcept
|
||||
{
|
||||
if (this == &usb)
|
||||
return *this;
|
||||
|
||||
bus = usb.bus;
|
||||
address = usb.address;
|
||||
|
||||
usb.bus = 0;
|
||||
usb.address = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UsbBase& UsbBase::operator=(const UsbBase& usb)
|
||||
{
|
||||
if (this == &usb)
|
||||
return *this;
|
||||
|
||||
bus = usb.bus;
|
||||
address = usb.address;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void UsbBase::BulkSend(const Byte* const data, const Size size)
|
||||
{
|
||||
Size out = 0;
|
||||
while (out < size)
|
||||
out = Send(&data[out], size);
|
||||
}
|
||||
|
||||
void UsbBase::BulkReceive(Byte** data, Size* size)
|
||||
{
|
||||
Byte *result = nullptr;
|
||||
Size total = 0;
|
||||
Size in;
|
||||
do
|
||||
{
|
||||
Byte *resize = new Byte[(total + *size) / *size];
|
||||
Util::Copy(resize, result, total);
|
||||
|
||||
in = Receive(&resize[total], *size);
|
||||
total += in;
|
||||
|
||||
delete[] result;
|
||||
result = resize;
|
||||
}
|
||||
while (in);
|
||||
|
||||
*size = total;
|
||||
}
|
||||
|
||||
UInt_32 UsbBase::GetBus() const
|
||||
{
|
||||
return bus;
|
||||
}
|
||||
|
||||
UInt_32 UsbBase::GetAddress() const
|
||||
{
|
||||
return address;
|
||||
}
|
||||
|
||||
bool UsbBase::IsValid() const
|
||||
{
|
||||
return bus && address;
|
||||
}
|
||||
}
|
106
src/io/Usb_LNX.cpp
Normal file
106
src/io/Usb_LNX.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "ehs/io/Usb_LNX.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
Usb::~Usb()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Usb::Usb()
|
||||
: hdl(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Usb::Usb(const UInt_32 bus, const UInt_32 address)
|
||||
: UsbBase(bus, address), hdl(-1)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
Usb::Usb(Usb&& usb) noexcept
|
||||
: UsbBase((UsbBase&&)usb), hdl(usb.hdl)
|
||||
{
|
||||
usb.hdl = -1;
|
||||
}
|
||||
|
||||
Usb::Usb(const Usb& usb)
|
||||
: UsbBase(usb), hdl(-1)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
Usb& Usb::operator=(Usb&& usb) noexcept
|
||||
{
|
||||
if (this == &usb)
|
||||
return *this;
|
||||
|
||||
UsbBase::operator=((UsbBase&&)usb);
|
||||
|
||||
hdl = usb.hdl;
|
||||
|
||||
usb.hdl = -1;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Usb& Usb::operator=(const Usb& usb)
|
||||
{
|
||||
if (this == &usb)
|
||||
return *this;
|
||||
|
||||
UsbBase::operator=(usb);
|
||||
|
||||
hdl = -1;
|
||||
|
||||
Initialize();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Usb::Initialize()
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Cannot initialize with an invalid object.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsInitialized())
|
||||
{
|
||||
EHS_LOG_INT("Warning", 1, "Object is already initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
hdl = open("/dev/bus/usb/" + Str_8::FromNum(GetBus()) + "/" + Str_8::FromNum(GetAddress()), O_RDWR);
|
||||
if (hdl == -1)
|
||||
EHS_LOG_INT("Error", 2, "Failed to connect to USB device.");
|
||||
}
|
||||
|
||||
void Usb::Release()
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Cannot release with an invalid object.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsInitialized())
|
||||
{
|
||||
EHS_LOG_INT("Warning", 1, "Object is already released.");
|
||||
return;
|
||||
}
|
||||
|
||||
close(hdl);
|
||||
|
||||
hdl = -1;
|
||||
}
|
||||
|
||||
bool Usb::IsInitialized() const
|
||||
{
|
||||
return hdl != -1;
|
||||
}
|
||||
}
|
@@ -275,6 +275,7 @@ namespace ehs
|
||||
|
||||
meshes[i].SetIndices(data.ReadArray<UInt_32, UInt_64>());
|
||||
|
||||
/*
|
||||
Bone& skeleton = mdl->GetSkeleton();
|
||||
UInt_8 boneCount = data.Read<UInt_8>();
|
||||
for (UInt_8 b = 0; b < boneCount; ++b)
|
||||
@@ -328,6 +329,7 @@ namespace ehs
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user