1 #include <sched.h>
2 #include <sys/resource.h>
3 #include <unistd.h>
4
5 #include <dvr/performance_client_api.h>
6 #include <log/log.h>
7 #include <pdx/service_dispatcher.h>
8 #include <private/dvr/buffer_hub.h>
9
main(int,char **)10 int main(int, char**) {
11 int ret = -1;
12 std::shared_ptr<android::dvr::BufferHubService> pdx_service;
13 std::unique_ptr<android::pdx::ServiceDispatcher> dispatcher;
14
15 // We need to be able to create endpoints with full perms.
16 umask(0000);
17
18 // Bump up the soft limit of open fd to the hard limit.
19 struct rlimit64 rlim;
20 ret = getrlimit64(RLIMIT_NOFILE, &rlim);
21 LOG_ALWAYS_FATAL_IF(ret != 0, "Failed to get nofile limit.");
22
23 ALOGI("Current nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max);
24 rlim.rlim_cur = rlim.rlim_max;
25 ret = setrlimit64(RLIMIT_NOFILE, &rlim);
26 ALOGE_IF(ret < 0, "Failed to set nofile limit, error=%s", strerror(errno));
27
28 rlim.rlim_cur = -1;
29 rlim.rlim_max = -1;
30 if (getrlimit64(RLIMIT_NOFILE, &rlim) < 0)
31 ALOGE("Failed to get nofile limit.");
32 else
33 ALOGI("New nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max);
34
35 dispatcher = android::pdx::ServiceDispatcher::Create();
36 CHECK_ERROR(!dispatcher, error, "Failed to create service dispatcher\n");
37
38 pdx_service = android::dvr::BufferHubService::Create();
39 CHECK_ERROR(!pdx_service, error, "Failed to create bufferhub pdx service\n");
40 dispatcher->AddService(pdx_service);
41
42 ret = dvrSetSchedulerClass(0, "graphics");
43 CHECK_ERROR(ret < 0, error, "Failed to set thread priority");
44
45 ALOGI("Entering message loop.");
46
47 ret = dispatcher->EnterDispatchLoop();
48 CHECK_ERROR(ret < 0, error, "Dispatch loop exited because: %s\n",
49 strerror(-ret));
50
51 error:
52 return -ret;
53 }
54