-
Notifications
You must be signed in to change notification settings - Fork 1
/
CommandListener.cpp
189 lines (176 loc) · 6.74 KB
/
CommandListener.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <dirent.h>
#include <errno.h>
#include <linux/if.h>
#define LOG_TAG "CommandListener"
#include <cutils/log.h>
#include <string.h>
#include <sysutils/SocketClient.h>
#include "Config.h"
#include "CommandListener.h"
#include "ResponseCode.h"
DisplayManager *CommandListener::mDisplayManager = NULL;
ScreenScaleManager *CommandListener::mScreenScaleManager = NULL;
BcshManger *CommandListener::mBcshManger = NULL;
CommandListener::CommandListener(DisplayManager *dm, ScreenScaleManager *ssm) :
FrameworkListener("displayd", true) {
ALOGD(" FrameworkListener displayd start");
registerCmd(new InterfaceCmd());
registerCmd(new ModeCmd());
registerCmd(new UtilsCmd());
mDisplayManager = dm;
mScreenScaleManager = ssm;
mBcshManger = new BcshManger();
}
CommandListener::InterfaceCmd::InterfaceCmd() :
DisplaydCommand("interface") {
}
int CommandListener::InterfaceCmd::runCommand(SocketClient *cli, int argc, char **argv) {
if (argc < 3) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
return 0;
}
if (!strcmp(argv[1], "list")) {
CommandListener::mDisplayManager->getIfaceInfo(cli, atoi(argv[2]));
} else if (!strcmp(argv[1], "getcur")) {
CommandListener::mDisplayManager->getCurIface(cli, atoi(argv[2]));
} else if(!strcmp(argv[1], "set")) {
char enable = 0;
if(!strcmp(argv[4], "true"))
enable = 1;
else if(!strcmp(argv[4], "false"))
enable = 0;
if(!mDisplayManager->enableIface(atoi(argv[2]), argv[3], enable))
cli->sendMsg(ResponseCode::CommandOkay, "Interface set completed", false);
else
cli->sendMsg(ResponseCode::OperationFailed, "Interface set failed", false);
} else if(!strcmp(argv[1], "switch")) {
CommandListener::mDisplayManager->selectNextIface(atoi(argv[2]));
cli->sendMsg(ResponseCode::CommandOkay, "Switch interface completed", false);
} else
cli->sendMsg(ResponseCode::CommandSyntaxError, "Unkown command", false);
return 0;
}
CommandListener::ModeCmd::ModeCmd() :
DisplaydCommand("mode") {
}
int CommandListener::ModeCmd::runCommand(SocketClient *cli, int argc, char **argv) {
if (argc < 4) {
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
return 0;
}
ALOGD(":ModeCmd::runCommand argv[1] = %s",argv[1]);
if(!strcmp(argv[1], "list")) {
mDisplayManager->getModeList(cli, atoi(argv[2]), argv[3]);
} else if(!strcmp(argv[1], "get")) {
mDisplayManager->getCurMode(cli, atoi(argv[2]), argv[3]);
} else if(!strcmp(argv[1], "set")) {
mDisplayManager->setMode(atoi(argv[2]), argv[3], argv[4]);
cli->sendMsg(ResponseCode::CommandOkay, "Mode set completed", false);
} else if(!strcmp(argv[1], "get3dmodes")) {
mDisplayManager->get3DModes(cli, atoi(argv[2]), argv[3]);
} else if(!strcmp(argv[1], "get3dmode")) {
mDisplayManager->get3DMode(cli, atoi(argv[2]), argv[3]);
} else if(!strcmp(argv[1], "set3dmode")) {
if(mDisplayManager->set3DMode(atoi(argv[2]), argv[3], argv[4]) == 0)
cli->sendMsg(ResponseCode::CommandOkay, "Set 3D Mode completed", false);
else
cli->sendMsg(ResponseCode::OperationFailed, "Set 3D Mode failed", false);
} else
cli->sendMsg(ResponseCode::CommandSyntaxError, "Unkown command", false);
return 0;
}
CommandListener::UtilsCmd::UtilsCmd() :
DisplaydCommand("utils") {
}
int CommandListener::UtilsCmd::runCommand(SocketClient *cli, int argc, char **argv) {
//ALOGD("runCommand argv[1] = %s argv[2] = %s",argv[1],argv[2]);
if (argc < 2) {
ALOGD("argc = %d",argc);
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
return 0;
}
if (!strcmp(argv[1], "switch")) {
#if ENABLE_SWITCH_FRAMEBUFFER
cli->sendMsg(ResponseCode::CommandOkay, "true", false);
#else
cli->sendMsg(ResponseCode::CommandOkay, "false", false);
#endif
} else if (!strcmp(argv[1], "scaleset")) {
if(argc != 5)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
int direction = atoi(argv[3]);
int value = atoi(argv[4]);
if(direction <= DISPLAY_OVERSCAN_ALL)
mScreenScaleManager->SSMCtrl(atoi(argv[2]), direction, value);
else
cli->sendMsg(ResponseCode::CommandParameterError, "Unkown direction", false);
cli->sendMsg(ResponseCode::CommandOkay, "Screen scale set ok", false);
}
} else if (!strcmp(argv[1], "switchfb")) {
if(argc != 5)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
mDisplayManager->switchFramebuffer(atoi(argv[2]),atoi(argv[3]), atoi(argv[4]));
cli->sendMsg(ResponseCode::CommandOkay, "switch fb ok", false);
}
} else if (!strcmp(argv[1], "brightness")){
if(argc != 4)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
mBcshManger->setBrightness(atoi(argv[2]), atoi(argv[3]));
cli->sendMsg(ResponseCode::CommandOkay, "set brightness ok", false);
}
} else if (!strcmp(argv[1], "contrast")){
if(argc != 4)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
mBcshManger->setContrast(atoi(argv[2]), atof(argv[3]));
cli->sendMsg(ResponseCode::CommandOkay, "set contrast ok", false);
}
} else if (!strcmp(argv[1], "saturation")){
if(argc != 4)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
mBcshManger->setSaturation(atoi(argv[2]), atof(argv[3]));
cli->sendMsg(ResponseCode::CommandOkay, "set sta_con ok", false);
}
} else if (!strcmp(argv[1], "hue")){
if(argc != 4)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
mBcshManger->setHue(atoi(argv[2]), atof(argv[3]));
cli->sendMsg(ResponseCode::CommandOkay, "set hue ok", false);
}
} else if (!strcmp(argv[1], "save")){
if(argc != 2)
cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing argument", false);
else {
CommandListener::mDisplayManager->saveConfig();
cli->sendMsg(ResponseCode::CommandOkay, "set save ok", false);
}
}
else
cli->sendMsg(ResponseCode::CommandSyntaxError, "Unkown command", false);
return 0;
}