tbx  0.7.6
taskmanager.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2014 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_TASKMANAGER
26 #define TBX_TASKMANAGER
27 
28 #include <string>
29 #include <vector>
30 
31 #include "handles.h"
32 
33 namespace tbx
34 {
35 
39 struct TaskInfo
40 {
41  std::string name;
43  unsigned int memory;
44  unsigned int flags;
45 
48  enum TaskFlags
49  {
50  None,
51  ModuleTask = 1, // Set for module task, unset application task
52  ResizeSlot = 2 // Set if slot bar can be dragged
53  };
54 };
55 
60 {
64  class Enumerator
65  {
66  int _buffer[128];
67  int _call_value;
68  int *_current;
69  int *_end;
70 
71  public:
72  Enumerator();
73  bool more() {return _current != _end || _call_value >= 0;}
74  bool next();
75 
76  TaskHandle handle() {return _current[0];}
77  std::string name() const;
78  unsigned int memory() {return _current[2];}
79  unsigned int flags() {return _current[3];}
80  };
81 
82  public:
83  bool running(const std::string &task_name) const;
84  std::string name(TaskHandle handle) const;
85  TaskHandle find_first(const std::string &task_name) const;
86  bool find_first(TaskInfo &info, const std::string &task_name) const;
87  bool find_all(std::vector<TaskInfo> &infos, const std::string &task_name) const;
88  void list(std::vector<TaskInfo> &infos) const;
89 };
90 
91 };
92 
93 #endif
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::TaskManager::running
bool running(const std::string &task_name) const
Check if a task is running.
Definition: taskmanager.cc:38
tbx::TaskManager::find_first
TaskHandle find_first(const std::string &task_name) const
Find the first running task with the given name.
Definition: taskmanager.cc:63
tbx::TaskInfo::handle
TaskHandle handle
Handle of the task.
Definition: taskmanager.h:42
tbx::TaskManager::list
void list(std::vector< TaskInfo > &infos) const
Get list of all running tasks.
Definition: taskmanager.cc:122
tbx::TaskInfo::memory
unsigned int memory
Memory used by the task.
Definition: taskmanager.h:43
tbx::TaskInfo::TaskFlags
TaskFlags
Values for the flags parameter can be combined.
Definition: taskmanager.h:49
tbx::TaskManager
Class to find and enumerate running tasks.
Definition: taskmanager.h:60
tbx::TaskManager::name
std::string name(TaskHandle handle) const
Return name of task from a handle.
Definition: taskmanager.cc:50
tbx::TaskHandle
int TaskHandle
Type for a Wimp Task.
Definition: handles.h:56
tbx::TaskInfo::None
@ None
No flags set.
Definition: taskmanager.h:50
tbx::TaskInfo::flags
unsigned int flags
A combination of one or more of the TaskFlags.
Definition: taskmanager.h:44
tbx::TaskManager::find_all
bool find_all(std::vector< TaskInfo > &infos, const std::string &task_name) const
Find all running tasks with given name and return full info.
Definition: taskmanager.cc:99
tbx::TaskInfo::name
std::string name
Name of the task.
Definition: taskmanager.h:41
tbx::TaskInfo
Structure containing information on a task.
Definition: taskmanager.h:40