Make the getter functions of job information classes const 85/138085/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 11 Jul 2017 04:54:28 +0000 (13:54 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 11 Jul 2017 04:54:28 +0000 (13:54 +0900)
Change-Id: I3edc085cce5ddc447c9d81af1d24522aa2fdd263
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/shared/Attribute.cpp
src/shared/Attribute.h
src/shared/JobAction.cpp
src/shared/JobAction.h
src/shared/JobContext.cpp
src/shared/JobContext.h
src/shared/JobInfo.cpp
src/shared/JobInfo.h

index 64fd600..d5e1543 100644 (file)
@@ -36,7 +36,7 @@ Attribute::~Attribute()
 {
 }
 
-const std::string& Attribute::getName()
+const std::string& Attribute::getName() const
 {
        return __name;
 }
@@ -87,7 +87,7 @@ IntegerAttribute::~IntegerAttribute()
 {
 }
 
-Attribute::Type IntegerAttribute::getType()
+Attribute::Type IntegerAttribute::getType() const
 {
        return Attribute::Type::INTEGER;
 }
@@ -128,7 +128,7 @@ IntegerAttribute& IntegerAttribute::addNonTarget(int nonTarget)
        return *this;
 }
 
-void IntegerAttribute::toJson(Json::Value& jsonNode)
+void IntegerAttribute::toJson(Json::Value& jsonNode) const
 {
        jsonNode[KEY_DATA_TYPE] = static_cast<int>(Type::INTEGER);
 
@@ -169,7 +169,7 @@ StringAttribute::~StringAttribute()
 {
 }
 
-Attribute::Type StringAttribute::getType()
+Attribute::Type StringAttribute::getType() const
 {
        return Attribute::Type::STRING;
 }
@@ -186,7 +186,7 @@ StringAttribute& StringAttribute::addNonTarget(const std::string& nonTarget)
        return *this;
 }
 
