--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CustomTemplate.h"
+
+static std::list<CustomTemplate> __instances;
+
+CustomTemplate::CustomTemplate(const std::string& name, const Json::Value& templateJson) :
+ __name(name),
+ __templateJson(templateJson)
+{
+}
+
+const std::string& CustomTemplate::getName() const
+{
+ return __name;
+}
+
+bool CustomTemplate::match(const std::string& fact)
+{
+ //TODO: true if the given fact is valid w.r.t. the template
+ return true;
+}
+
+bool CustomTemplate::add(const std::string& name, const std::string& attrTmpl)
+{
+ IF_FAIL_RETURN(!get(name), false);
+
+ //TODO: validity check of the name (regex)
+
+ Json::Reader reader;
+ Json::Value tmplJson;
+
+ try {
+ reader.parse(attrTmpl, tmplJson);
+ } catch (const Json::Exception& e) {
+ _E("Exception: %s", e.what());
+ return false;
+ }
+
+ //TODO: further validity check of the template
+
+ __instances.emplace_back(name, tmplJson);
+
+ return true;
+}
+
+void CustomTemplate::remove(const std::string& name)
+{
+ __instances.remove_if(
+ [&name](const CustomTemplate& tmpl)->bool {
+ return tmpl.getName() == name;
+ });
+}
+
+CustomTemplate* CustomTemplate::get(const std::string& name)
+{
+ for (auto& tmpl : __instances) {
+ if (tmpl.getName() == name)
+ return &tmpl;
+ }
+
+ return NULL;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_TRIGGER_CUSTOM_TEMPLATE_H__
+#define __CONTEXT_TRIGGER_CUSTOM_TEMPLATE_H__
+
+#include <string>
+#include <list>
+#include <json/json.h>
+#include <ContextTypes.h>
+
+class CustomTemplate {
+public:
+ CustomTemplate(const std::string& name, const Json::Value& templateJson);
+
+ const std::string& getName() const;
+ bool match(const std::string& fact);
+
+ static bool add(const std::string& name, const std::string& attrTmpl);
+ static void remove(const std::string& name);
+ static CustomTemplate* get(const std::string& name);
+
+private:
+ std::string __name;
+ Json::Value __templateJson;
+};
+
+#endif