tma: Implement example set:sys getter service
This commit is contained in:
43
stratosphere/tma/source/settings/settings_service.cpp
Normal file
43
stratosphere/tma/source/settings/settings_service.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "settings_service.hpp"
|
||||
#include "settings_task.hpp"
|
||||
|
||||
TmaTask *SettingsService::NewTask(TmaPacket *packet) {
|
||||
TmaTask *new_task = nullptr;
|
||||
switch (packet->GetCommand()) {
|
||||
case SettingsServiceCmd_GetSetting:
|
||||
{
|
||||
new_task = new GetSettingTask(this->manager);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
new_task = nullptr;
|
||||
break;
|
||||
}
|
||||
if (new_task != nullptr) {
|
||||
new_task->SetServiceId(this->GetServiceId());
|
||||
new_task->SetTaskId(packet->GetTaskId());
|
||||
new_task->OnStart(packet);
|
||||
new_task->SetNeedsPackets(true);
|
||||
}
|
||||
|
||||
return new_task;
|
||||
}
|
||||
34
stratosphere/tma/source/settings/settings_service.hpp
Normal file
34
stratosphere/tma/source/settings/settings_service.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "../tma_conn_service_ids.hpp"
|
||||
#include "../tma_service.hpp"
|
||||
|
||||
enum SettingsServiceCmd : u32 {
|
||||
SettingsServiceCmd_GetSetting = 0,
|
||||
};
|
||||
|
||||
class SettingsService : public TmaService {
|
||||
public:
|
||||
SettingsService(TmaServiceManager *m) : TmaService(m, "SettingsService") { }
|
||||
virtual ~SettingsService() { }
|
||||
|
||||
virtual TmaTask *NewTask(TmaPacket *packet) override;
|
||||
};
|
||||
46
stratosphere/tma/source/settings/settings_task.cpp
Normal file
46
stratosphere/tma/source/settings/settings_task.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "settings_task.hpp"
|
||||
|
||||
void GetSettingTask::OnStart(TmaPacket *packet) {
|
||||
size_t length;
|
||||
packet->ReadString(this->name, sizeof(this->name), &length);
|
||||
packet->ReadString(this->item_key, sizeof(this->item_key), &length);
|
||||
|
||||
if (R_SUCCEEDED(setsysGetSettingsItemValueSize(this->name, this->item_key, &this->value_size))) {
|
||||
if (this->value_size <= sizeof(this->value)) {
|
||||
if (R_SUCCEEDED(setsysGetSettingsItemValue(this->name, this->item_key, this->value, this->value_size))) {
|
||||
this->succeeded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetSettingTask::OnReceivePacket(TmaPacket *packet) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
void GetSettingTask::OnSendPacket(TmaPacket *packet) {
|
||||
packet->Write<u8>((u8)this->succeeded);
|
||||
packet->Write<u32>((u32)this->value_size);
|
||||
packet->Write(this->value, this->value_size);
|
||||
|
||||
this->Complete();
|
||||
}
|
||||
38
stratosphere/tma/source/settings/settings_task.hpp
Normal file
38
stratosphere/tma/source/settings/settings_task.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "../tma_task.hpp"
|
||||
|
||||
class GetSettingTask : public TmaTask {
|
||||
private:
|
||||
char name[0x40] = {0};
|
||||
char item_key[0x40] = {0};
|
||||
u8 value[0x40] = {0};
|
||||
u64 value_size = 0;
|
||||
bool succeeded = false;
|
||||
|
||||
public:
|
||||
GetSettingTask(TmaServiceManager *m) : TmaTask(m) { }
|
||||
virtual ~GetSettingTask() { }
|
||||
|
||||
virtual void OnStart(TmaPacket *packet) override;
|
||||
virtual void OnReceivePacket(TmaPacket *packet) override;
|
||||
virtual void OnSendPacket(TmaPacket *packet) override;
|
||||
};
|
||||
@@ -65,11 +65,17 @@ void __appInit(void) {
|
||||
fatalSimple(rc);
|
||||
}
|
||||
|
||||
rc = setsysInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalSimple(rc);
|
||||
}
|
||||
|
||||
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
|
||||
}
|
||||
|
||||
void __appExit(void) {
|
||||
/* Cleanup services. */
|
||||
setsysExit();
|
||||
pscExit();
|
||||
smExit();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "tma_target.hpp"
|
||||
|
||||
#include "test/atmosphere_test_service.hpp"
|
||||
#include "settings/settings_service.hpp"
|
||||
|
||||
struct TmaTargetConfig {
|
||||
char configuration_id1[0x80];
|
||||
@@ -208,6 +209,7 @@ void TmaTarget::Initialize() {
|
||||
g_service_manager = new TmaServiceManager();
|
||||
/* TODO: Make this better. */
|
||||
g_service_manager->AddService(new AtmosphereTestService(g_service_manager));
|
||||
g_service_manager->AddService(new SettingsService(g_service_manager));
|
||||
|
||||
RefreshTargetConfig();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user