1 /*
2 *
3 * Copyright (C) 2023 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <android-base/logging.h>
20 #include <android-base/strings.h>
21 #include <sys/eventfd.h>
22 #include <sys/msg.h>
23 #include <wmediumd/wmediumd.h>
24 #include <wmediumd_server/wmediumd_server.h>
25
26 #include <string>
27 #include <thread>
28 #include <vector>
29
30 constexpr char kGrpcUdsPathOption[] = "--grpc_uds_path=";
31
main(int argc,char * argv[])32 int main(int argc, char* argv[]) {
33 std::vector<char*> wmediumd_args;
34 std::string grpc_uds_path;
35 for (int i = 0; i < argc; i++) {
36 if (android::base::StartsWith(argv[i], kGrpcUdsPathOption)) {
37 std::string current_arg(argv[i]);
38 grpc_uds_path = current_arg.substr(strlen(kGrpcUdsPathOption));
39 } else {
40 wmediumd_args.push_back(argv[i]);
41 }
42 }
43
44 int fd = eventfd(0, 0);
45 int msq_id = msgget(IPC_PRIVATE, IPC_CREAT | 0666);
46
47 std::thread wmediumd_server_thread;
48 if (!grpc_uds_path.empty()) {
49 wmediumd_server_thread =
50 std::thread(RunWmediumdServer, grpc_uds_path, fd, msq_id);
51 }
52
53 wmediumd_main(wmediumd_args.size(), wmediumd_args.data(), fd, msq_id);
54
55 if (!grpc_uds_path.empty()) {
56 wmediumd_server_thread.join();
57 }
58
59 msgctl(msq_id, IPC_RMID, 0);
60 close(fd);
61 return 0;
62 }