summaryrefslogtreecommitdiff
path: root/src/Main.cc
blob: f3bf0d7508f85c317b5de7147b741fa98c30a5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <unistd.h>
#include "Action.h"
#include "Handle.h"
#include "HttpServ.h"
#include "Socket.h"
#include "config.h"
#include "Message.h"
#include "Menu.h"
#include "Exceptions.h"
#include "Form.h"
#include "Confirm.h"
#include "Table.h"
#include "admin.h"

class InPipe : public Handle {
  public:
      InPipe(int in, int out) : Handle(in), m_out(out) { };
      virtual ~InPipe() {}
    int GetOut(void) { return m_out; }
    virtual bool CanWrite(void) { return false; }
    virtual bool CanRead(void) { return true; }
    virtual String GetName(void) { return "Input pipe"; }
  private:
    int m_out;
} * in;

extern Action * MenuAdmin, * MenuGestionMatos, * MenuGestionChantier, * MenuGestionPieces, * MenuGestionFournisseurs, * MenuInterventions, * MenuGestionLocations;
Action * ListeMenuPrincipal[] = {MenuAdmin, MenuGestionMatos, MenuGestionChantier, MenuGestionPieces, MenuGestionFournisseurs, MenuInterventions, MenuGestionLocations};
String MenuPrincipalLabels[] = {"Administration", "Gestion du materiel", "Gestion des chantiers", "Gestion du stock de pièces", "Gestion des fournisseurs", "Interventions", "Locations"};

Action * buildmenu(void) {
    return new Menu("Menu Principal", "start", MenuPrincipalLabels, ListeMenuPrincipal, 7);
}

int main(int argc, char ** argv) {
    int p[2], c;
    String port = "1500";
    
    if (pipe(p)) {
	cerr << "Error creating pipe.\n";
	exit(-1);
    }
    
    close(1);
    dup(p[1]);
    in = new InPipe(p[0], p[1]);
    
    String test = "poide\n", r;
    cout << test;
    cout.flush();
    (*in) >> r;
    if (r != "poide") {
	cerr << "The stdout redirect has failed.\n";
	exit(-1);
    }
    
    while ((c = getopt(argc, argv, "p:")) != EOF) {
	switch (c) {
	case 'p':
	    port = optarg;
	    break;
	default:
	    cerr << "Usage: " << argv[0] << " [-p port]\n";
	    exit(-1);
	}
    }
    
    try {
	HttpServ h(port.to_int());

	h.MainLoop(buildmenu());
    }
    catch (GeneralException e) {
	cerr << e.GetMsg() << endl;
	exit(-1);
    }
    
    delete in;
    exit(0);
}