-void StringAttribute::toJson(Json::Value& jsonNode)
+void StringAttribute::toJson(Json::Value& jsonNode) const
 {
        jsonNode[KEY_DATA_TYPE] = static_cast<int>(Type::STRING);
 
index 413a0a1..4647dae 100644 (file)
@@ -30,15 +30,16 @@ namespace ctx {
        public:
                enum class Type {
                        INTEGER = 1,
+                       //DOUBLE = 2,
                        STRING = 3
                };
 
                virtual ~Attribute();
 
-               virtual Attribute::Type getType() = 0;
-               virtual void toJson(Json::Value& jsonNode) = 0;
+               virtual Attribute::Type getType() const = 0;
+               virtual void toJson(Json::Value& jsonNode) const = 0;
 
-               const std::string& getName();
+               const std::string& getName() const;
 
                static Attribute* build(const std::string& name, Json::Value& jsonNode);
 
@@ -54,10 +55,9 @@ namespace ctx {
        public:
                IntegerAttribute(const std::string& name);
                IntegerAttribute(const std::string& name, Json::Value& jsonNode);
-
                ~IntegerAttribute();
 
-               Attribute::Type getType();
+               Attribute::Type getType() const;
 
                IntegerAttribute& setClosedLowerBound(int bound);
                IntegerAttribute& setClosedUpperBound(int bound);
@@ -66,7 +66,7 @@ namespace ctx {
                IntegerAttribute& addTarget(int target);
                IntegerAttribute& addNonTarget(int nonTarget);
 
-               void toJson(Json::Value& jsonNode);
+               void toJson(Json::Value& jsonNode) const;
 
        private:
                int __closedLowerBound;
@@ -82,15 +82,14 @@ namespace ctx {
        public:
                StringAttribute(const std::string& name);
                StringAttribute(const std::string& name, Json::Value& jsonNode);
-
                ~StringAttribute();
 
-               Attribute::Type getType();
+               Attribute::Type getType() const;
 
                StringAttribute& addTarget(const std::string& target);
                StringAttribute& addNonTarget(const std::string& nonTarget);
 
-               void toJson(Json::Value& jsonNode);
+               void toJson(Json::Value& jsonNode) const;
 
        private:
                std::set<std::string> __targets;
index fde1677..47fdd68 100644 (file)
@@ -51,7 +51,7 @@ static std::string __bundleToString(bundle* bndl)
 
 static bundle* __stringToBundle(const std::string& str)
 {
-       return bundle_decode(reinterpret_cast<const unsigned char*>(str.c_str()), str.size());
+       return bundle_decode(reinterpret_cast<const unsigned char*>(str.c_str()), strlen(str.c_str()));
 }
 
 JobAction::JobAction()
@@ -105,27 +105,27 @@ JobDBusCall::~JobDBusCall()
                g_variant_unref(__parameters);
 }
 
-JobAction::Type JobDBusCall::getType()
+JobAction::Type JobDBusCall::getType() const
 {
        return JobAction::Type::DBUS_METHOD;
 }
 
-const std::string& JobDBusCall::getBusName()
+const std::string& JobDBusCall::getBusName() const
 {
        return __busName;
 }
 
-const std::string& JobDBusCall::getObjectPath()
+const std::string& JobDBusCall::getObjectPath() const
 {
        return __objectPath;
 }
 
-const std::string& JobDBusCall::getInterface()
+const std::string& JobDBusCall::getInterface() const
 {
        return __interface;
 }
 
-const std::string& JobDBusCall::getMethodName()
+const std::string& JobDBusCall::getMethodName() const
 {
        return __methodName;
 }
@@ -135,7 +135,7 @@ GVariant* JobDBusCall::getParameters()
        return __parameters;
 }
 
-void JobDBusCall::toJson(Json::Value& jsonNode)
+void JobDBusCall::toJson(Json::Value& jsonNode) const
 {
        Json::Value& node = jsonNode[KEY_DBUS];
 
@@ -167,7 +167,7 @@ JobAppControl::~JobAppControl()
                bundle_free(__appCtrlBundle);
 }
 
-JobAction::Type JobAppControl::getType()
+JobAction::Type JobAppControl::getType() const
 {
        return JobAction::Type::APP_CONTROL;
 }
@@ -177,7 +177,7 @@ bundle* JobAppControl::getAppControl()
        return __appCtrlBundle;
 }
 
-void JobAppControl::toJson(Json::Value& jsonNode)
+void JobAppControl::toJson(Json::Value& jsonNode) const
 {
        jsonNode[KEY_APP_CTRL][KEY_BUNDLE] = __bundleToString(__appCtrlBundle);
 }
@@ -206,22 +206,22 @@ JobNotification::~JobNotification()
                bundle_free(__appCtrlBundle);
 }
 
-JobAction::Type JobNotification::getType()
+JobAction::Type JobNotification::getType() const
 {
        return JobAction::Type::NOTIFICATION;
 }
 
-const std::string& JobNotification::getTitle()
+const std::string& JobNotification::getTitle() const
 {
        return __title;
 }
 
-const std::string& JobNotification::getContent()
+const std::string& JobNotification::getContent() const
 {
        return __content;
 }
 
-const std::string& JobNotification::getIconPath()
+const std::string& JobNotification::getIconPath() const
 {
        return __iconPath;
 }
@@ -231,7 +231,7 @@ bundle* JobNotification::getAppControl()
        return __appCtrlBundle;
 }
 
