1 /*
2 * Copyright (C) 2022 Huawei Device 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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15 #include "daemon_common.h"
16 #include "daemon_updater.h"
17 #include "flashd/flashd.h"
18 #include "updater/updater.h"
19 #include "updater_main.h"
20
21 using namespace Hdc;
22 namespace Flashd {
flashd_main(int argc,char ** argv)23 int flashd_main(int argc, char **argv)
24 {
25 Base::SetLogLevel(LOG_LAST); // debug log print
26 Base::SetLogCache(false);
27 UpdaterInit::GetInstance().InvokeEvent(FLAHSD_PRE_INIT_EVENT);
28
29 std::vector<std::string> args = Updater::ParseParams(argc, argv);
30 bool enableUsb = false;
31 bool enableTcp = false;
32 WRITE_LOG(LOG_DEBUG, "flashd main run %d", argc);
33 const int size = 64;
34 char modeSet[size] = "";
35 WRITE_LOG(LOG_DEBUG, "Background mode, persist.hdc.mode %s", modeSet);
36 for (std::string arg : args) {
37 if (arg.find("-l") != std::string::npos) {
38 int logLevel = atoi(arg.c_str() + strlen("-l"));
39 if (logLevel < 0 || logLevel > LOG_LAST) {
40 logLevel = LOG_LAST;
41 }
42 Base::SetLogLevel(logLevel);
43 } else if (arg.find("-t") != std::string::npos || strncmp(modeSet, "tcp", 3) == 0) { // 3 tcp
44 enableTcp = true;
45 } else if (arg.find("-u") != std::string::npos) {
46 enableUsb = true;
47 }
48 }
49
50 if (!enableTcp && !enableUsb) {
51 Base::PrintMessage("Both TCP and USB are disable, default enable usb");
52 enableUsb = true;
53 }
54 HdcDaemon daemon(false);
55 daemon.InitMod(enableTcp, enableUsb);
56 #ifndef UPDATER_UT
57 daemon.WorkerPendding();
58 #endif
59 return 0;
60 }
61 }
62