4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <sensor_internal.h>
27 #include "dbus_util.h"
29 std::vector<injector *> injector_manager::injectors;
31 injector::injector(sensor_type_t sensor_type, const char *event_name)
35 injector_manager::register_injector(this);
38 injector_manager::injector_manager()
41 _E("Failed to init dbus");
46 injector_manager::~injector_manager()
51 void injector_manager::register_injector(injector *inject)
53 injectors.push_back(inject);
56 bool injector_manager::run(int argc, char *argv[])
61 if (argc < INJECTOR_ARGC) {
66 /* 1. get sensor type */
67 type = get_sensor_type(argv[2]);
68 RETVM_IF(type == UNKNOWN_SENSOR, false, "Invalid argument : %s\n", argv[2]);
70 /* 2. set up injector */
71 injector *_injector = get_injector(type, argv[3]);
72 RETVM_IF(!_injector, false, "Cannot find matched injector\n");
74 /* 3. set up injector */
75 result = _injector->setup();
76 RETVM_IF(!result, false, "Failed to init injector\n");
79 result = _injector->inject(argc, argv);
80 RETVM_IF(!result, false, "Failed to run injector\n");
82 /* 5. tear down injector */
83 result = _injector->teardown();
84 RETVM_IF(!result, false, "Failed to tear down injector\n");
89 injector *injector_manager::get_injector(sensor_type_t type, const char *name)
93 count = injectors.size();
95 for (int i = 0; i < count; ++i) {
96 if (type == injectors[i]->type() &&
97 (injectors[i]->name() == name))
103 void injector_manager::usage(void)
105 _N("usage: sensorctl inject <sensor_type> [<event_type>] [<options>]\n\n");