From 82933c469054b10a5ea68f56ba02a164bf5deb2a Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Fri, 17 Jul 2015 12:51:50 +0300 Subject: [PATCH] [IMPROVE] Add checker of supported features in FeatureManager Change-Id: I09a08f002b0e7f1cd5c4d3a2729f3abf00a915bd Signed-off-by: Vyacheslav Cherkashin --- daemon/cpp/features/feature_manager.cpp | 7 +++++++ daemon/cpp/features/feature_manager.h | 4 ++++ daemon/cpp/features/feature_manager_c.cpp | 23 +++++++++++++++++------ daemon/daemon.c | 10 +++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/daemon/cpp/features/feature_manager.cpp b/daemon/cpp/features/feature_manager.cpp index 8003680..809f9a2 100644 --- a/daemon/cpp/features/feature_manager.cpp +++ b/daemon/cpp/features/feature_manager.cpp @@ -213,6 +213,8 @@ static const char defFeatureName[] = "UNKNOWN"; const size_t FeatureRegister::UNKNOWN_FEATURE_NUM = -1; Feature *FeatureRegister::_features[FEATURES_MAX]; const char *FeatureRegister::_names[FEATURES_MAX]; +uint64_t FeatureRegister::_f0 = 0; +uint64_t FeatureRegister::_f1 = 0; FeatureRegister::FeatureRegister(Feature *feature, size_t num, const char *name) { @@ -228,6 +230,11 @@ FeatureRegister::FeatureRegister(Feature *feature, size_t num, const char *name) _features[num] = feature; _names[num] = name; + + if (num < 64) + _f0 |= (uint64_t)1 << num; + else + _f1 |= (uint64_t)1 << (num - 64); } Feature *FeatureRegister::feature(size_t num) diff --git a/daemon/cpp/features/feature_manager.h b/daemon/cpp/features/feature_manager.h index 9206b8d..f08d1f3 100644 --- a/daemon/cpp/features/feature_manager.h +++ b/daemon/cpp/features/feature_manager.h @@ -82,9 +82,13 @@ public: static std::string featureName(size_t num); static std::string featureName(const Feature *feature); static size_t featureNum(const Feature *feature); + static uint64_t f0() { return _f0; } + static uint64_t f1() { return _f1; } static const size_t UNKNOWN_FEATURE_NUM; private: + static uint64_t _f0; + static uint64_t _f1; static Feature *_features[FEATURES_MAX]; static const char *_names[FEATURES_MAX]; }; diff --git a/daemon/cpp/features/feature_manager_c.cpp b/daemon/cpp/features/feature_manager_c.cpp index 2a36ed9..1afb1a6 100644 --- a/daemon/cpp/features/feature_manager_c.cpp +++ b/daemon/cpp/features/feature_manager_c.cpp @@ -92,14 +92,25 @@ extern "C" int fm_stop(void) return 0; } +static uint64_t checkSupportFeatures(uint64_t f, uint64_t fs, size_t offset) +{ + if (f != fs) { + uint64_t diff = f ^ fs; + + for (int i = 0; diff; diff >>= 1, ++i) { + if (diff & 1) + LOGW("feature[%d] is not support\n", i + offset); + } + } + + return f & fs; +} + extern "C" int fm_set(uint64_t f0, uint64_t f1) { - /* fill actual features (f0_support and f1_support) */ - const uint64_t f0_support = f0 & (FL_WEB_STARTUP_PROFILING | - FL_APP_STARTUP - ); - const uint64_t f1_support = f1 & (0); - std::string f(u64toString(f1_support) + u64toString(f0_support)); + const uint64_t fSupport0 = checkSupportFeatures(f0, FeatureRegister::f0(), 0); + const uint64_t fSupport1 = checkSupportFeatures(f1, FeatureRegister::f1(), 64); + const std::string f(u64toString(fSupport1) + u64toString(fSupport0)); if (fm->setFeatures(feature_bs(f)) != FeatureManager::Ok) { LOGE("set features\n"); diff --git a/daemon/daemon.c b/daemon/daemon.c index e06af80..e71f128 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -504,6 +504,14 @@ static void reconfigure_recording(struct conf_t conf) uint64_t to_enable = (new_features ^ old_features) & new_features; uint64_t to_disable = (new_features ^ old_features) & old_features; + /* fill actual features fm suppor */ + uint64_t fm_f0 = conf.use_features0 + & ( + FL_APP_STARTUP | + FL_WEB_STARTUP_PROFILING + ); + uint64_t fm_f1 = conf.use_features1 & 0; + if (IS_OPT_SET_IN(FL_RECORDING, to_disable)) { del_input_events(); prof_session.conf.use_features0 &= ~FL_RECORDING; @@ -514,7 +522,7 @@ static void reconfigure_recording(struct conf_t conf) prof_session.conf.use_features0 |= FL_RECORDING; } - fm_set(conf.use_features0, conf.use_features1); + fm_set(fm_f0, fm_f1); } static void reconfigure_ld_probes(struct conf_t conf, struct msg_t **msg_reply, struct msg_t **msg_reply_additional) -- 2.7.4