Add static class to manage services

This commit is contained in:
Cruel
2015-08-17 01:53:41 -04:00
parent cde21d2c0d
commit ca2c5281bf
3 changed files with 107 additions and 0 deletions
+33
View File
@@ -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
+61
View File
@@ -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
+13
View File
@@ -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