]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ned/server/src/app_task.h
Inital import
[l4.git] / l4 / pkg / ned / server / src / app_task.h
1 /*
2  * (c) 2008-2009 Technische Universität Dresden
3  * This file is part of TUD:OS and distributed under the terms of the
4  * GNU General Public License 2.
5  * Please see the COPYING-GPL-2 file for details.
6  */
7 #pragma once
8
9 #include <l4/re/log>
10 #include <l4/re/env>
11 #include <l4/re/rm>
12 #include <l4/sys/scheduler>
13 #include <l4/re/util/object_registry>
14 #include <l4/re/util/cap_alloc>
15
16 #include <l4/cxx/ipc_server>
17 #include "server.h"
18
19 class App_task : public Ned::Server_object
20 {
21 private:
22   long _ref_cnt;
23
24 public:
25   enum State { Initializing, Running, Zombie };
26
27   long remove_ref() { return --_ref_cnt; }
28   void add_ref() { ++_ref_cnt; }
29
30   long ref_cnt() const { return _ref_cnt; }
31
32 private:
33   // hm, missing template typedefs
34   template< typename T >
35   struct Auto_del_cap : public L4Re::Util::Auto_del_cap<T> {};
36
37   // hm, missing template typedefs
38   template< typename T >
39   struct Auto_cap : public L4Re::Util::Auto_cap<T> {};
40
41   Ned::Registry *_r;
42
43   Auto_del_cap<L4::Task>::Cap _task;
44   Auto_del_cap<L4::Thread>::Cap _thread;
45   Auto_del_cap<L4Re::Rm>::Cap _rm;
46
47   State _state;
48   unsigned long _exit_code;
49   l4_cap_idx_t _observer;
50
51 public:
52   State state() const { return _state; }
53   unsigned long exit_code() const { return _exit_code; }
54   l4_cap_idx_t observer() const { return _observer; }
55   void observer(l4_cap_idx_t o) { _observer = o; }
56   void running()
57   {
58     _state = Running;
59     add_ref(); // so we run do not silently kick this task
60   }
61
62
63   App_task(Ned::Registry *r, L4::Cap<L4::Factory> alloc);
64
65   //L4::Cap<L4Re::Mem_alloc> allocator() const { return _ma; }
66
67   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios);
68
69   L4::Cap<L4Re::Rm> rm() { return _rm.get(); }
70   L4::Cap<L4::Task> task_cap() const { return _task.get(); }
71   L4::Cap<L4::Thread> thread_cap() const { return _thread.get(); }
72
73   virtual void terminate();
74
75   virtual ~App_task();
76 };