-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
executable file
·160 lines (134 loc) · 4.02 KB
/
main.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
/*
* 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.
*
* VER Descriptions Date Author
* 1.0 Created for display management 2011-06-29 Zheng Yang
* 1.1 Fix some bug 2011-09-13 Zheng Yang
* 1.2 Add USB OTG host and slave mode management. 2011-10-09 Zheng Yang
* 1.3 Separate YPbPr from TV interface. 2011-11-11 Zheng Yang
* 1.4 Initialize screen scale after system reset. 2011-11-24 Zheng Yang
* 1.5 Modified for Android 4.0 platform. 2011-12-15 Zheng Yang
* 1.6 Support scale display screen with x/y direction. 2012-05-24 Zheng Yang
* 1.7 Support load HDCP key and SRM file. 2012-05-30 Zheng Yang
* 1.8 Support Dual screen management. 2012-06-30 Zheng Yang
* 1.9 Support LED light control. 2012-07-03 Zheng Yang
* 2.0 Modified for Android 4.1 platform. 2012-08-03 Zheng Yang
* 2.1 Add HDMI 3D interface. 2012-11-26 Zheng Yang
* 2.2 Audo detect scale sysfs node. 2012-12-18 Zheng Yang
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <dirent.h>
#define LOG_TAG "DisplayD"
#include "cutils/log.h"
#include "Config.h"
#include "CommandListener.h"
#include "NetlinkManager.h"
#include "DisplayManager.h"
#if ENABLE_OTG_MANAGER
#include "OtgManager.h"
#endif
#include "ScreenScaleManager.h"
#include "Hdcp.h"
static void coldboot(const char *path);
static void sigchld_handler(int sig);
int main() {
CommandListener *cl;
NetlinkManager *nm;
DisplayManager *dm;
#if ENABLE_OTG_MANAGER
OtgManager *om;
#endif
ScreenScaleManager *ssm;
ALOGI("Display damen 2.1 starting");
Hdcp_init();
// signal(SIGCHLD, sigchld_handler);
ssm = new ScreenScaleManager();
dm = new(DisplayManager);
if (!(nm = NetlinkManager::Instance(dm))) {
ALOGE("Unable to create NetlinkManager");
exit(1);
};
cl = new CommandListener(dm, ssm);
nm->setBroadcaster((SocketListener *) cl);
if (nm->start()) {
ALOGE("Unable to start NetlinkManager (%s)", strerror(errno));
exit(1);
}
#if ENABLE_OTG_MANAGER
/* Start otg manager */
om = new OtgManager();
#endif
/*
* Now that we're up, we can respond to commands
*/
if (cl->startListener()) {
ALOGE("Unable to start CommandListener (%s)", strerror(errno));
exit(1);
}
// Eventually we'll become the monitoring thread
while(1) {
sleep(1000);
}
ALOGI("Displayd exiting");
exit(0);
}
static void do_coldboot(DIR *d, int lvl)
{
struct dirent *de;
int dfd, fd;
dfd = dirfd(d);
fd = openat(dfd, "uevent", O_WRONLY);
if(fd >= 0) {
write(fd, "add\n", 4);
close(fd);
}
while((de = readdir(d))) {
DIR *d2;
if (de->d_name[0] == '.')
continue;
if (de->d_type != DT_DIR && lvl > 0)
continue;
fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
if(fd < 0)
continue;
d2 = fdopendir(fd);
if(d2 == 0)
close(fd);
else {
do_coldboot(d2, lvl + 1);
closedir(d2);
}
}
}
static void coldboot(const char *path)
{
DIR *d = opendir(path);
if(d) {
do_coldboot(d, 0);
closedir(d);
}
}
static void sigchld_handler(int sig) {
pid_t pid = wait(NULL);
ALOGD("Child process %d exited", pid);
}