sensor: add option parameter checking routine 63/78663/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 6 Jul 2016 10:42:48 +0000 (19:42 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 6 Jul 2016 10:42:48 +0000 (19:42 +0900)
Change-Id: I67c79fb520762290631e32688fbfe45be60d3892
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/sensor/SensorProvider.cpp
src/sensor/SensorProvider.h
src/sensor/heartrate/HeartRate.cpp
src/sensor/heartrate/HeartRate.h
src/sensor/heartrate/HeartRateLogger.cpp
src/sensor/heartrate/HeartRateLogger.h

index 1e680ac..47d5269 100644 (file)
@@ -115,6 +115,8 @@ int SensorProvider::write(Json data, Json *requestResult)
                option.remove(NULL, KEY_RETENTION);
        }
 
+       IF_FAIL_RETURN(verifyOption(option), ERR_INVALID_PARAMETER);
+
        if (operation == VAL_START)
                return __addClient(pkgId, retentionPeriod, option);
        else if (operation == VAL_STOP)
@@ -123,6 +125,13 @@ int SensorProvider::write(Json data, Json *requestResult)
        return ERR_NOT_SUPPORTED;
 }
 
+bool SensorProvider::verifyOption(Json option)
+{
+       std::list<std::string> keys;
+       option.getKeys(&keys);
+       return keys.size() == 0;
+}
+
 int SensorProvider::__addClient(std::string pkgId, int retentionPeriod, Json option)
 {
        Json tmp;
index 601b191..5b806a0 100644 (file)
@@ -39,6 +39,7 @@ namespace ctx {
 
        protected:
                virtual Querier* getQuerier(Json option) = 0;
+               virtual bool verifyOption(Json option);
 
                SensorLogger *sensorLogger;
 
index 03fae8a..3afa98e 100644 (file)
@@ -52,3 +52,19 @@ Querier* HeartRateProvider::getQuerier(Json option)
        IF_FAIL_RETURN_TAG(querier, NULL, _E, "Memory allocation failed");
        return querier;
 }
+
+bool HeartRateProvider::verifyOption(Json option)
+{
+       std::list<std::string> keys;
+       option.getKeys(&keys);
+
+       IF_FAIL_RETURN(keys.size() <= 1, false);
+
+       int interval = 0;
+       if (option.get(NULL, KEY_INTERVAL, &interval)) {
+               if (interval < MIN_MEASURING_INTERVAL || interval > MAX_MEASURING_INTERVAL)
+                       return false;
+       }
+
+       return true;
+}
index c9d071b..71f0812 100644 (file)
@@ -31,6 +31,7 @@ namespace ctx {
 
        protected:
                Querier* getQuerier(Json option);
+               bool verifyOption(Json option);
        };
 }
 
index 05adbe1..8ef6895 100644 (file)
@@ -25,7 +25,6 @@
 #define SAMPLING_INTERVAL      200             /* ms */
 #define VALID_HR_LB                    30              /* BPM */
 #define MIN_VALID_COUNT                3
-#define MAX_TIMER_INTERVAL     1440    /* minutes */
 #define MEASURING_LIMIT                10000   /* ms */
 
 using namespace ctx;
@@ -61,7 +60,7 @@ bool HeartRateLogger::start()
 {
        std::vector<Json> options;
        ClientInfo clientInfo;
-       float interval = MAX_TIMER_INTERVAL;
+       float interval = MAX_MEASURING_INTERVAL;
 
        if (clientInfo.get(SUBJ_SENSOR_HEART_RATE, options) != ERR_NONE)
                return false;
index b3a56c1..fa12aa6 100644 (file)
@@ -21,6 +21,9 @@
 #include "../SensorLogger.h"
 #include "../SensorProxy.h"
 
+#define MIN_MEASURING_INTERVAL 10              /* minutes */
+#define MAX_MEASURING_INTERVAL 1440    /* minutes */
+
 namespace ctx {
 
        class HeartRateLogger : public SensorLogger, public SensorProxy, public ITimerListener {