diff options
Diffstat (limited to 'src/Main.cc')
-rw-r--r-- | src/Main.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/Main.cc b/src/Main.cc new file mode 100644 index 0000000..f3bf0d7 --- /dev/null +++ b/src/Main.cc @@ -0,0 +1,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); +} |