#pragma once

#ifdef _WIN32
int wmain();
BOOL WINAPI ConsoleHandler(DWORD CEvent);
#else
int main();
void SignalHandler(int s);
#endif
static volatile bool m_keepRunning = true;

struct InertiaListener;


class MainApp {
private:
	std::shared_ptr<InertiaListener> m_listener;

	void ToggleTransmit(std::wstring const& connection);
	void ToggleAccelerometerRange(std::wstring const& connection);
	void SendCommand(std::wstring const& connection);
	std::wstring SetLogging(std::wstring const& connection, inertia::LogWriterSettings const& logWriterSettings);
	void ConvertFile(std::wstring const& filename);

public:
	int Run();
	void Destruct();

	static void SleepMs(unsigned const ms);
};


struct InertiaListener
	: inertia::StreamListener
{
private:
	bool async;
	mutable int openedState;

public:
	InertiaListener(bool const _async);

	void StatusUpdate(std::wstring const& source, const bool isOpen, std::wstring const& feedback) const override;
	void Received(std::wstring const& source, const unsigned addrID, inertia::ConfigVectorPtr const& configs, inertia::CommandVectorPtr const& commands, inertia::SampleVectorPtr const& samples) const override;
	int GetOpenedState() const;
};