-void JobNotification::toJson(Json::Value& jsonNode)
+void JobNotification::toJson(Json::Value& jsonNode) const
 {
        Json::Value& node = jsonNode[KEY_NOTI];
 
index 9872cd7..ea68d88 100644 (file)
@@ -36,8 +36,10 @@ namespace ctx {
                };
 
                virtual ~JobAction();
-               virtual Type getType() = 0;
-               virtual void toJson(Json::Value& jsonNode) = 0;
+
+               virtual Type getType() const = 0;
+
+               virtual void toJson(Json::Value& jsonNode) const = 0;
 
                static JobAction* build(Json::Value& jsonNode);
 
@@ -51,18 +53,17 @@ namespace ctx {
                JobDBusCall(const std::string& busName, const std::string& objPath,
                                const std::string& interface, const std::string& methodName, GVariant* param);
                JobDBusCall(Json::Value& jsonNode);
-
                ~JobDBusCall();
 
-               JobAction::Type getType();
+               JobAction::Type getType() const;
 
-               const std::string& getBusName();
-               const std::string& getObjectPath();
-               const std::string& getInterface();
-               const std::string& getMethodName();
+               const std::string& getBusName() const;
+               const std::string& getObjectPath() const;
+               const std::string& getInterface() const;
+               const std::string& getMethodName() const;
                GVariant* getParameters();
 
-               void toJson(Json::Value& jsonNode);
+               void toJson(Json::Value& jsonNode) const;
 
        private:
                std::string __busName;
@@ -77,14 +78,13 @@ namespace ctx {
        public:
                JobAppControl(bundle* appCtrlBundle);
                JobAppControl(Json::Value& jsonNode);
-
                ~JobAppControl();
 
-               JobAction::Type getType();
+               JobAction::Type getType() const;
 
                bundle* getAppControl();
 
-               void toJson(Json::Value& jsonNode);
+               void toJson(Json::Value& jsonNode) const;
 
        private:
                bundle* __appCtrlBundle;
@@ -96,17 +96,16 @@ namespace ctx {
                JobNotification(const std::string& title, const std::string& content,
                                const std::string& iconPath, bundle* appCtrlBundle);
                JobNotification(Json::Value& jsonNode);
-
                ~JobNotification();
 
-               JobAction::Type getType();
+               JobAction::Type getType() const;
 
-               const std::string& getTitle();
-               const std::string& getContent();
-               const std::string& getIconPath();
+               const std::string& getTitle() const;
+               const std::string& getContent() const;
+               const std::string& getIconPath() const;
                bundle* getAppControl();
 
-               void toJson(Json::Value& jsonNode);
+               void toJson(Json::Value& jsonNode) const;
 
        private:
                std::string __title;
index 965855a..5e21ee2 100644 (file)
@@ -50,7 +50,7 @@ JobContext::~JobContext()
        }
 }
 
-const std::string& JobContext::getUri()
+const std::string& JobContext::getUri() const
 {
        return __uri;
 }
@@ -86,13 +86,7 @@ bool JobContext::prepareAttributeStr(const std::string& attrName)
        return true;
 }
 
-JobContext& JobContext::setDisjunction(bool disjunction)
-{
-       __disjunction = disjunction;
-       return *this;
-}
-
-void JobContext::toJson(Json::Value& jsonNode)
+void JobContext::toJson(Json::Value& jsonNode) const
 {
        __toJson(jsonNode);
        Json::Value& attrNode = jsonNode[KEY_ATTRIBUTE];
@@ -105,6 +99,17 @@ void JobContext::toJson(Json::Value& jsonNode)
        jsonNode[KEY_DISJUNCTION] = __disjunction;
 }
 
+bool JobContext::isDisjunction() const
+{
+       return __disjunction;
+}
+
+JobContext& JobContext::setDisjunction(bool disjunction)
+{
+       __disjunction = disjunction;
+       return *this;
+}
+
 
 JobTrigger::JobTrigger(const std::string& uri) :
        JobContext(uri)
@@ -120,12 +125,12 @@ JobTrigger::~JobTrigger()
 {
 }
 
-JobContext::Type JobTrigger::getType()
+JobContext::Type JobTrigger::getType() const
 {
        return JobContext::Type::TRIGGER;
 }
 
-void JobTrigger::__toJson(Json::Value& jsonNode)
+void JobTrigger::__toJson(Json::Value& jsonNode) const
 {
 }
 
@@ -146,17 +151,17 @@ JobRequirement::~JobRequirement()
 {
 }
 
-JobContext::Type JobRequirement::getType()
+JobContext::Type JobRequirement::getType() const
 {
        return JobContext::Type::REQUIREMENT;
 }
 
-bool JobRequirement::isOptional()
+bool JobRequirement::isOptional() const
 {
        return __optional;
 }
 
-void JobRequirement::__toJson(Json::Value& jsonNode)
+void JobRequirement::__toJson(Json::Value& jsonNode) const
 {
        jsonNode[KEY_OPTIONAL] = __optional;
 }
index df66821..ed88645 100644 (file)
@@ -38,16 +38,18 @@ namespace ctx {
 
                virtual ~JobContext();
 
-               virtual JobContext::Type getType() = 0;
+               virtual JobContext::Type getType() const = 0;
 
-               const std::string& getUri();
+               const std::string& getUri() const;
                Attribute* getAttribute(const std::string& attrName);
+
                bool prepareAttributeInt(const std::string& attrName);
                bool prepareAttributeStr(const std::string& attrName);
 
-               void toJson(Json::Value& jsonNode);
+               void toJson(Json::Value& jsonNode) const;
 
                /* Legacy support */
+               bool isDisjunction() const;
                JobContext& setDisjunction(bool disjunction);
 
        protected:
@@ -55,7 +57,7 @@ namespace ctx {
                JobContext(const std::string& uri, Json::Value& jsonNode);
 
        private:
-               virtual void __toJson(Json::Value& jsonNode) = 0;
+               virtual void __toJson(Json::Value& jsonNode) const = 0;
 
                std::string __uri;
                std::list<Attribute*> __attributes;
@@ -68,13 +70,12 @@ namespace ctx {
        public:
                JobTrigger(const std::string& uri);
                JobTrigger(const std::string& uri, Json::Value& jsonNode);
-
                ~JobTrigger();
 
-               JobContext::Type getType();
+               JobContext::Type getType() const;
 
        private:
-               void __toJson(Json::Value& jsonNode);
+               void __toJson(Json::Value& jsonNode) const;
        };
 
 
@@ -82,15 +83,14 @@ namespace ctx {
        public:
                JobRequirement(const std::string& uri, bool optional);
                JobRequirement(const std::string& uri, Json::Value& jsonNode);
-
                ~JobRequirement();
 
-               JobContext::Type getType();
+               JobContext::Type getType() const;
 
-               bool isOptional();
+               bool isOptional() const;
 
        private:
-               void __toJson(Json::Value& jsonNode);
+               void __toJson(Json::Value& jsonNode) const;
 
                bool __optional;
        };
index 14bdfb9..e58ad2a 100644 (file)
 using namespace ctx;
 
 JobInfo::JobInfo() :
+       __jobId(-1),
+       __started(false),
        __oneTime(false),
        __persistent(false),
        __requirementTimeout(0),
        __action(NULL),
-       __jobId(-1),
-       __started(false),
        __disjunction(false)
 {
 }
@@ -82,43 +82,67 @@ JobInfo::~JobInfo()
        delete __action;
 }
 
-bool JobInfo::operator==(const JobInfo& rhs)
+int JobInfo::getId() const
 {
-       //TODO: compare two JobInfo, but ignore jobId & started flag
-       return false;
+       return __jobId;
 }
 
-const std::string& JobInfo::getUserData()
+bool JobInfo::isStarted() const
 {
-       return __userData;
+       return __started;
 }
 
-JobInfo& JobInfo::setOneTime(bool oneTime)
+bool JobInfo::isOneTime() const
 {
-       __oneTime = oneTime;
-       return *this;
+       return __oneTime;
 }
 
-JobInfo& JobInfo::setPersistent(bool persistent)
+bool JobInfo::isPersistent() const
 {
-       __persistent = persistent;
+       return __persistent;
+}
+
+std::list<JobRequirement*>& JobInfo::getRequirements()
+{
+       return __requirements;
+}
+
+unsigned int JobInfo::getRequirementTimeout() const
+{
+       return __requirementTimeout;
+}
+
+JobAction* JobInfo::getAction()
+{
+       return __action;
+}
+
+const std::string& JobInfo::getUserData() const
+{
+       return __userData;
+}
+
+JobInfo& JobInfo::setId(int jobId)
+{
+       __jobId = jobId;
        return *this;
 }
 
-bool JobInfo::isPersistent()
+JobInfo& JobInfo::setStarted(bool started)
 {
-       return __persistent;
+       __started = started;
+       return *this;
 }
 
-JobInfo& JobInfo::setRequirementTimeout(unsigned int timeoutMs)
+JobInfo& JobInfo::setOneTime(bool oneTime)
 {
-       __requirementTimeout = timeoutMs;
+       __oneTime = oneTime;
        return *this;
 }
 
-JobInfo& JobInfo::setUserData(const std::string& userData)
+JobInfo& JobInfo::setPersistent(bool persistent)
 {
-       __userData = userData;
+       __persistent = persistent;
        return *this;
 }
 
@@ -130,9 +154,10 @@ JobInfo& JobInfo::addRequirement(JobRequirement* req)
        return *this;
 }
 
-std::list<JobRequirement*>& JobInfo::getRequirements()
+JobInfo& JobInfo::setRequirementTimeout(unsigned int timeoutMs)
 {
-       return __requirements;
+       __requirementTimeout = timeoutMs;
+       return *this;
 }
 
 JobInfo& JobInfo::setAction(JobAction* action)
@@ -145,12 +170,13 @@ JobInfo& JobInfo::setAction(JobAction* action)
        return *this;
 }
 
