2 * psychlops_app_state_OSX.h
3 * Psychlops Standard Library (Universal)
5 * Last Modified 2007/06/22 by Kenchi HOSOKAWA
6 * (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
9 #include <ApplicationServices/ApplicationServices.h>
10 #include <CoreServices/CoreServices.h>
11 #include <mach/mach.h>
12 #include <mach/mach_time.h>
13 #include <mach/mach_init.h>
14 #include <mach/thread_policy.h>
16 #include "psychlops_app_state_OSX.h"
17 #include "../../core/ApplicationInterfaces/psychlops_app_info.h"
21 int AppState::createSynchronousProcess(std::string command)
26 APIApplicationProperties APIApplicationProperties::startupinfo;
28 APIApplicationProperties::APIApplicationProperties() {
29 thread_state_[AppState::SLEEP] = kStoppedThreadState;
30 thread_state_[AppState::IDLE] = kReadyThreadState;
31 thread_state_[AppState::LOW] = kRunningThreadState;
32 thread_state_[AppState::NORMAL] = kRunningThreadState;
33 thread_state_[AppState::HIGH] = kRunningThreadState;
34 MPSetTaskWeight(MPCurrentTaskID(),10000);
36 APIApplicationProperties::~APIApplicationProperties() {
39 void APIApplicationProperties::setThreadPriority( int priority ) {
40 SetThreadState(kCurrentThreadID, thread_state_[priority], kNoThreadID);
42 int APIApplicationProperties::getThreadPriority() {
43 ThreadState threadState;
44 GetThreadState(kCurrentThreadID, &threadState);
46 case kStoppedThreadState:
47 return AppState::SLEEP;
48 case kReadyThreadState:
49 return AppState::IDLE;
51 case kRunningThreadState:
52 return AppState::NORMAL;
57 void stringToPascalString255(std::string from, unsigned char to[255]) {
58 int length = (from.length()>254 ? 254 : from.length());
59 to[0] = (unsigned char)length;
60 for(int i=0; i<length; i++) {
65 void AppState::alert(std::string message) {
66 unsigned char str[255];
67 stringToPascalString255(message, str);
68 StandardAlert(kAlertCautionAlert, str, NULL, NULL, NULL);
72 } /* <- namespace Psycholops */