now, version will be attached to shared object extension.
[framework/api/power.git] / test / system-power.c
1 /*
2  * 
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4  * PROPRIETARY/CONFIDENTIAL
5  * 
6  * This software is the confidential and proprietary information of SAMSUNG 
7  * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
8  * this software is owned by Samsung and you shall not disclose such 
9  * Confidential Information and shall use it only in accordance with the terms 
10  * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
11  * make no representations or warranties about the suitability of the software, 
12  * either express or implied, including but not limited to the implied 
13  * warranties of merchantability, fitness for a particular purpose, or 
14  * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
15  * licensee arising out of or related to this software.
16  * 
17  */
18
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <stdbool.h>
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <power.h>
26
27 char* sname[] = {
28         "Normal",
29         "Screen Dim",
30         "Screen Off"
31 };
32
33 static void lock(int state)
34 {
35         int err;
36         err = power_lock_state(state, 0);
37         if(err == POWER_ERROR_NONE){
38                 if(state >= POWER_STATE_NORMAL && state <= POWER_STATE_SCREEN_OFF)
39                         printf("lock state [%s] locked\n", sname[state]);
40                 else
41                         printf("unknown state\n");
42         }else{
43                 printf("power_lock_state fail\n");
44         }
45 }
46
47 static void unlock(int state)
48 {
49         if(power_unlock_state(state) == POWER_ERROR_NONE){
50                 if(state >= POWER_STATE_NORMAL && state <= POWER_STATE_SCREEN_OFF)
51                         printf("lock state [%s] unlocked\n", sname[state]);
52                 else
53                         printf("unknown state\n");
54         }else{
55                 printf("power_unlock_state fail\n");
56         }
57 }
58
59 static void to_use(int state, int sleeptime)
60 {
61     lock(state);
62     sleep(sleeptime);
63     unlock(state);
64 }
65
66 static void pulse(int sleeptime)
67 {
68
69     power_lock_state(POWER_STATE_SCREEN_DIM, 1000);
70     power_lock_state(POWER_STATE_SCREEN_OFF, 10000);
71     power_lock_state(POWER_STATE_SCREEN_DIM, 1000);
72     power_lock_state(POWER_STATE_NORMAL,     1000);
73
74     printf("pulse~~~\n");
75     sleep(sleeptime);
76 }
77
78 int main(int argc, char *argv[])
79 {
80     int m;
81         int state;
82         int sleeptime;
83
84         if(argc < 3){
85                 printf("1 : Normal\n");
86                 printf("2 : Screen Dim\n");
87                 printf("3 : Screen Off\n");
88         printf("4 : pulse test\n");
89                 return 0;
90         }else{
91                 switch(m = atoi(argv[1]))
92                 {
93                         case 1:
94                                 state = POWER_STATE_NORMAL;
95                 printf("normal!!!\n");
96                                 break;
97                         case 2:
98                                 state = POWER_STATE_SCREEN_DIM;
99                 printf("dim!!!\n");
100                                 break;
101                         case 3:
102                                 state = POWER_STATE_SCREEN_OFF;
103                 printf("off!!!\n");
104                                 break;
105             case 4:
106                 break;
107                         default:
108                                 return 0;
109                 }
110         sleeptime = atoi(argv[2]);
111                 if (m < 4){
112             printf("to_use\n");
113             to_use(state, sleeptime);
114         }else{
115             printf("pulse\n");
116             pulse(sleeptime);
117         }
118         }
119         
120         return 0;
121 }