kodi
ILanguageInvoker.h
1 /*
2  * Copyright (C) 2013-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "addons/IAddon.h"
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
19 
20 typedef enum
21 {
22  InvokerStateUninitialized,
23  InvokerStateInitialized,
24  InvokerStateRunning,
25  InvokerStateStopping,
26  InvokerStateScriptDone,
27  InvokerStateExecutionDone,
28  InvokerStateFailed
29 } InvokerState;
30 
32 {
33 public:
34  explicit ILanguageInvoker(ILanguageInvocationHandler *invocationHandler);
35  virtual ~ILanguageInvoker();
36 
37  virtual bool Execute(const std::string &script, const std::vector<std::string> &arguments = std::vector<std::string>());
38  virtual bool Stop(bool abort = false);
39  virtual bool IsStopping() const;
40 
41  void SetId(int id) { m_id = id; }
42  int GetId() const { return m_id; }
43  const ADDON::AddonPtr& GetAddon() const { return m_addon; }
44  void SetAddon(const ADDON::AddonPtr &addon) { m_addon = addon; }
45  InvokerState GetState() const { return m_state; }
46  bool IsActive() const;
47  bool IsRunning() const;
48  void Reset() { m_state = InvokerStateUninitialized; }
49 
50 protected:
51  friend class CLanguageInvokerThread;
52 
56  virtual void AbortNotification();
57 
58  virtual bool execute(const std::string &script, const std::vector<std::string> &arguments) = 0;
59  virtual bool stop(bool abort) = 0;
60 
61  virtual void pulseGlobalEvent();
62  virtual bool onExecutionInitialized();
63  virtual void onExecutionFailed();
64  virtual void onExecutionDone();
65  virtual void onExecutionFinalized();
66 
67  void setState(InvokerState state);
68 
69  ADDON::AddonPtr m_addon;
70 
71 private:
72  int m_id = -1;
73  InvokerState m_state = InvokerStateUninitialized;
74  ILanguageInvocationHandler *m_invocationHandler;
75 };
76 
77 typedef std::shared_ptr<ILanguageInvoker> LanguageInvokerPtr;
Definition: LanguageInvokerThread.h:19
Definition: ILanguageInvocationHandler.h:13
virtual void AbortNotification()
Called to notify the script is aborting.
Definition: ILanguageInvoker.cpp:64
Definition: ILanguageInvoker.h:31