2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2010-07-05 10:46:32 +00:00
|
|
|
#include "UDPWrapper.h"
|
2010-10-12 19:42:29 +00:00
|
|
|
|
2010-07-05 10:46:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-02-08 05:50:37 +00:00
|
|
|
const std::string DefaultPort(const int index)
|
2010-07-10 06:48:24 +00:00
|
|
|
{
|
|
|
|
static std::string s;
|
|
|
|
s = "443";
|
|
|
|
s += (char)('2' + index);
|
2014-02-08 05:50:37 +00:00
|
|
|
return s;
|
2010-07-10 06:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
UDPWrapper::UDPWrapper(int indx, const char* const _name) :
|
2010-07-06 01:37:34 +00:00
|
|
|
ControllerEmu::ControlGroup(_name,GROUP_TYPE_UDPWII),
|
|
|
|
inst(NULL), index(indx),
|
|
|
|
updIR(false),updAccel(false),
|
|
|
|
updButt(false),udpEn(false)
|
2010-07-10 06:48:24 +00:00
|
|
|
, port(DefaultPort(indx))
|
2010-07-05 10:46:32 +00:00
|
|
|
{
|
|
|
|
//PanicAlert("UDPWrapper #%d ctor",index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UDPWrapper::LoadConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
|
|
|
|
{
|
|
|
|
ControlGroup::LoadConfig(sec,defdev,base);
|
|
|
|
|
|
|
|
std::string group( base + name ); group += "/";
|
|
|
|
|
2010-07-14 17:33:14 +00:00
|
|
|
int _updAccel,_updIR,_updButt,_udpEn,_updNun,_updNunAccel;
|
2014-02-08 05:50:37 +00:00
|
|
|
sec->Get(group + "Enable",&_udpEn, 0);
|
|
|
|
sec->Get(group + "Port", &port, DefaultPort(index));
|
|
|
|
sec->Get(group + "Update_Accel", &_updAccel, 1);
|
|
|
|
sec->Get(group + "Update_IR", &_updIR, 1);
|
|
|
|
sec->Get(group + "Update_Butt", &_updButt, 1);
|
|
|
|
sec->Get(group + "Update_Nunchuk", &_updNun, 1);
|
|
|
|
sec->Get(group + "Update_NunchukAccel", &_updNunAccel, 0);
|
2010-07-05 10:46:32 +00:00
|
|
|
|
|
|
|
udpEn=(_udpEn>0);
|
|
|
|
updAccel=(_updAccel>0);
|
|
|
|
updIR=(_updIR>0);
|
|
|
|
updButt=(_updButt>0);
|
2010-07-14 17:33:14 +00:00
|
|
|
updNun=(_updNun>0);
|
|
|
|
updNunAccel=(_updNunAccel>0);
|
2010-07-05 10:46:32 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDPWrapper::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
|
|
|
|
{
|
|
|
|
ControlGroup::SaveConfig(sec,defdev,base);
|
|
|
|
std::string group( base + name ); group += "/";
|
2014-02-08 05:50:37 +00:00
|
|
|
sec->Set(group + "Enable", (int)udpEn, 0);
|
|
|
|
sec->Set(group + "Port", port, DefaultPort(index));
|
|
|
|
sec->Set(group + "Update_Accel", (int)updAccel, 1);
|
|
|
|
sec->Set(group + "Update_IR", (int)updIR, 1);
|
|
|
|
sec->Set(group + "Update_Butt", (int)updButt, 1);
|
|
|
|
sec->Set(group + "Update_Nunchuk", (int)updNun, 1);
|
|
|
|
sec->Set(group + "Update_NunchukAccel", (int)updNunAccel, 0);
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDPWrapper::Refresh()
|
|
|
|
{
|
|
|
|
bool udpAEn=(inst!=NULL);
|
|
|
|
if (udpEn&&udpAEn)
|
|
|
|
{
|
|
|
|
if (strcmp(inst->getPort(),port.c_str()))
|
|
|
|
{
|
|
|
|
delete inst;
|
2014-02-08 05:50:37 +00:00
|
|
|
inst = new UDPWiimote(port.c_str(),"Dolphin-Emu",index); //TODO: Changeable display name
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!udpEn)
|
|
|
|
{
|
|
|
|
if (inst)
|
|
|
|
delete inst;
|
2014-02-08 05:50:37 +00:00
|
|
|
inst = NULL;
|
2010-07-05 10:46:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//else
|
2014-02-08 05:50:37 +00:00
|
|
|
inst = new UDPWiimote(port.c_str(),"Dolphin-Emu",index);
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UDPWrapper::~UDPWrapper()
|
|
|
|
{
|
|
|
|
if (inst)
|
|
|
|
delete inst;
|
|
|
|
}
|