GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
user.h
Go to the documentation of this file.
1 #ifndef USER_H_
2 #define USER_H_
3 
4 #include <string>
5 #include <vector>
6 
7 #include "utils.h"
8 #include "interfaces.h"
9 #include "job.h"
10 #include "bytebuffer.h"
11 #include "menu.h"
12 
15 {
18 };
19 
20 static char* UserTypeStr[] = { "Academic", "Enterprise" };
21 
23 
26 class User : public ISave, public IPrint
27 {
28 public:
29  virtual ~User() { };
30 
31  uint GetId() const { return _id; }
32  void SetId(uint val) { _id = val; }
33 
34  void SetName(const std::string& name);
35  const std::string& GetName() const { return _name; }
36 
37  virtual bool Save(ByteBuffer& bb) const override;
38  static User* Load(ByteBuffer& bb);
39 
40  virtual bool CanCreateJob(const Job* job) = 0;
41  virtual void CreatedJob(const Job* job) = 0;
42 
43  virtual void Print(std::ostream& os = std::cout) const override;
44  static void PrintHeader(std::ostream& os = std::cout);
45 
46  static Menu* GetMenu() { return _menu; }
47 
48 protected:
49  User(uint id) : _id(id) { }
50  User(const std::string& name);
51 
52  static Menu* _menu;
54 
55 private:
56  std::string _name;
58 };
59 
61 
64 class AcademicUser : public User
65 {
66 public:
67  AcademicUser(uint id) : User(id) {}
68  AcademicUser(const std::string& name) : User( name), _jobCount(0) {}
69  AcademicUser(const std::string& name, uint jobCount) : User(name), _jobCount(jobCount) {}
70 
71  uint GetJobCount() const { return _jobCount; }
72 
73  bool Save(ByteBuffer& bb) const override;
74 
75  void CreatedJob(const Job* job) override { if (job) _jobCount++; }
76 
77  bool CanCreateJob(const Job* job) override { return !!job; }
78 
79  void Print(std::ostream& os = std::cout) const override;
80 
81 private:
83 };
84 
86 
89 class EnterpriseUser : public User
90 {
91 public:
92  EnterpriseUser(const std::string& name, double budget) : User(name), _budget(budget) {}
93 
94  double GetBudget() const { return _budget; }
95 
96  void SetBudget(double val) { _budget = val; }
97 
98  bool Save(ByteBuffer& bb) const override;
99 
100  void CreatedJob(const Job* job) override;
101 
102  bool CanCreateJob(const Job* job) override;
103 
104  void Print(std::ostream& os = std::cout) const override;
105 
106 private:
107  double _budget;
108 };
109 
110 #endif // USER_H_