Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add some missing #include
[simgrid.git] / include / simgrid / simix.hpp
1 /* Copyright (c) 2007-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_SIMIX_HPP
8 #define SIMGRID_SIMIX_HPP
9
10 #include <cstddef>
11
12 #include <string>
13 #include <utility>
14 #include <memory>
15 #include <functional>
16
17 #include <xbt/function_types.h>
18 #include <simgrid/simix.h>
19
20 namespace simgrid {
21 namespace simix {
22
23 class Context;
24 class ContextFactory;
25
26 class ContextFactory {
27 private:
28   std::string name_;
29 public:
30
31   ContextFactory(std::string name) : name_(std::move(name)) {}
32   virtual ~ContextFactory();
33   virtual Context* create_context(std::function<void()> code,
34     void_pfn_smxprocess_t cleanup, smx_process_t process) = 0;
35   virtual void run_all() = 0;
36   virtual Context* self();
37   std::string const& name() const
38   {
39     return name_;
40   }
41 private:
42   void declare_context(void* T, std::size_t size);
43 protected:
44   template<class T, class... Args>
45   T* new_context(Args&&... args)
46   {
47     T* context = new T(std::forward<Args>(args)...);
48     this->declare_context(context, sizeof(T));
49     return context;
50   }
51 };
52
53 class Context {
54 private:
55   std::function<void()> code_;
56   void_pfn_smxprocess_t cleanup_func_ = nullptr;
57   smx_process_t process_ = nullptr;
58 public:
59   bool iwannadie;
60 public:
61   Context(std::function<void()> code,
62           void_pfn_smxprocess_t cleanup_func,
63           smx_process_t process);
64   void operator()()
65   {
66     code_();
67   }
68   bool has_code() const
69   {
70     return (bool) code_;
71   }
72   smx_process_t process()
73   {
74     return this->process_;
75   }
76   void set_cleanup(void_pfn_smxprocess_t cleanup)
77   {
78     cleanup_func_ = cleanup;
79   }
80
81   // Virtual methods
82   virtual ~Context();
83   virtual void stop();
84   virtual void suspend() = 0;
85 };
86
87 }
88 }
89
90 #endif