1 /*
2  * (c) 2008-2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #pragma once
10 
11 #include <l4/re/log>
12 #include <l4/re/env>
13 #include <l4/re/rm>
14 #include <l4/sys/scheduler>
15 #include <l4/re/util/object_registry>
16 #include <l4/re/util/cap_alloc>
17 
18 #include <l4/sys/cxx/ipc_epiface>
19 #include "server.h"
20 
21 class App_task :
22   public L4::Epiface_t<App_task, L4Re::Parent, Ned::Server_object>
23 {
24 private:
25   long _ref_cnt;
26 
27 public:
28   enum State { Initializing, Running, Zombie };
29 
remove_ref()30   long remove_ref() { return --_ref_cnt; }
add_ref()31   void add_ref() { ++_ref_cnt; }
32 
ref_cnt()33   long ref_cnt() const { return _ref_cnt; }
34 
35 private:
36 
37   template<typename T> using Unique_del_cap = L4Re::Util::Unique_del_cap<T>;
38   template<typename T> using Unique_cap = L4Re::Util::Unique_cap<T>;
39 
40   Ned::Registry *_r;
41 
42   Unique_del_cap<L4::Task> _task;
43   Unique_del_cap<L4::Thread> _thread;
44   Unique_del_cap<L4Re::Rm> _rm;
45 
46   State _state;
47   unsigned long _exit_code;
48   l4_cap_idx_t _observer;
49 
50 public:
state()51   State state() const { return _state; }
exit_code()52   unsigned long exit_code() const { return _exit_code; }
observer()53   l4_cap_idx_t observer() const { return _observer; }
observer(l4_cap_idx_t o)54   void observer(l4_cap_idx_t o) { _observer = o; }
running()55   void running()
56   {
57     _state = Running;
58     add_ref();
59   }
60 
61 
62   App_task(Ned::Registry *r, L4Re::Util::Ref_cap<L4::Factory>::Cap const &alloc);
63 
64   //L4::Cap<L4Re::Mem_alloc> allocator() const { return _ma; }
65 
66   int op_signal(L4Re::Parent::Rights, unsigned long, unsigned long);
67 
rm()68   L4::Cap<L4Re::Rm> rm() { return _rm.get(); }
task_cap()69   L4::Cap<L4::Task> task_cap() const { return _task.get(); }
thread_cap()70   L4::Cap<L4::Thread> thread_cap() const { return _thread.get(); }
71 
72   virtual void terminate();
73 
74   virtual ~App_task();
75 };
76