1 /* Copyright 2020-2021 IGEL Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include "lease-manager.h"
17 #include "lease-server.h"
25 static void usage(const char *progname)
27 printf("Usage: %s [OPTIONS] [<DRM device>]\n\n"
29 "-h, --help \tPrint this help\n"
30 "-v, --verbose \tEnable verbose debug messages\n",
34 const char *opts = "vh";
35 const struct option options[] = {
36 {"help", no_argument, NULL, 'h'},
37 {"verbose", no_argument, NULL, 'v'},
41 int main(int argc, char **argv)
43 char *device = "/dev/dri/card0";
45 bool debug_log = false;
48 while ((c = getopt_long(argc, argv, opts, options, NULL)) != -1) {
49 int ret = EXIT_FAILURE;
64 device = argv[optind];
66 dlm_log_enable_debug(debug_log);
68 struct lm *lm = lm_create(device);
70 ERROR_LOG("DRM Lease initialization failed\n");
74 struct lease_handle **lease_handles = NULL;
75 int count_ids = lm_get_lease_handles(lm, &lease_handles);
76 assert(count_ids > 0);
78 struct ls *ls = ls_create(lease_handles, count_ids);
81 ERROR_LOG("Client socket initialization failed\n");
86 while (ls_get_request(ls, &req)) {
88 case LS_REQ_GET_LEASE: {
89 int fd = lm_lease_grant(lm, req.lease_handle);
92 "Can't fulfill lease request: lease=%s\n",
93 req.lease_handle->name);
94 ls_disconnect_client(ls, req.client);
98 if (!ls_send_fd(ls, req.client, fd)) {
100 "Client communication error: lease=%s\n",
101 req.lease_handle->name);
102 ls_disconnect_client(ls, req.client);
103 lm_lease_revoke(lm, req.lease_handle);
107 case LS_REQ_RELEASE_LEASE:
108 ls_disconnect_client(ls, req.client);
109 lm_lease_revoke(lm, req.lease_handle);
112 ERROR_LOG("Internal error: Invalid lease request\n");