2 // Author : Chris Koeritz
3 /******************************************************************************
4 * Copyright (c) 1994-$now By Author. This program is free software; you can *
5 * redistribute it and/or modify it under the terms of the GNU General Public *
6 * License as published by the Free Software Foundation; either version 2 of *
7 * the License or (at your option) any later version. This is online at: *
8 * http://www.fsf.org/copyleft/gpl.html *
9 * Please send any updates to: fred@gruntose.com *
10 \*****************************************************************************/
12 #include "time_control.h"
14 #include <application/windoze_helper.h>
15 #include <basis/utf_conversion.h>
18 #if defined(__WIN32__) || defined(__UNIX__)
19 #include <sys/timeb.h>
25 using namespace basis;
26 using namespace structures;
30 void time_control::sleep_ms(basis::un_int msec)
40 bool time_control::set_time(const time_locus &new_time)
44 os_time.wYear = WORD(new_time.year);
45 os_time.wMonth = new_time.month;
46 os_time.wDayOfWeek = new_time.day_of_week;
47 os_time.wDay = new_time.day_of_year;
48 os_time.wHour = new_time.hour;
49 os_time.wMinute = new_time.minute;
50 os_time.wSecond = new_time.second;
51 os_time.wMilliseconds = 0; // currently unused.
53 // get our process token for manipulation.
55 OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
56 | TOKEN_QUERY, &petoken);
59 // identifier so we can adjust our privileges.
61 LookupPrivilegeValue(NULL, to_unicode_temp("SeSystemTimePrivilege"), &our_id);
62 // make up a privilege structure for the adjustment.
63 TOKEN_PRIVILEGES privs;
64 privs.PrivilegeCount = 1;
65 privs.Privileges[0].Luid = our_id;
66 privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
67 // enable system-time privileges.
68 AdjustTokenPrivileges(petoken, false, &privs, sizeof(TOKEN_PRIVILEGES),
71 SetLocalTime(&os_time); // actually set the time.
73 // disable the time adjustment privileges again.
74 AdjustTokenPrivileges(petoken, true, &privs, sizeof(TOKEN_PRIVILEGES),
77 // let all the main windows know that the time got adjusted.
78 //do we need to do this ourselves?
79 ::PostMessage(HWND_BROADCAST, WM_TIMECHANGE, 0, 0);
81 //hmmm: make sure this seems right.
85 #elif defined(__UNIX__)
88 //temp to shut up warnings
89 time_locus ted = new_time;
90 return ted.year ? 0:1;