-JobAction* JobInfo::getAction()
+JobInfo& JobInfo::setUserData(const std::string& userData)
 {
-       return __action;
+       __userData = userData;
+       return *this;
 }
 
-std::string JobInfo::serialize()
+std::string JobInfo::serialize() const
 {
        Json::Value jsonRoot;
        toJson(jsonRoot);
@@ -161,7 +187,7 @@ std::string JobInfo::serialize()
        return fastWriter.write(jsonRoot);
 }
 
-void JobInfo::toJson(Json::Value& jsonRoot)
+void JobInfo::toJson(Json::Value& jsonRoot) const
 {
        jsonRoot[KEY_JOB_TYPE] = static_cast<int>(getType());
        jsonRoot[KEY_ONE_TIME] = __oneTime;
@@ -185,24 +211,15 @@ void JobInfo::toJson(Json::Value& jsonRoot)
        jsonRoot[KEY_DISJUNCTION] = __disjunction;
 }
 
-void JobInfo::setId(int jobId)
+bool JobInfo::operator==(const JobInfo& rhs) const
 {
-       __jobId = jobId;
-}
-
-int JobInfo::getId()
-{
-       return __jobId;
-}
-
-void JobInfo::setStarted(bool started)
-{
-       __started = started;
+       //TODO: compare two JobInfo, but ignore jobId & started flag
+       return false;
 }
 
