diff --git a/services/include/sensor_dump.h b/services/include/sensor_dump.h index be667abb70f27ac788bd77d7ebad6ece136a9e0e..98df5086eda72e83a3f907352ce7dabbd6c387b7 100644 --- a/services/include/sensor_dump.h +++ b/services/include/sensor_dump.h @@ -46,6 +46,9 @@ private: int32_t GetDataDimension(int32_t sensorId); std::string GetDataBySensorId(int32_t sensorId, SensorData &sensorData); static std::unordered_map sensorMap_; + void RunSensorDump(int32_t fd, int32_t optionIndex, const std::vector &args, char **argv); + std::vector sensors_; + ClientInfo &clientInfo_ = ClientInfo::GetInstance(); }; } // namespace Sensors } // namespace OHOS diff --git a/services/src/sensor_dump.cpp b/services/src/sensor_dump.cpp index d82eb3de3ae9ab1495743ac5552cb278163ec258..9ef81fd5d44be3c7660860f82fb9fef9e1729d71 100644 --- a/services/src/sensor_dump.cpp +++ b/services/src/sensor_dump.cpp @@ -84,6 +84,52 @@ std::unordered_map SensorDump::sensorMap_ = { { SENSOR_TYPE_ID_HEADPOSTURE, "HEAD POSTURE" }, }; +void SensorDump::RunSensorDump(int32_t fd, int32_t optionIndex, const std::vector &args, char **argv) +{ + struct option dumpOptions[] = { + {"channel", no_argument, 0, 'c'}, +#ifdef BUILD_VARIANT_ENG + {"data", no_argument, 0, 'd'}, +#endif // BUILD_VARIANT_ENG + {"open", no_argument, 0, 'o'}, + {"help", no_argument, 0, 'h'}, + {"list", no_argument, 0, 'l'}, + {NULL, 0, 0, 0} + }; + optind = 1; + int32_t c; + while ((c = getopt_long(args.size(), argv, "cdohl", dumpOptions, &optionIndex)) != -1) { + switch (c) { + case 'c': { + DumpSensorChannel(fd, clientInfo_); + break; + } +#ifdef BUILD_VARIANT_ENG + case 'd': { + DumpSensorData(fd, clientInfo_); + break; + } +#endif // BUILD_VARIANT_ENG + case 'o': { + DumpOpeningSensor(fd, sensors_, clientInfo_); + break; + } + case 'h': { + DumpHelp(fd); + break; + } + case 'l': { + DumpSensorList(fd, sensors_); + break; + } + default: { + dprintf(fd, "Unrecognized option, More info with: \"hidumper -s 3601 -a -h\"\n"); + break; + } + } + } +} + void SensorDump::ParseCommand(int32_t fd, const std::vector &args, const std::vector &sensors, ClientInfo &clientInfo) { @@ -104,16 +150,6 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, return; } int32_t optionIndex = 0; - struct option dumpOptions[] = { - {"channel", no_argument, 0, 'c'}, -#ifdef BUILD_VARIANT_ENG - {"data", no_argument, 0, 'd'}, -#endif // BUILD_VARIANT_ENG - {"open", no_argument, 0, 'o'}, - {"help", no_argument, 0, 'h'}, - {"list", no_argument, 0, 'l'}, - {NULL, 0, 0, 0} - }; char **argv = new (std::nothrow) char *[args.size()]; CHKPV(argv); if (memset_s(argv, args.size() * sizeof(char *), 0, args.size() * sizeof(char *)) != EOK) { @@ -132,38 +168,8 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, goto RELEASE_RES; } } - optind = 1; - int32_t c; - while ((c = getopt_long(args.size(), argv, "cdohl", dumpOptions, &optionIndex)) != -1) { - switch (c) { - case 'c': { - DumpSensorChannel(fd, clientInfo); - break; - } -#ifdef BUILD_VARIANT_ENG - case 'd': { - DumpSensorData(fd, clientInfo); - break; - } -#endif // BUILD_VARIANT_ENG - case 'o': { - DumpOpeningSensor(fd, sensors, clientInfo); - break; - } - case 'h': { - DumpHelp(fd); - break; - } - case 'l': { - DumpSensorList(fd, sensors); - break; - } - default: { - dprintf(fd, "Unrecognized option, More info with: \"hidumper -s 3601 -a -h\"\n"); - break; - } - } - } + sensors_ = sensors; + RunSensorDump(fd, optionIndex, args, argv); RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { if (argv[i] != nullptr) {