2016-12-12 20:40:35 +00:00
|
|
|
#include "State.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
CommandState::CommandState() : m_command(L"/state")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandState::~CommandState()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandState::CompareCommand(std::wstring& command)
|
|
|
|
{
|
|
|
|
return (command == m_command);
|
|
|
|
}
|
|
|
|
|
2016-12-23 20:31:26 +00:00
|
|
|
void CommandState::LoadArgs(Arguments& args, CommandModeType mode)
|
2016-12-12 20:40:35 +00:00
|
|
|
{
|
|
|
|
wstring state, enable;
|
|
|
|
|
|
|
|
if (!args.GetNext(state))
|
2016-12-26 21:52:27 +00:00
|
|
|
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'state'");
|
2016-12-12 20:40:35 +00:00
|
|
|
|
|
|
|
if (state == L"on")
|
|
|
|
m_state = true;
|
|
|
|
else if (state == L"off")
|
|
|
|
m_state = false;
|
|
|
|
else
|
2016-12-26 21:52:27 +00:00
|
|
|
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'state'");
|
2016-12-12 20:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandState::PerformCommand(Connection& connection)
|
|
|
|
{
|
|
|
|
HidStatus status;
|
|
|
|
|
|
|
|
status = Hid_SetState(connection.GetContext(), (m_state ? HidActiveState::StateEnabled : HidActiveState::StateDisabled));
|
|
|
|
if (!HID_STATUS_SUCCESSFUL(status))
|
|
|
|
throw WException(HID_STATUS_CODE(status), L"Error, command 'state' rejected");
|
|
|
|
|
2016-12-26 21:33:16 +00:00
|
|
|
g_stderr << L"Command 'state' successful" << endl;
|
2016-12-12 20:40:35 +00:00
|
|
|
}
|
2016-12-14 23:29:27 +00:00
|
|
|
|
2016-12-23 00:05:09 +00:00
|
|
|
void CommandState::InstallCommand(RegistryKey& configKey)
|
|
|
|
{
|
|
|
|
configKey.SetDwordValue(L"Hid_State", (m_state ? 1 : 0));
|
2016-12-23 20:31:26 +00:00
|
|
|
|
2016-12-26 21:33:16 +00:00
|
|
|
g_stderr << L"Install 'state' successful" << endl;
|
2016-12-23 00:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandState::UninstallCommand(RegistryKey& configKey)
|
|
|
|
{
|
|
|
|
configKey.RemoveValue(L"Hid_State");
|
2016-12-23 20:31:26 +00:00
|
|
|
|
2016-12-26 21:33:16 +00:00
|
|
|
g_stderr << L"Uninstall 'state' successful" << endl;
|
2016-12-23 00:05:09 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 23:29:27 +00:00
|
|
|
CommandPtr CommandState::CreateInstance()
|
|
|
|
{
|
|
|
|
return CommandPtr(new CommandState());
|
|
|
|
}
|