-bool JobInfo::isStarted()
+bool JobInfo::isDisjunction() const
 {
-       return __started;
+       return __disjunction;
 }
 
 JobInfo& JobInfo::setDisjunction(bool disjunction)
@@ -257,7 +274,7 @@ JobInfo::Type PeriodicJobInfo::getType() const
        return JobInfo::Type::PERIODIC;
 }
 
-void PeriodicJobInfo::__toJson(Json::Value& jsonRoot)
+void PeriodicJobInfo::__toJson(Json::Value& jsonRoot) const
 {
        jsonRoot[KEY_INTERVAL] = __intervalMin;
        jsonRoot[KEY_ANCHOR] = static_cast<int64_t>(__anchor);
@@ -291,6 +308,11 @@ OnDemandJobInfo::~OnDemandJobInfo()
 {
 }
 
+std::list<JobTrigger*>& OnDemandJobInfo::getTriggers()
+{
+       return __triggers;
+}
+
 OnDemandJobInfo& OnDemandJobInfo::addTrigger(JobTrigger* trigger)
 {
        if (trigger)
@@ -299,12 +321,7 @@ OnDemandJobInfo& OnDemandJobInfo::addTrigger(JobTrigger* trigger)
        return *this;
 }
 
-std::list<JobTrigger*>& OnDemandJobInfo::getTriggers()
-{
-       return __triggers;
-}
-
-void OnDemandJobInfo::__toJson(Json::Value& jsonRoot)
+void OnDemandJobInfo::__toJson(Json::Value& jsonRoot) const
 {
        for (auto& trig : __triggers) {
                trig->toJson(jsonRoot[KEY_TRIGGER][trig->getUri()]);
index 6e8480c..3663c30 100644 (file)
@@ -43,34 +43,40 @@ namespace ctx {
 
                virtual JobInfo::Type getType() const = 0;
 
-               bool operator==(const JobInfo& rhs);
+               int getId() const;
 
-               const std::string& getUserData();
+               bool isStarted() const;
+               bool isOneTime() const;
+               bool isPersistent() const;
 
+               std::list<JobRequirement*>& getRequirements();
+               unsigned int getRequirementTimeout() const;
+
+               JobAction* getAction();
+
+               const std::string& getUserData() const;
+
+               JobInfo& setId(int jobId);
+
+               JobInfo& setStarted(bool started);
                JobInfo& setOneTime(bool oneTime);
                JobInfo& setPersistent(bool persistent);
-               bool isPersistent();
-               JobInfo& setRequirementTimeout(unsigned int timeoutMs);
-
-               // UserData should be a string that can be a string element of Json
-               JobInfo& setUserData(const std::string& userData);
 
                JobInfo& addRequirement(JobRequirement* req);
-               std::list<JobRequirement*>& getRequirements();
+               JobInfo& setRequirementTimeout(unsigned int timeoutMs);
 
                JobInfo& setAction(JobAction* action);
-               JobAction* getAction();
 
-               std::string serialize();
-               void toJson(Json::Value& jsonRoot);
+               // UserData should be a string that can be a string element of Json
+               JobInfo& setUserData(const std::string& userData);
 
-               void setId(int jobId);
-               int getId();
+               std::string serialize() const;;
+               void toJson(Json::Value& jsonRoot) const;
 
-               void setStarted(bool started);
-               bool isStarted();
+               bool operator==(const JobInfo& rhs) const;
 
                /* Legacy support */
+               bool isDisjunction() const;
                JobInfo& setDisjunction(bool disjunction);
 
                static JobInfo* deserialize(const std::string& serializedStr);
@@ -80,17 +86,16 @@ namespace ctx {
                JobInfo(Json::Value& jsonRoot, const std::string& serializedStr);
 
        private:
-               virtual void __toJson(Json::Value& jsonRoot) = 0;
+               virtual void __toJson(Json::Value& jsonRoot) const = 0;
 
+               int __jobId;
+               bool __started;
                bool __oneTime;
                bool __persistent;
-               unsigned int __requirementTimeout;
-               std::string __userData;
                std::list<JobRequirement*> __requirements;
+               unsigned int __requirementTimeout;
                JobAction* __action;
-
-               int __jobId;
-               bool __started;
+               std::string __userData;
 
                /* Legacy support */
                bool __disjunction;
@@ -101,13 +106,12 @@ namespace ctx {
        public:
                PeriodicJobInfo(unsigned int intervalMin, time_t anchor);
                PeriodicJobInfo(Json::Value& jsonRoot, const std::string& serializedStr);
-
                ~PeriodicJobInfo();
 
                JobInfo::Type getType() const;
 
        private:
-               void __toJson(Json::Value& jsonRoot);
+               void __toJson(Json::Value& jsonRoot) const;
 
                unsigned int __intervalMin;
                time_t __anchor;
@@ -118,16 +122,16 @@ namespace ctx {
        public:
                OnDemandJobInfo();
                OnDemandJobInfo(Json::Value& jsonRoot, const std::string& serializedStr);
-
                ~OnDemandJobInfo();
 
                JobInfo::Type getType() const;
 
-               OnDemandJobInfo& addTrigger(JobTrigger* trigger);
                std::list<JobTrigger*>& getTriggers();
 
+               OnDemandJobInfo& addTrigger(JobTrigger* trigger);
+
        private:
-               void __toJson(Json::Value& jsonRoot);
+               void __toJson(Json::Value& jsonRoot) const;
 
                std::list<JobTrigger*> __triggers;
        };