mirror of
https://github.com/encounter/cpp3ds.git
synced 2026-03-30 11:04:22 -07:00
Add static class to manage services
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#ifndef CPP3DS_SERVICE_H
|
||||
#define CPP3DS_SERVICE_H
|
||||
|
||||
#include <cpp3ds/Config.hpp>
|
||||
#ifndef EMULATION
|
||||
#include <3ds.h>
|
||||
#endif
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
enum ServiceName {
|
||||
NETWORK = 0x0001,
|
||||
AUDIO = 0x0002,
|
||||
|
||||
ALL = 0xFFFF
|
||||
};
|
||||
|
||||
class Service {
|
||||
public:
|
||||
static bool enable(ServiceName service);
|
||||
static bool disable(ServiceName service);
|
||||
|
||||
private:
|
||||
static Uint16 m_enabledServices;
|
||||
#ifndef EMULATION
|
||||
static u32* socBuffer;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace cpp3ds
|
||||
|
||||
|
||||
#endif //CPP3DS_SERVICE_H
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <cpp3ds/Config.hpp>
|
||||
#include <cpp3ds/System/Service.hpp>
|
||||
#include <3ds.h>
|
||||
#include <malloc.h>
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
Uint16 Service::m_enabledServices = 0x0;
|
||||
u32* Service::socBuffer = NULL;
|
||||
|
||||
bool Service::enable(ServiceName service) {
|
||||
if (service & m_enabledServices)
|
||||
return true;
|
||||
|
||||
if (service == ALL)
|
||||
return enable(NETWORK) && enable(AUDIO);
|
||||
|
||||
if (service == NETWORK) {
|
||||
socBuffer = (u32*) memalign(0x1000, 0x100000);
|
||||
if (!socBuffer)
|
||||
return false;
|
||||
Result socResult = SOC_Initialize(socBuffer, 0x100000);
|
||||
if (socResult != 0) {
|
||||
free(socBuffer);
|
||||
socBuffer = NULL;
|
||||
return false;
|
||||
}
|
||||
m_enabledServices |= service;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (service == AUDIO) {
|
||||
return csndInit() == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Service::disable(ServiceName service) {
|
||||
if (service & ~m_enabledServices)
|
||||
return true;
|
||||
|
||||
if (service == ALL)
|
||||
return disable(NETWORK);
|
||||
|
||||
if (service == NETWORK) {
|
||||
SOC_Shutdown();
|
||||
free(socBuffer);
|
||||
socBuffer = NULL;
|
||||
}
|
||||
|
||||
if (service == AUDIO) {
|
||||
// Stop all audio
|
||||
// CSND_SetPlayStateR(1, 0);
|
||||
// CSND_SetPlayStateR(2, 0);
|
||||
csndExecCmds(true);
|
||||
csndExit();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cpp3ds
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <cpp3ds/System/Service.hpp>
|
||||
|
||||
namespace cpp3ds {
|
||||
|
||||
bool Service::enable(ServiceName service) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Service::disable(ServiceName service) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace cpp3ds
|
||||
Reference in New Issue
Block a user