mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Code cleanup, move a lot of "Host" APIs to GpCommon
This commit is contained in:
@@ -2,11 +2,7 @@
|
||||
|
||||
#include "EGpAudioDriverType.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class HostSystemServices;
|
||||
}
|
||||
|
||||
struct IGpSystemServices;
|
||||
struct IGpAudioDriver;
|
||||
struct IGpLogDriver;
|
||||
|
||||
@@ -18,5 +14,5 @@ struct GpAudioDriverProperties
|
||||
bool m_debug;
|
||||
|
||||
IGpLogDriver *m_logger;
|
||||
PortabilityLayer::HostSystemServices *m_systemServices;
|
||||
IGpSystemServices *m_systemServices;
|
||||
};
|
||||
|
||||
@@ -9,11 +9,7 @@ struct IGpDisplayDriver;
|
||||
struct IGpFiber;
|
||||
struct IGpVOSEventQueue;
|
||||
struct IGpLogDriver;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class HostSystemServices;
|
||||
}
|
||||
struct IGpSystemServices;
|
||||
|
||||
struct GpDisplayDriverProperties
|
||||
{
|
||||
@@ -46,5 +42,5 @@ struct GpDisplayDriverProperties
|
||||
|
||||
IGpVOSEventQueue *m_eventQueue;
|
||||
IGpLogDriver *m_logger;
|
||||
PortabilityLayer::HostSystemServices *m_systemServices;
|
||||
IGpSystemServices *m_systemServices;
|
||||
};
|
||||
|
||||
132
GpCommon/GpDriverIndex.h
Normal file
132
GpCommon/GpDriverIndex.h
Normal file
@@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace GpDriverIDs
|
||||
{
|
||||
enum GpDriverID
|
||||
{
|
||||
kAudio,
|
||||
kFileSystem,
|
||||
kDisplay,
|
||||
kLog,
|
||||
kInput,
|
||||
kSystemServices,
|
||||
kFont,
|
||||
kEventQueue,
|
||||
|
||||
kCount
|
||||
};
|
||||
}
|
||||
|
||||
typedef GpDriverIDs::GpDriverID GpDriverID_t;
|
||||
|
||||
template<int T>
|
||||
struct GpDriverIndex
|
||||
{
|
||||
};
|
||||
|
||||
#define GP_DEFINE_DRIVER(driverID, type) \
|
||||
struct type;\
|
||||
template<>\
|
||||
struct GpDriverIndex<GpDriverIDs::driverID>\
|
||||
{\
|
||||
typedef type Type_t;\
|
||||
static const bool kIsMultiDriver = false;\
|
||||
}
|
||||
|
||||
#define GP_DEFINE_MULTI_DRIVER(driverID, type) \
|
||||
struct type;\
|
||||
template<>\
|
||||
struct GpDriverIndex<GpDriverIDs::driverID>\
|
||||
{\
|
||||
typedef type Type_t;\
|
||||
static const bool kIsMultiDriver = true;\
|
||||
}
|
||||
|
||||
GP_DEFINE_DRIVER(kAudio, IGpAudioDriver);
|
||||
GP_DEFINE_DRIVER(kFileSystem, IGpFileSystem);
|
||||
GP_DEFINE_DRIVER(kDisplay, IGpDisplayDriver);
|
||||
GP_DEFINE_DRIVER(kLog, IGpLogDriver);
|
||||
GP_DEFINE_MULTI_DRIVER(kInput, IGpInputDriver);
|
||||
GP_DEFINE_DRIVER(kSystemServices, IGpSystemServices);
|
||||
GP_DEFINE_DRIVER(kFont, IGpFontHandler);
|
||||
GP_DEFINE_DRIVER(kEventQueue, IGpVOSEventQueue);
|
||||
|
||||
struct GpDriverCollection
|
||||
{
|
||||
GpDriverCollection();
|
||||
|
||||
template<GpDriverID_t T>
|
||||
void SetDriver(typename GpDriverIndex<T>::Type_t *driver);
|
||||
|
||||
template<GpDriverID_t T>
|
||||
void SetDrivers(typename GpDriverIndex<T>::Type_t *const* drivers, size_t numDrivers);
|
||||
|
||||
template<GpDriverID_t T>
|
||||
typename GpDriverIndex<T>::Type_t *GetDriver() const;
|
||||
|
||||
template<GpDriverID_t T>
|
||||
typename GpDriverIndex<T>::Type_t *GetDriver(size_t index) const;
|
||||
|
||||
template<GpDriverID_t T>
|
||||
size_t GetDriverCount() const;
|
||||
|
||||
private:
|
||||
struct DriverEntry
|
||||
{
|
||||
void *m_value;
|
||||
size_t m_numDrivers;
|
||||
};
|
||||
|
||||
DriverEntry m_drivers[GpDriverIDs::kCount];
|
||||
};
|
||||
|
||||
inline GpDriverCollection::GpDriverCollection()
|
||||
{
|
||||
for (int i = 0; i < GpDriverIDs::kCount; i++)
|
||||
{
|
||||
this->m_drivers[i].m_value = nullptr;
|
||||
this->m_drivers[i].m_numDrivers = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<GpDriverID_t T>
|
||||
void GpDriverCollection::SetDriver(typename GpDriverIndex<T>::Type_t *driver)
|
||||
{
|
||||
GP_STATIC_ASSERT(!GpDriverIndex<T>::kIsMultiDriver);
|
||||
m_drivers[T].m_numDrivers = 1;
|
||||
m_drivers[T].m_value = driver;
|
||||
}
|
||||
|
||||
template<GpDriverID_t T>
|
||||
void GpDriverCollection::SetDrivers(typename GpDriverIndex<T>::Type_t *const* drivers, size_t numDrivers)
|
||||
{
|
||||
GP_STATIC_ASSERT(GpDriverIndex<T>::kIsMultiDriver);
|
||||
m_drivers[T].m_numDrivers = numDrivers;
|
||||
m_drivers[T].m_value = const_cast<typename GpDriverIndex<T>::Type_t **>(drivers);
|
||||
}
|
||||
|
||||
template<GpDriverID_t T>
|
||||
inline typename GpDriverIndex<T>::Type_t *GpDriverCollection::GetDriver() const
|
||||
{
|
||||
GP_STATIC_ASSERT(!GpDriverIndex<T>::kIsMultiDriver);
|
||||
return static_cast<typename GpDriverIndex<T>::Type_t*>(this->m_drivers[T].m_value);
|
||||
}
|
||||
|
||||
template<GpDriverID_t T>
|
||||
inline typename GpDriverIndex<T>::Type_t *GpDriverCollection::GetDriver(size_t index) const
|
||||
{
|
||||
GP_STATIC_ASSERT(GpDriverIndex<T>::kIsMultiDriver);
|
||||
return static_cast<typename GpDriverIndex<T>::Type_t*const*>(this->m_drivers[T].m_value)[index];
|
||||
}
|
||||
|
||||
|
||||
template<GpDriverID_t T>
|
||||
size_t GpDriverCollection::GetDriverCount() const
|
||||
{
|
||||
GP_STATIC_ASSERT(GpDriverIndex<T>::kIsMultiDriver);
|
||||
return this->m_drivers[T].m_numDrivers;
|
||||
}
|
||||
8
GpCommon/IGpDirectoryCursor.h
Normal file
8
GpCommon/IGpDirectoryCursor.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
struct IGpDirectoryCursor
|
||||
{
|
||||
public:
|
||||
virtual bool GetNext(const char *&outFileName) = 0;
|
||||
virtual void Destroy() = 0;
|
||||
};
|
||||
43
GpCommon/IGpFileSystem.h
Normal file
43
GpCommon/IGpFileSystem.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "GpFileCreationDisposition.h"
|
||||
#include "VirtualDirectory.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class GpIOStream;
|
||||
struct IGpThreadRelay;
|
||||
struct IGpDirectoryCursor;
|
||||
|
||||
struct IGpFileSystem
|
||||
{
|
||||
public:
|
||||
typedef void(*DelayCallback_t)(uint32_t ticks);
|
||||
|
||||
virtual bool FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path) = 0;
|
||||
virtual bool FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool *exists) = 0;
|
||||
virtual GpIOStream *OpenFileNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* subPaths, size_t numSubPaths, bool writeAccess, GpFileCreationDisposition_t createDisposition) = 0;
|
||||
virtual bool DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed) = 0;
|
||||
virtual IGpDirectoryCursor *ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths) = 0;
|
||||
|
||||
virtual bool ValidateFilePath(const char *path, size_t pathLen) const = 0;
|
||||
virtual bool ValidateFilePathUnicodeChar(uint32_t ch) const = 0;
|
||||
|
||||
virtual bool IsVirtualDirectoryLooseResources(PortabilityLayer::VirtualDirectory_t virtualDir) const = 0;
|
||||
virtual void SetMainThreadRelay(IGpThreadRelay *relay) = 0;
|
||||
virtual void SetDelayCallback(DelayCallback_t delayCallback) = 0;
|
||||
|
||||
// Helpers
|
||||
GpIOStream *OpenFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool writeAccess, GpFileCreationDisposition_t createDisposition);
|
||||
IGpDirectoryCursor *ScanDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory);
|
||||
};
|
||||
|
||||
inline GpIOStream *IGpFileSystem::OpenFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool writeAccess, GpFileCreationDisposition_t createDisposition)
|
||||
{
|
||||
return this->OpenFileNested(virtualDirectory, &path, 1, writeAccess, createDisposition);
|
||||
}
|
||||
|
||||
inline IGpDirectoryCursor *IGpFileSystem::ScanDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory)
|
||||
{
|
||||
return this->ScanDirectoryNested(virtualDirectory, nullptr, 0);
|
||||
}
|
||||
10
GpCommon/IGpMutex.h
Normal file
10
GpCommon/IGpMutex.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
struct IGpMutex
|
||||
{
|
||||
public:
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
virtual void Lock() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
};
|
||||
35
GpCommon/IGpSystemServices.h
Normal file
35
GpCommon/IGpSystemServices.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef CreateMutex
|
||||
#error "CreateMutex was macrod"
|
||||
#endif
|
||||
|
||||
#ifdef CreateThread
|
||||
#error "CreateThread was macrod"
|
||||
#endif
|
||||
|
||||
struct IGpMutex;
|
||||
struct IGpThreadEvent;
|
||||
|
||||
struct IGpSystemServices
|
||||
{
|
||||
public:
|
||||
typedef int(*ThreadFunc_t)(void *context);
|
||||
|
||||
virtual int64_t GetTime() const = 0;
|
||||
virtual void GetLocalDateTime(unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second) const = 0;
|
||||
virtual IGpMutex *CreateMutex() = 0;
|
||||
virtual IGpMutex *CreateRecursiveMutex() = 0;
|
||||
virtual void *CreateThread(ThreadFunc_t threadFunc, void *context) = 0;
|
||||
virtual IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0;
|
||||
virtual uint64_t GetFreeMemoryCosmetic() const = 0; // Returns free memory in bytes, does not have to be accurate
|
||||
virtual void Beep() const = 0;
|
||||
virtual bool IsTouchscreen() const = 0;
|
||||
virtual bool IsUsingMouseAsTouch() const = 0;
|
||||
virtual bool IsTextInputObstructive() const = 0;
|
||||
virtual unsigned int GetCPUCount() const = 0;
|
||||
virtual void SetTextInputEnabled(bool isEnabled) = 0;
|
||||
virtual bool IsTextInputEnabled() const = 0;
|
||||
};
|
||||
12
GpCommon/IGpThreadEvent.h
Normal file
12
GpCommon/IGpThreadEvent.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct IGpThreadEvent
|
||||
{
|
||||
public:
|
||||
virtual void Wait() = 0;
|
||||
virtual bool WaitTimed(uint32_t msec) = 0;
|
||||
virtual void Signal() = 0;
|
||||
virtual void Destroy() = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user