added Config::reset() to support re-reading the config file, added PPPC::event_*() stubs to handle events and PPPC::update_pins() to write to the pport
git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@56 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
parent
ff99f698b2
commit
2dd4be5a62
13
Config.cc
13
Config.cc
@ -17,12 +17,19 @@ Config::Entry::Entry(const string & name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Config::Config()
|
Config::Config()
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::reset()
|
||||||
{
|
{
|
||||||
port = "LPT1"; /* default to first parallel port */
|
port = "LPT1"; /* default to first parallel port */
|
||||||
|
entries.clear(); /* erase any entries previously configured */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::read(const char * file)
|
void Config::read(const char * file)
|
||||||
{
|
{
|
||||||
|
reset();
|
||||||
ifstream ifs(file);
|
ifstream ifs(file);
|
||||||
if (ifs.is_open())
|
if (ifs.is_open())
|
||||||
{
|
{
|
||||||
@ -68,7 +75,11 @@ void Config::read(const char * file)
|
|||||||
{
|
{
|
||||||
if (parts.first == "pin")
|
if (parts.first == "pin")
|
||||||
{
|
{
|
||||||
entries[entry_num].pin = atoi(parts.second.c_str());
|
int pin = atoi(parts.second.c_str());
|
||||||
|
if (pin >= 0 && pin <= 7)
|
||||||
|
entries[entry_num].pin = pin;
|
||||||
|
else
|
||||||
|
cerr << "Bad pin #: " << parts.second << endl;
|
||||||
}
|
}
|
||||||
else if (parts.first == "on_start")
|
else if (parts.first == "on_start")
|
||||||
{
|
{
|
||||||
|
1
Config.h
1
Config.h
@ -31,6 +31,7 @@ class Config
|
|||||||
void read(const char * file);
|
void read(const char * file);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void reset();
|
||||||
std::pair<std::string, std::string> split(const std::string & line);
|
std::pair<std::string, std::string> split(const std::string & line);
|
||||||
Action parseAction(const std::string & str);
|
Action parseAction(const std::string & str);
|
||||||
};
|
};
|
||||||
|
57
pppc.cc
57
pppc.cc
@ -11,6 +11,11 @@
|
|||||||
#include "pppc.h"
|
#include "pppc.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#define SET_BIT(var,position,value) \
|
||||||
|
(var) = ((var) & (~(1 << (position)))) | ((value) << (position))
|
||||||
|
#define GET_BIT(var,position) \
|
||||||
|
(((var) >> (position)) & 0x1)
|
||||||
|
|
||||||
static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
int WinMain(
|
int WinMain(
|
||||||
@ -91,11 +96,15 @@ void addMenuItem(HMENU hMenu, CHAR * itemstr, WORD id)
|
|||||||
|
|
||||||
PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
||||||
{
|
{
|
||||||
|
m_pins = 0u;
|
||||||
|
|
||||||
if (config_file != NULL)
|
if (config_file != NULL)
|
||||||
{
|
{
|
||||||
m_config.read(config_file);
|
m_config.read(config_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_start();
|
||||||
|
|
||||||
/* Load the application icon */
|
/* Load the application icon */
|
||||||
HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
|
HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
|
||||||
if (icon == 0)
|
if (icon == 0)
|
||||||
@ -151,7 +160,6 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
|||||||
|
|
||||||
/* begin capturing session notifications */
|
/* begin capturing session notifications */
|
||||||
session_notification_enable(m_hWnd);
|
session_notification_enable(m_hWnd);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL PPPC::mainLoop()
|
BOOL PPPC::mainLoop()
|
||||||
@ -179,12 +187,12 @@ BOOL PPPC::mainLoop()
|
|||||||
if (msg.wParam == WTS_SESSION_LOGON
|
if (msg.wParam == WTS_SESSION_LOGON
|
||||||
|| msg.wParam == WTS_SESSION_UNLOCK)
|
|| msg.wParam == WTS_SESSION_UNLOCK)
|
||||||
{
|
{
|
||||||
pport_write(0xFF);
|
event_unlock();
|
||||||
}
|
}
|
||||||
if (msg.wParam == WTS_SESSION_LOGOFF
|
if (msg.wParam == WTS_SESSION_LOGOFF
|
||||||
|| msg.wParam == WTS_SESSION_LOCK)
|
|| msg.wParam == WTS_SESSION_LOCK)
|
||||||
{
|
{
|
||||||
pport_write(0x0);
|
event_lock();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
@ -195,7 +203,6 @@ BOOL PPPC::mainLoop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,9 +211,51 @@ BOOL PPPC::mainLoop()
|
|||||||
|
|
||||||
PPPC::~PPPC()
|
PPPC::~PPPC()
|
||||||
{
|
{
|
||||||
|
event_exit();
|
||||||
|
|
||||||
/* delete the tray icon */
|
/* delete the tray icon */
|
||||||
Shell_NotifyIcon(NIM_DELETE, &m_nid);
|
Shell_NotifyIcon(NIM_DELETE, &m_nid);
|
||||||
|
|
||||||
/* stop listening for session notifications */
|
/* stop listening for session notifications */
|
||||||
session_notification_disable(m_hWnd);
|
session_notification_disable(m_hWnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PPPC::event_start()
|
||||||
|
{
|
||||||
|
for (int sz = m_config.entries.size(), i = 0; i < sz; i++)
|
||||||
|
{
|
||||||
|
switch (m_config.entries[i].on_start)
|
||||||
|
{
|
||||||
|
case Config::ON:
|
||||||
|
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||||
|
break;
|
||||||
|
case Config::OFF:
|
||||||
|
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update_pins();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPPC::event_exit()
|
||||||
|
{
|
||||||
|
update_pins();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPPC::event_lock()
|
||||||
|
{
|
||||||
|
update_pins();
|
||||||
|
m_previous_pins = m_pins;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPPC::event_unlock()
|
||||||
|
{
|
||||||
|
update_pins();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPPC::update_pins()
|
||||||
|
{
|
||||||
|
pport_write(m_pins);
|
||||||
|
}
|
||||||
|
8
pppc.h
8
pppc.h
@ -15,9 +15,17 @@ class PPPC
|
|||||||
BOOL mainLoop();
|
BOOL mainLoop();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void event_start();
|
||||||
|
void event_exit();
|
||||||
|
void event_lock();
|
||||||
|
void event_unlock();
|
||||||
|
void update_pins();
|
||||||
|
|
||||||
Config m_config;
|
Config m_config;
|
||||||
HWND m_hWnd;
|
HWND m_hWnd;
|
||||||
NOTIFYICONDATA m_nid;
|
NOTIFYICONDATA m_nid;
|
||||||
|
unsigned char m_pins;
|
||||||
|
unsigned char m_previous_pins;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* non class-member functions */
|
/* non class-member functions */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user