OSDN Git Service

first
[psychlops/cpp.git] / psychlops / platform / osx / psychlops_app_state_OSX.cpp
1 /*
2  *  psychlops_app_state_OSX.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2007/06/22 by Kenchi HOSOKAWA
6  *  (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
7  */
8
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>
15
16 #include "psychlops_app_state_OSX.h"
17 #include "../../core/ApplicationInterfaces/psychlops_app_info.h"
18
19 namespace Psychlops {
20
21         int AppState::createSynchronousProcess(std::string command)
22         {
23                 return 0;
24         }
25
26         APIApplicationProperties APIApplicationProperties::startupinfo;
27
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);
35         }
36         APIApplicationProperties::~APIApplicationProperties() {
37         }
38
39         void APIApplicationProperties::setThreadPriority( int priority ) {
40                 SetThreadState(kCurrentThreadID, thread_state_[priority], kNoThreadID);
41         }
42         int APIApplicationProperties::getThreadPriority() {
43                 ThreadState threadState;
44                 GetThreadState(kCurrentThreadID, &threadState);
45                 switch(threadState) {
46                 case kStoppedThreadState:
47                         return AppState::SLEEP;
48                 case kReadyThreadState:
49                         return AppState::IDLE;
50                 default:
51                 case kRunningThreadState:
52                         return AppState::NORMAL;
53                 }
54         }
55
56         
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++) {
61                         to[i+1] = from[i];
62                 }
63         }
64         
65         void AppState::alert(std::string message) {
66                 unsigned char str[255];
67                 stringToPascalString255(message, str);
68                 StandardAlert(kAlertCautionAlert, str, NULL, NULL, NULL);
69         }
70         
71         
72 }       /*      <- namespace Psycholops         */