#include "udpl_dll_imp.h"
#include "tap_config.h"

extern std::tstring strDllPath;	// dll のパス

void UdplManagerImp::onTapSwitch(void)
{

	std::tstring fname = strDllPath + TAPDLL_NAME;
	htapdll = LoadLibrary(fname.c_str());
	tapnum = 0;

	if (htapdll) {
		getTapSwitchNum = (_GETTAPSWITCHNUM)GetProcAddress(htapdll, "getTapSwitchNum");
		switchTapSwitch = (_SWITCHTAPSWITCH)GetProcAddress(htapdll, "switchTapSwitch");

		tapnum = getTapSwitchNum();
		if (tapnum != 0) {
			switchTapSwitch(0, SW_ON);	// no.0 の tap switch を ON にする
			std::this_thread::sleep_for(std::chrono::seconds(TAP_WAIT));
		}
	}
}

void UdplManagerImp::offTapSwitch(void)
{
	if (htapdll) {
		if (tapnum != 0) {
			switchTapSwitch(0, SW_OFF);
		}
		FreeLibrary(htapdll);
		htapdll = nullptr;
	}
}