[atomato] [Engine] Add basic engine API
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [atomato] [Engine] Add basic engine API
- Date: Wed, 17 Feb 2016 11:51:39 +0000 (UTC)
commit f6861c95928edf926bddceaf240fb1981b6b069d
Author: Rodrigo Moya <rodrigo gnome org>
Date: Sat Feb 13 19:59:51 2016 +0100
[Engine] Add basic engine API
src/engine/action.vala | 91 ++++++++++++++++++++++++++++++++++++
src/engine/aggregate-action.vala | 60 +++++++++++++++++++++++
src/engine/conditional-action.vala | 51 ++++++++++++++++++++
src/engine/loop-action.vala | 54 +++++++++++++++++++++
src/main.vala | 2 +-
5 files changed, 257 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/action.vala b/src/engine/action.vala
new file mode 100644
index 0000000..3ff7087
--- /dev/null
+++ b/src/engine/action.vala
@@ -0,0 +1,91 @@
+/* GNOME Automation Engine
+ * Copyright (C) 2006-2016 The GNOME Foundation
+ *
+ * Authors:
+ * Rodrigo Moya (rodrigo gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+namespace Atomato.Engine
+{
+ public delegate ActionResult ActionFunc (ActionArguments args);
+
+ public class ActionArguments : Object
+ {
+ public ActionArguments.from_result (ActionResult result)
+ {
+ }
+ }
+
+ public class ActionResult : Object
+ {
+ private bool _success;
+ private string _error_message;
+
+ public ActionResult.with_success ()
+ {
+ _success = true;
+ _error_message = null;
+ }
+
+ public ActionResult.with_error (string error)
+ {
+ _success = false;
+ _error_message = error;
+ }
+
+ public bool was_successful {
+ get {
+ return _success;
+ }
+ }
+
+ public string error_message {
+ get {
+ return _error_message;
+ }
+ set {
+ _error_message = value;
+ }
+ }
+ }
+
+ public class Action : Object
+ {
+ string _name;
+ ActionFunc _action_func;
+
+ public Action (string name, ActionFunc action_func)
+ {
+ _name = name;
+ _action_func = action_func;
+ }
+
+ public virtual ActionResult run (ActionArguments args)
+ {
+ if (_action_func != null) {
+ return _action_func (args);
+ }
+ }
+
+ public string name {
+ get {
+ return _name;
+ }
+ }
+ }
+}
diff --git a/src/engine/aggregate-action.vala b/src/engine/aggregate-action.vala
new file mode 100644
index 0000000..9fed729
--- /dev/null
+++ b/src/engine/aggregate-action.vala
@@ -0,0 +1,60 @@
+/* GNOME Automation Engine
+ * Copyright (C) 2006-2016 The GNOME Foundation
+ *
+ * Authors:
+ * Rodrigo Moya (rodrigo gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+namespace Atomato.Engine
+{
+ public class AggregateAction : Action
+ {
+ List<Action> _actions = new List<Action> ();
+
+ public AggregateAction ()
+ {
+ base ("AggregateAction");
+ }
+
+ public void add_action (Action action)
+ {
+ _actions.append (action);
+ }
+
+ public override ActionResult run (ActionArguments args)
+ {
+ ActionResult result = null;
+ ActionArguments action_args = args;
+
+ // Execute all actions in order
+ foreach (var action in _actions) {
+ stdout.printf ("Running action %s\n", action.name);
+ result = action.run (action_args);
+ if (result == null || !result.was_successful) {
+ // If one action fails, stop
+ stdout.printf ("Action %s failed\n", action.name);
+ break;
+ }
+
+ action_args = new ActionArguments.from_result (result);
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/src/engine/conditional-action.vala b/src/engine/conditional-action.vala
new file mode 100644
index 0000000..f375591
--- /dev/null
+++ b/src/engine/conditional-action.vala
@@ -0,0 +1,51 @@
+/* GNOME Automation Engine
+ * Copyright (C) 2006-2016 The GNOME Foundation
+ *
+ * Authors:
+ * Rodrigo Moya (rodrigo gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+namespace Atomato.Engine
+{
+ public delegate bool ActionConditionFunc (ActionArguments args);
+
+ public class ConditionalAction : Action
+ {
+ ActionConditionFunc _condition_func;
+ Action _action_to_invoke;
+
+ public ConditionalAction (ActionConditionFunc condition, Action action)
+ {
+ base ("Condition");
+
+ _condition_func = condition;
+ _action_to_invoke = action;
+ }
+
+ public override ActionResult run (ActionArguments args)
+ {
+ if (_condition_func != null) {
+ if (!_condition_func (args)) {
+ return new ActionResult ();
+ }
+ }
+
+ return _action_to_invoke.run (args);
+ }
+ }
+}
diff --git a/src/engine/loop-action.vala b/src/engine/loop-action.vala
new file mode 100644
index 0000000..8c3a5bb
--- /dev/null
+++ b/src/engine/loop-action.vala
@@ -0,0 +1,54 @@
+/* GNOME Automation Engine
+ * Copyright (C) 2006-2016 The GNOME Foundation
+ *
+ * Authors:
+ * Rodrigo Moya (rodrigo gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+namespace Atomato.Engine
+{
+ public class LoopAction : Action
+ {
+ ActionConditionFunc _condition_func;
+ Action _action_to_invoke;
+
+ public LoopAction (ActionConditionFunc condition, Action action)
+ {
+ base ("Loop");
+
+ _condition_func = condition;
+ _action_to_invoke = action;
+ }
+
+ public override ActionResult run (ActionArguments args)
+ {
+ ActionResult result = null;
+
+ if (_condition_func != null) {
+ while (_condition_func (args)) {
+ result = _action_to_invoke.run (args);
+ if (result == null) {
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/src/main.vala b/src/main.vala
index 04b7f0d..787fa10 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -52,7 +52,7 @@ namespace Atomato
protected override int handle_local_options (GLib.VariantDict options)
{
- if (options.contains("version")) {
+ if (options.contains ("version")) {
print ("%s %s\n", Environment.get_application_name (), Config.VERSION);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]