X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ftimely%2Ftime_control.cpp;fp=nucleus%2Flibrary%2Ftimely%2Ftime_control.cpp;h=17e71ddb57c58431cb1ac179371a5bae3200b95f;hb=457b128b77b5b4a0b7dd3094de543de2ce1477ad;hp=0000000000000000000000000000000000000000;hpb=32d7caf45d886d0d24e69eea00511c7815ac15d0;p=feisty_meow.git diff --git a/nucleus/library/timely/time_control.cpp b/nucleus/library/timely/time_control.cpp new file mode 100644 index 00000000..17e71ddb --- /dev/null +++ b/nucleus/library/timely/time_control.cpp @@ -0,0 +1,98 @@ +// Name : time_control +// Author : Chris Koeritz +/****************************************************************************** +* Copyright (c) 1994-$now By Author. This program is free software; you can * +* redistribute it and/or modify it under the terms of the GNU General Public * +* License as published by the Free Software Foundation; either version 2 of * +* the License or (at your option) any later version. This is online at: * +* http://www.fsf.org/copyleft/gpl.html * +* Please send any updates to: fred@gruntose.com * +\*****************************************************************************/ + +#include "time_control.h" + +#include +#include + +#include +#if defined(__WIN32__) || defined(__UNIX__) + #include +#endif +#ifdef __UNIX__ + #include +#endif + +using namespace basis; +using namespace structures; + +namespace timely { + +void time_control::sleep_ms(basis::un_int msec) +{ +#ifdef __UNIX__ + usleep(msec * 1000); +#endif +#ifdef __WIN32__ + Sleep(msec); +#endif +} + +bool time_control::set_time(const time_locus &new_time) +{ +#ifdef __WIN32__ + SYSTEMTIME os_time; + os_time.wYear = WORD(new_time.year); + os_time.wMonth = new_time.month; + os_time.wDayOfWeek = new_time.day_of_week; + os_time.wDay = new_time.day_of_year; + os_time.wHour = new_time.hour; + os_time.wMinute = new_time.minute; + os_time.wSecond = new_time.second; + os_time.wMilliseconds = 0; // currently unused. + + // get our process token for manipulation. + HANDLE petoken; + OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES + | TOKEN_QUERY, &petoken); + // get our +//something or other +// identifier so we can adjust our privileges. + LUID our_id; + LookupPrivilegeValue(NULL, to_unicode_temp("SeSystemTimePrivilege"), &our_id); + // make up a privilege structure for the adjustment. + TOKEN_PRIVILEGES privs; + privs.PrivilegeCount = 1; + privs.Privileges[0].Luid = our_id; + privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + // enable system-time privileges. + AdjustTokenPrivileges(petoken, false, &privs, sizeof(TOKEN_PRIVILEGES), + NULL, NULL); + + SetLocalTime(&os_time); // actually set the time. + + // disable the time adjustment privileges again. + AdjustTokenPrivileges(petoken, true, &privs, sizeof(TOKEN_PRIVILEGES), + NULL, NULL); + + // let all the main windows know that the time got adjusted. +//do we need to do this ourselves? + ::PostMessage(HWND_BROADCAST, WM_TIMECHANGE, 0, 0); + +//hmmm: make sure this seems right. + CloseHandle(petoken); + + return true; +#elif defined(__UNIX__) +//no implem yet. + +//temp to shut up warnings +time_locus ted = new_time; +return ted.year ? 0:1; + +#else + return false; +#endif +} + +} // namespace. +