├── src ├── AMutex.o ├── APizza.o ├── main.o ├── AProcess.o ├── AThread.o ├── ACondVars.o ├── ANamedPipe.o ├── AThreadPool.o ├── Americana.o ├── AProcess.cpp ├── APizza.cpp ├── AThread.cpp ├── AUI.cpp ├── AMutex.cpp ├── Mutex.cpp ├── CondVars.cpp ├── Process.cpp ├── ACondVars.cpp ├── Thread.cpp ├── Ingredient.cpp ├── Plazza.cpp ├── Pizza.cpp ├── ANamedPipe.cpp ├── AThreadPool.cpp ├── main.cpp ├── Margarita.cpp ├── Order.cpp ├── Americana.cpp ├── Cook.cpp ├── Regina.cpp ├── Fantasia.cpp ├── Factory.cpp ├── NamedPipe.cpp ├── Kitchen.cpp ├── Reception.cpp └── Parser.cpp ├── .gitattributes ├── inc ├── Static.hh ├── Regina.hh ├── CondVars.hh ├── Fantasia.hh ├── AMutex.hh ├── Americana.hh ├── Margarita.hh ├── IUI.hh ├── AUI.hh ├── Mutex.hh ├── Thread.hh ├── Process.hh ├── ACondVars.hh ├── Pizza.hh ├── Order.hh ├── Cook.hh ├── NamedPipe.hh ├── AProcess.hh ├── Plazza.hh ├── Ingredient.hh ├── Factory.hh ├── AThread.hh ├── AThreadPool.hh ├── Reception.hh ├── APizza.hh ├── ANamedPipe.hh ├── Kitchen.hh └── Parser.hh ├── .gitignore └── Makefile /src/AMutex.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/AMutex.o -------------------------------------------------------------------------------- /src/APizza.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/APizza.o -------------------------------------------------------------------------------- /src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/main.o -------------------------------------------------------------------------------- /src/AProcess.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/AProcess.o -------------------------------------------------------------------------------- /src/AThread.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/AThread.o -------------------------------------------------------------------------------- /src/ACondVars.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/ACondVars.o -------------------------------------------------------------------------------- /src/ANamedPipe.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/ANamedPipe.o -------------------------------------------------------------------------------- /src/AThreadPool.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/AThreadPool.o -------------------------------------------------------------------------------- /src/Americana.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Plazza/master/src/Americana.o -------------------------------------------------------------------------------- /src/AProcess.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AProcess.cpp for AProcess.cpp in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Sun Apr 27 18:28:01 2014 LOEB Thomas 8 | // Last update Sun Apr 27 18:28:37 2014 LOEB Thomas 9 | // 10 | 11 | #include "AProcess.hh" 12 | 13 | AProcess::AProcess() {} 14 | 15 | AProcess::~AProcess() {} 16 | -------------------------------------------------------------------------------- /src/APizza.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // APizza.cpp for APizza.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:20:50 2014 Baptiste Acca 8 | // Last update Fri Apr 25 14:01:21 2014 Baptiste Acca 9 | // 10 | 11 | #include "APizza.hh" 12 | 13 | APizza::APizza() 14 | { 15 | 16 | } 17 | 18 | APizza::~APizza() 19 | { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/AThread.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AThread.cpp for AThread.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:55:23 2014 Baptiste Acca 8 | // Last update Fri Apr 25 15:55:29 2014 Baptiste Acca 9 | // 10 | 11 | #include "AThread.hh" 12 | 13 | AThread::AThread() 14 | { 15 | 16 | } 17 | 18 | AThread::~AThread() 19 | { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/AUI.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AUI.cpp for AUI.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 16:09:24 2014 abgral_f 8 | // Last update Sun Apr 27 12:35:23 2014 LOEB Thomas 9 | // 10 | 11 | #include "AUI.hh" 12 | 13 | AUI::AUI() {} 14 | 15 | AUI::~AUI() {} 16 | 17 | std::string AUI::getLine() const { 18 | return (this->_line); 19 | } 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /src/AMutex.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AMutex.cpp for AMutex.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 14:01:42 2014 Baptiste Acca 8 | // Last update Fri Apr 25 18:10:54 2014 LOEB Thomas 9 | // 10 | 11 | #include "AMutex.hh" 12 | 13 | AMutex::AMutex() { 14 | pthread_mutex_init(&this->_mutex, NULL); 15 | } 16 | 17 | AMutex::~AMutex() { 18 | pthread_mutex_destroy(&this->_mutex); 19 | } 20 | -------------------------------------------------------------------------------- /inc/Static.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Static.hh for Static.hh in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Sat Apr 26 18:47:54 2014 LOEB Thomas 8 | // Last update Sat Apr 26 18:48:27 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef STATIC_HH_ 12 | # define STATIC_HH_ 13 | 14 | # include "Kitchen.hh" 15 | 16 | double Kitchen::_multiplier; 17 | int Kitchen::_nbCooks; 18 | int Kitchen::_timerFill; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /inc/Regina.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Regina.hh for Regina.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:02:35 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:36:26 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef REGINA_HH_ 12 | #define REGINA_HH_ 13 | 14 | #include "Pizza.hh" 15 | 16 | class Regina : public Pizza { 17 | public: 18 | Regina(int const &, TaillePizza const &); 19 | Regina(TaillePizza const &); 20 | virtual ~Regina(); 21 | }; 22 | 23 | #endif /* REGINA_HH_ */ 24 | -------------------------------------------------------------------------------- /src/Mutex.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Mutex.cpp for Mutex.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 12:56:06 2014 abgral_f 8 | // Last update Fri Apr 25 18:30:05 2014 LOEB Thomas 9 | // 10 | 11 | #include "Mutex.hh" 12 | 13 | Mutex::Mutex() {} 14 | 15 | Mutex::~Mutex() {} 16 | 17 | void Mutex::lock() { 18 | pthread_mutex_lock(&this->_mutex); 19 | } 20 | 21 | void Mutex::unlock() { 22 | pthread_mutex_unlock(&this->_mutex); 23 | } 24 | -------------------------------------------------------------------------------- /inc/CondVars.hh: -------------------------------------------------------------------------------- 1 | // 2 | // CondVars.hh for CondVars.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:48:27 2014 Baptiste Acca 8 | // Last update Fri Apr 25 13:56:14 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef CONDVARS_HH_ 12 | #define CONDVARS_HH_ 13 | 14 | #include "ACondVars.hh" 15 | 16 | class CondVars : public ACondVars { 17 | public: 18 | CondVars(); 19 | virtual ~CondVars(); 20 | virtual int timedwait(); 21 | virtual int signal(); 22 | }; 23 | 24 | #endif /* CONDVARS_HH_ */ 25 | -------------------------------------------------------------------------------- /inc/Fantasia.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Fantasia.hh for Fantasia.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:07:59 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:49:14 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef FANTASIA_HH_ 12 | #define FANTASIA_HH_ 13 | 14 | #include "Pizza.hh" 15 | 16 | class Fantasia : public Pizza { 17 | public: 18 | Fantasia(int const &, TaillePizza const &); 19 | Fantasia(TaillePizza const &); 20 | virtual ~Fantasia(); 21 | }; 22 | 23 | #endif /* FANTASIA_HH_ */ 24 | -------------------------------------------------------------------------------- /inc/AMutex.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Amutex.hh for Amutex.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 21:18:53 2014 abgral_f 8 | // Last update Fri Apr 25 18:28:10 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef AMUTEX_HH_ 12 | # define AMUTEX_HH_ 13 | 14 | #include 15 | 16 | class AMutex { 17 | protected: 18 | pthread_mutex_t _mutex; 19 | 20 | public: 21 | AMutex(); 22 | virtual ~AMutex(); 23 | virtual void lock() = 0; 24 | virtual void unlock() = 0; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /inc/Americana.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Americana.hh for Americana.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:07:06 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:36:16 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef AMERICANA_HH_ 12 | #define AMERICANA_HH_ 13 | 14 | #include "Pizza.hh" 15 | 16 | class Americana : public Pizza { 17 | public: 18 | Americana(int const &, TaillePizza const &); 19 | Americana(TaillePizza const &); 20 | virtual ~Americana(); 21 | }; 22 | 23 | #endif /* AMERICANA_HH_ */ 24 | -------------------------------------------------------------------------------- /inc/Margarita.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Margarita.hh for Margarita.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:50:41 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:36:38 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef MARGARITA_HH_ 12 | #define MARGARITA_HH_ 13 | 14 | #include "Pizza.hh" 15 | 16 | class Margarita : public Pizza { 17 | public: 18 | Margarita(int const &, TaillePizza const &); 19 | Margarita(TaillePizza const &); 20 | virtual ~Margarita(); 21 | }; 22 | 23 | #endif /* MARGARITA_HH_ */ 24 | -------------------------------------------------------------------------------- /inc/IUI.hh: -------------------------------------------------------------------------------- 1 | // 2 | // IUI.hh for IUI.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:53:54 2014 abgral_f 8 | // Last update Sun Apr 27 18:21:01 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef IUI_HH_ 12 | # define IUI_HH_ 13 | 14 | #include "Kitchen.hh" 15 | 16 | class IUI { 17 | public: 18 | virtual ~IUI() {} 19 | virtual void getOrder(std::vector &) = 0; 20 | virtual int getCooksOccup(Kitchen *) = 0; 21 | virtual bool getIngredients(Kitchen *) = 0; 22 | }; 23 | 24 | # endif 25 | -------------------------------------------------------------------------------- /inc/AUI.hh: -------------------------------------------------------------------------------- 1 | // 2 | // AUI.hh for AUI.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:59:52 2014 abgral_f 8 | // Last update Sun Apr 27 12:24:03 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef AUI_HH_ 12 | # define AUI_HH_ 13 | 14 | #include 15 | #include "IUI.hh" 16 | // #include "GUI.hh" 17 | 18 | class AUI : public IUI 19 | { 20 | protected: 21 | std::string _line; 22 | // GUI *_gui; 23 | 24 | public: 25 | AUI(); 26 | virtual ~AUI(); 27 | std::string getLine() const; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/CondVars.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CondVars.cpp for CondVars.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:48:18 2014 Baptiste Acca 8 | // Last update Sat Apr 26 16:47:32 2014 LOEB Thomas 9 | // 10 | 11 | #include "CondVars.hh" 12 | 13 | CondVars::CondVars() { 14 | } 15 | 16 | CondVars::~CondVars() { 17 | } 18 | 19 | int CondVars::timedwait() 20 | { 21 | return (pthread_cond_timedwait(&(this->_cond), &(this->_mutex), &(this->_timeout))); 22 | } 23 | 24 | int CondVars::signal() 25 | { 26 | return (pthread_cond_signal(&(this->_cond))); 27 | } 28 | -------------------------------------------------------------------------------- /inc/Mutex.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Mutex.hh for Mutex.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 12:57:24 2014 abgral_f 8 | // Last update Fri Apr 25 18:23:19 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef MUTEX_HH_ 12 | # define MUTEX_HH_ 13 | 14 | #include "AMutex.hh" 15 | 16 | class Mutex : public AMutex 17 | { 18 | public: 19 | Mutex(); 20 | virtual ~Mutex(); 21 | virtual void lock(); 22 | virtual void unlock(); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/Process.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Process.cpp for Process.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:17:42 2014 abgral_f 8 | // Last update Sun Apr 27 18:31:22 2014 LOEB Thomas 9 | // 10 | 11 | #include "Process.hh" 12 | 13 | Process::Process() {} 14 | 15 | Process::~Process() {} 16 | 17 | int Process::fork() 18 | { 19 | this->_pid = ::fork(); 20 | return (this->_pid); 21 | } 22 | 23 | int Process::waitpid() const 24 | { 25 | return (::waitpid(0, NULL, 0)); 26 | } 27 | 28 | pid_t Process::getPid() const 29 | { 30 | return (this->_pid); 31 | } 32 | -------------------------------------------------------------------------------- /inc/Thread.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Thread.hh for Thread.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 14:26:31 2014 abgral_f 8 | // Last update Sat Apr 26 12:19:01 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef THREAD_HH_ 12 | # define THREAD_HH_ 13 | 14 | #include "AThread.hh" 15 | 16 | class Thread : public AThread 17 | { 18 | public: 19 | Thread(); 20 | virtual ~Thread(); 21 | virtual void create(void *(*start_routine)(void*), void *); 22 | virtual void join(); 23 | virtual void exit(); 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /inc/Process.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Process.hh for Process.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:15:47 2014 abgral_f 8 | // Last update Sun Apr 27 18:30:29 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef PROCESS_HH_ 12 | # define PROCESS_HH_ 13 | 14 | #include "AProcess.hh" 15 | 16 | class Process : public AProcess 17 | { 18 | public: 19 | Process(); 20 | virtual ~Process(); 21 | virtual int fork(); 22 | virtual int waitpid() const; 23 | virtual pid_t getPid() const; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /inc/ACondVars.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ACondVars.hh for ACondVars.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:42:18 2014 Baptiste Acca 8 | // Last update Sat Apr 26 16:57:08 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef ACONDVARS_HH_ 12 | #define ACONDVARS_HH_ 13 | 14 | #include 15 | 16 | class ACondVars { 17 | protected: 18 | pthread_cond_t _cond; 19 | pthread_mutex_t _mutex; 20 | struct timespec _timeout; 21 | 22 | public: 23 | ACondVars(); 24 | virtual ~ACondVars(); 25 | void setTimeOut(unsigned int); 26 | virtual int timedwait() = 0; 27 | virtual int signal() = 0; 28 | }; 29 | 30 | #endif /* ACONDVARS_HH_ */ 31 | -------------------------------------------------------------------------------- /inc/Pizza.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Pizza.hh for Pizza.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 16:52:43 2014 Baptiste Acca 8 | // Last update Sat Apr 26 18:27:09 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef PIZZA_HH_ 12 | #define PIZZA_HH_ 13 | 14 | #include "APizza.hh" 15 | 16 | class Pizza : public APizza { 17 | public: 18 | Pizza(); 19 | virtual ~Pizza(); 20 | virtual void bakePizza(double const &) const; 21 | virtual std::vector getIngredients() const; 22 | virtual TaillePizza getSize() const; 23 | virtual TypePizza getType() const; 24 | virtual int getIdCmd() const; 25 | virtual void setIdCmd(int const &); 26 | }; 27 | 28 | #endif /* PIZZA_HH_ */ 29 | -------------------------------------------------------------------------------- /inc/Order.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Order.hh for Order.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 18:45:28 2014 Baptiste Acca 8 | // Last update Sun Apr 27 16:47:39 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef ORDER_HH_ 12 | #define ORDER_HH_ 13 | 14 | #include 15 | #include 16 | #include "APizza.hh" 17 | 18 | class Order { 19 | private: 20 | std::string _cmd; 21 | std::vector _pizzas; 22 | clock_t _time; 23 | 24 | public: 25 | Order(std::vector, std::string); 26 | ~Order(); 27 | bool pizzaReady(std::string const &); 28 | clock_t getTime() const; 29 | std::string const & getCmd() const; 30 | }; 31 | 32 | #endif /* ORDER_HH_ */ 33 | -------------------------------------------------------------------------------- /src/ACondVars.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ACondVars.cpp for ACondVars.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:42:28 2014 Baptiste Acca 8 | // Last update Sat Apr 26 18:09:04 2014 LOEB Thomas 9 | // 10 | 11 | #include "ACondVars.hh" 12 | 13 | ACondVars::ACondVars() 14 | { 15 | pthread_cond_init(&this->_cond, NULL); 16 | pthread_mutex_init(&this->_mutex, NULL); 17 | } 18 | 19 | ACondVars::~ACondVars() 20 | { 21 | pthread_cond_destroy(&this->_cond); 22 | pthread_mutex_destroy(&this->_mutex); 23 | } 24 | 25 | void ACondVars::setTimeOut(unsigned int sec) { 26 | clock_gettime(CLOCK_REALTIME, &this->_timeout); 27 | this->_timeout.tv_sec += sec; 28 | this->_timeout.tv_nsec = 0; 29 | } 30 | -------------------------------------------------------------------------------- /inc/Cook.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Cook.hh for Cook.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:06:27 2014 abgral_f 8 | // Last update Sun Apr 27 16:15:22 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef COOK_HH_ 12 | # define COOK_HH_ 13 | 14 | #include "Ingredient.hh" 15 | #include "Thread.hh" 16 | 17 | class Kitchen; 18 | 19 | class Cook : public Thread 20 | { 21 | public: 22 | Cook(Kitchen &); 23 | virtual ~Cook(); 24 | APizza * getPizza() const; 25 | bool takeIngredients(AMutex *, Ingredient *[], APizza *); 26 | void makePizzas(Kitchen *); 27 | Kitchen * getATP() const; 28 | 29 | private: 30 | Kitchen *_atp; 31 | APizza *_pizza; 32 | }; 33 | 34 | void *launchCook(void *); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /inc/NamedPipe.hh: -------------------------------------------------------------------------------- 1 | // 2 | // NamedPipe.hh for NamedPipe.hh in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:19:35 2014 LOEB Thomas 8 | // Last update Fri Apr 25 15:43:02 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef NAMEDPIPE_HH_ 12 | # define NAMEDPIPE_HH_ 13 | 14 | # include "ANamedPipe.hh" 15 | 16 | # define RIGHTS 0644 17 | 18 | class NamedPipe : public ANamedPipe { 19 | public: 20 | NamedPipe(unsigned int); 21 | virtual ~NamedPipe(); 22 | virtual void mkfifo(); 23 | virtual void unlink(); 24 | virtual void open(ANamedPipe::Speaker); 25 | virtual void close(ANamedPipe::Speaker); 26 | virtual void write(ANamedPipe::Speaker); 27 | virtual void read(ANamedPipe::Speaker); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /inc/AProcess.hh: -------------------------------------------------------------------------------- 1 | // 2 | // AProcess.hh for AProcess.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 22:05:27 2014 abgral_f 8 | // Last update Sun Apr 27 18:30:55 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef APROCESS_HH_ 12 | # define APROCESS_HH_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | class AProcess 19 | { 20 | public: 21 | AProcess(); 22 | virtual ~AProcess(); 23 | virtual int fork() = 0; 24 | virtual int waitpid() const = 0; 25 | virtual pid_t getPid() const = 0; 26 | protected: 27 | pid_t _pid; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/Thread.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Thread.cpp for Thread.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 14:27:41 2014 abgral_f 8 | // Last update Sat Apr 26 12:20:44 2014 LOEB Thomas 9 | // 10 | 11 | #include "Thread.hh" 12 | 13 | Thread::Thread() {} 14 | 15 | Thread::~Thread() {} 16 | 17 | void Thread::create(void *(*start_routine)(void*), void *arg) 18 | { 19 | if (::pthread_create(&(this->_thread), NULL, start_routine, arg) != 0) 20 | throw std::runtime_error(PTHREAD_CREATE_ERROR); 21 | } 22 | 23 | void Thread::join() 24 | { 25 | if (::pthread_join(this->_thread, NULL) != 0) 26 | throw std::runtime_error(PTHREAD_JOIN_ERROR); 27 | } 28 | 29 | void Thread::exit() 30 | { 31 | ::pthread_exit(NULL); 32 | } 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /src/Ingredient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Ingredient.cpp for Ingredient.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 14:59:11 2014 Baptiste Acca 8 | // Last update Thu Apr 24 15:19:34 2014 Baptiste Acca 9 | // 10 | 11 | #include "Ingredient.hh" 12 | 13 | Ingredient::Ingredient(TypeIngredient const &type, unsigned int const &amount) 14 | { 15 | this->_type = type; 16 | this->_amount = amount; 17 | } 18 | 19 | Ingredient::~Ingredient() 20 | { 21 | 22 | } 23 | 24 | TypeIngredient Ingredient::getType() const 25 | { 26 | return this->_type; 27 | } 28 | 29 | unsigned int Ingredient::getAmount() const 30 | { 31 | return this->_amount; 32 | } 33 | 34 | void Ingredient::incIng() 35 | { 36 | this->_amount++; 37 | } 38 | 39 | void Ingredient::decIng() 40 | { 41 | this->_amount--; 42 | } 43 | -------------------------------------------------------------------------------- /inc/Plazza.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Plazza.hh for Plazza.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:08:50 2014 Baptiste Acca 8 | // Last update Sun Apr 27 16:15:55 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef PLAZZA_HH_ 12 | # define PLAZZA_HH_ 13 | 14 | # include "Reception.hh" 15 | 16 | /* ERRORS */ 17 | 18 | # define BAD_ARGS "[Plazza]: Usage: ./Plazza CookingTimeMultiplier CooksNumber TimeRefill" 19 | # define NEG_ARG "[Plazza]: Error: Arguments can't have negatives values" 20 | 21 | class Plazza { 22 | private: 23 | Reception *_reception; 24 | std::vector _kitchens; 25 | bool _open; 26 | 27 | public: 28 | Plazza(); 29 | ~Plazza(); 30 | bool isOpen() const; 31 | void closePlazza(bool); 32 | void makeBusiness(); 33 | }; 34 | 35 | #endif /* PLAZZA_HH_ */ 36 | -------------------------------------------------------------------------------- /inc/Ingredient.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Ingredient.hh for Ingredient.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 14:59:04 2014 Baptiste Acca 8 | // Last update Sun Apr 27 12:59:03 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef INGREDIENT_HH_ 12 | #define INGREDIENT_HH_ 13 | 14 | typedef enum TypeIngredient 15 | { 16 | DOE, 17 | TOMATO, 18 | GRUYERE, 19 | HAM, 20 | MUSHROOMS, 21 | STEAK, 22 | EGGPLANT, 23 | GOATCHEESE, 24 | CHIEFLOVE 25 | } TypeIngredient; 26 | 27 | class Ingredient { 28 | TypeIngredient _type; 29 | unsigned int _amount; 30 | public: 31 | Ingredient(TypeIngredient const &, unsigned int const &); 32 | ~Ingredient(); 33 | TypeIngredient getType() const; 34 | unsigned int getAmount() const; 35 | void incIng(); 36 | void decIng(); 37 | }; 38 | 39 | #endif /* INGREDIENT_HH_ */ 40 | -------------------------------------------------------------------------------- /src/Plazza.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Plazza.cpp for Plazza.cpp in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Sun Apr 27 12:48:28 2014 LOEB Thomas 8 | // Last update Sun Apr 27 18:33:14 2014 LOEB Thomas 9 | // 10 | 11 | #include "Plazza.hh" 12 | #include "Process.hh" 13 | 14 | Plazza::Plazza() { 15 | this->_reception = new Reception(); 16 | this->_open = true; 17 | } 18 | 19 | Plazza::~Plazza() { 20 | delete(this->_reception); 21 | } 22 | 23 | bool Plazza::isOpen() const { 24 | return (this->_open); 25 | } 26 | 27 | void Plazza::closePlazza(bool b) { 28 | this->_open = !b; 29 | } 30 | 31 | void Plazza::makeBusiness() { 32 | Process wait; 33 | 34 | while (this->isOpen() == true) 35 | { 36 | this->_reception->listen(this->_kitchens); 37 | if (this->_reception->getLine() == "/closed") 38 | this->closePlazza(true); 39 | } 40 | while (!wait.waitpid()); 41 | } 42 | -------------------------------------------------------------------------------- /inc/Factory.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Factory.hh for Factory.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:51:45 2014 Baptiste Acca 8 | // Last update Thu Apr 24 18:30:15 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef FACTORY_HH_ 12 | #define FACTORY_HH_ 13 | 14 | #include "APizza.hh" 15 | 16 | class Factory { 17 | private: 18 | TypePizza _types[4]; 19 | APizza *(Factory::*_typePtr[4])(TaillePizza const &, int const &) const; 20 | private: 21 | APizza *createMargarita(TaillePizza const &, int const &) const; 22 | APizza *createAmericana(TaillePizza const &, int const &) const; 23 | APizza *createFantasia(TaillePizza const &, int const &) const; 24 | APizza *createRegina(TaillePizza const &, int const &) const; 25 | public: 26 | Factory(); 27 | ~Factory(); 28 | APizza *createPizza(TypePizza const &, TaillePizza const &, int const &) const; 29 | }; 30 | 31 | #endif /* FACTORY_HH_ */ 32 | -------------------------------------------------------------------------------- /inc/AThread.hh: -------------------------------------------------------------------------------- 1 | // 2 | // AThread.hh for AThread.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 14:20:56 2014 abgral_f 8 | // Last update Fri Apr 25 19:14:17 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef ATHREAD_HH_ 12 | # define ATHREAD_HH_ 13 | 14 | #include 15 | #include 16 | 17 | /* ERRORS */ 18 | 19 | # define PTHREAD_CREATE_ERROR "[Plazza]: ERROR: System call 'fork' failed\n" 20 | # define PTHREAD_JOIN_ERROR "[Plazza]: ERROR: System call 'fork' failed\n" 21 | 22 | class AThread 23 | { 24 | protected: 25 | pthread_t _thread; 26 | 27 | public: 28 | AThread(); 29 | virtual ~AThread(); 30 | virtual void create(void *(*start_routine)(void*), void *) = 0; 31 | virtual void join() = 0; 32 | virtual void exit() = 0; 33 | }; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/Pizza.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Pizza.cpp for Pizza.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 16:52:25 2014 Baptiste Acca 8 | // Last update Sat Apr 26 18:26:31 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include "Pizza.hh" 13 | 14 | Pizza::Pizza() 15 | { 16 | 17 | } 18 | 19 | Pizza::~Pizza() 20 | { 21 | 22 | } 23 | 24 | void Pizza::bakePizza(double const &multiplier) const 25 | { 26 | usleep(this->_cookTime * 1000000 * multiplier); 27 | } 28 | 29 | std::vector Pizza::getIngredients() const 30 | { 31 | return (this->_ingredients); 32 | } 33 | 34 | TaillePizza Pizza::getSize() const 35 | { 36 | return (this->_size); 37 | } 38 | 39 | TypePizza Pizza::getType() const 40 | { 41 | return (this->_type); 42 | } 43 | 44 | int Pizza::getIdCmd() const 45 | { 46 | return (this->_idCmd); 47 | } 48 | 49 | void Pizza::setIdCmd(int const &idCmd) 50 | { 51 | this->_idCmd = idCmd; 52 | } 53 | -------------------------------------------------------------------------------- /inc/AThreadPool.hh: -------------------------------------------------------------------------------- 1 | // 2 | // AThreadPool.hh for AThreadPool.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:13:31 2014 Baptiste Acca 8 | // Last update Sun Apr 27 18:48:48 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef ATHREADPOOL_HH_ 12 | #define ATHREADPOOL_HH_ 13 | 14 | #include "CondVars.hh" 15 | #include "Mutex.hh" 16 | #include "Pizza.hh" 17 | 18 | class AThreadPool { 19 | protected: 20 | ACondVars *_cond; 21 | AMutex *_mutex; 22 | std::vector _pizzas; 23 | 24 | public: 25 | AThreadPool(); 26 | virtual ~AThreadPool(); 27 | AMutex * getMutex() const; 28 | APizza * takePizza(); 29 | int waitPizza(unsigned int); 30 | int freePizza(); 31 | virtual void waitOrder() = 0; 32 | virtual void getOrder() = 0; 33 | virtual void giveCooksOccup() const = 0; 34 | virtual void giveCooksIngredients() const = 0; 35 | virtual void givePizza(APizza const *) const = 0; 36 | }; 37 | 38 | #endif /* ATHREADPOOL_HH_ */ 39 | -------------------------------------------------------------------------------- /src/ANamedPipe.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ANamedPipe.cpp for ANamedPipe.cpp in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:31:16 2014 LOEB Thomas 8 | // Last update Fri Apr 25 16:16:42 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include "ANamedPipe.hh" 13 | 14 | ANamedPipe::ANamedPipe(unsigned int noKitchen) { 15 | std::ostringstream oss; 16 | 17 | oss << noKitchen; 18 | this->_filenames[0] = std::string(K_TO_R(oss.str())); 19 | this->_filenames[1] = std::string(R_TO_K(oss.str())); 20 | } 21 | 22 | ANamedPipe::~ANamedPipe() {} 23 | 24 | std::string const & ANamedPipe::getFilename(unsigned int idx) const { 25 | return (this->_filenames[idx]); 26 | } 27 | 28 | int ANamedPipe::getFd(unsigned int idx) const { 29 | return (this->_fds[idx]); 30 | } 31 | 32 | std::string const & ANamedPipe::getBuffer() const { 33 | return (this->_buffer); 34 | } 35 | 36 | void ANamedPipe::setBuffer(std::string const & buffer) { 37 | this->_buffer = buffer; 38 | } 39 | -------------------------------------------------------------------------------- /inc/Reception.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Reception.hh for Reception.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:58:19 2014 abgral_f 8 | // Last update Sun Apr 27 18:23:35 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef RECEPTION_HH_ 12 | # define RECEPTION_HH_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "AUI.hh" 19 | #include "Order.hh" 20 | 21 | class Reception : public AUI 22 | { 23 | private: 24 | std::vector _orders; 25 | fd_set _listenfds; 26 | 27 | public: 28 | Reception(); 29 | virtual ~Reception(); 30 | virtual void getOrder(std::vector &); 31 | virtual int getCooksOccup(Kitchen *); 32 | virtual bool getIngredients(Kitchen *); 33 | void listen(std::vector &); 34 | void algorithm(std::vector &, std::vector const &); 35 | void createKitchen(std::vector &); 36 | }; 37 | 38 | template 39 | T getNb(std::string const &); 40 | 41 | # endif 42 | -------------------------------------------------------------------------------- /src/AThreadPool.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AThreadPool.cpp for AThreadPool.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:13:27 2014 Baptiste Acca 8 | // Last update Sun Apr 27 16:53:56 2014 LOEB Thomas 9 | // 10 | 11 | #include "AThreadPool.hh" 12 | 13 | AThreadPool::AThreadPool() 14 | { 15 | this->_cond = new CondVars(); 16 | this->_mutex = new Mutex(); 17 | } 18 | 19 | AThreadPool::~AThreadPool() 20 | { 21 | delete(this->_cond); 22 | delete(this->_mutex); 23 | } 24 | 25 | AMutex * AThreadPool::getMutex() const { 26 | return (this->_mutex); 27 | } 28 | 29 | APizza * AThreadPool::takePizza() { 30 | APizza * ret = NULL; 31 | 32 | if (!this->_pizzas.empty()) { 33 | this->_mutex->lock(); 34 | ret = this->_pizzas.back(); 35 | this->_pizzas.pop_back(); 36 | this->_mutex->unlock(); 37 | } 38 | return (ret); 39 | } 40 | 41 | int AThreadPool::waitPizza(unsigned int sec) { 42 | this->_cond->setTimeOut(sec); 43 | return (this->_cond->timedwait()); 44 | } 45 | 46 | int AThreadPool::freePizza() { 47 | return (this->_cond->signal()); 48 | } 49 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp for main.cpp in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Fri Apr 25 16:47:49 2014 LOEB Thomas 8 | // Last update Sun Apr 27 18:50:06 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include 13 | #include "Plazza.hh" 14 | 15 | template 16 | T getNb(std::string const &nb) 17 | { 18 | T ret; 19 | std::stringstream oss(nb); 20 | 21 | oss >> ret; 22 | return ret; 23 | } 24 | 25 | void parsParameters(int ac, char **av) 26 | { 27 | if (ac != 4) 28 | throw std::runtime_error(BAD_ARGS); 29 | if ((Kitchen::_multiplier = getNb(av[1])) < 0 30 | || (Kitchen::_nbCooks = getNb(av[2])) < 0 31 | || (Kitchen::_timerFill = getNb(av[3])) < 0) 32 | throw std::runtime_error(NEG_ARG); 33 | } 34 | 35 | int main(int ac, char **av) { 36 | Plazza plazza; 37 | 38 | try 39 | { 40 | parsParameters(ac, av); 41 | plazza.makeBusiness(); 42 | } 43 | catch (std::runtime_error e) { 44 | std::cerr << e.what() << std::endl; 45 | } 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /inc/APizza.hh: -------------------------------------------------------------------------------- 1 | // 2 | // APizza.hh for APizza.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:20:56 2014 Baptiste Acca 8 | // Last update Sat Apr 26 18:26:46 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef APIZZA_HH_ 12 | #define APIZZA_HH_ 13 | 14 | #include 15 | #include "Ingredient.hh" 16 | 17 | typedef enum TypePizza 18 | { 19 | REGINA = 1, 20 | MARGARITA = 2, 21 | AMERICAINE = 4, 22 | FANTASIA = 8 23 | } TypePizza; 24 | 25 | typedef enum TaillePizza 26 | { 27 | S = 1, 28 | M = 2, 29 | L = 4, 30 | XL = 8, 31 | XXL = 16 32 | } TaillePizza; 33 | 34 | class APizza { 35 | protected: 36 | std::vector _ingredients; 37 | unsigned int _cookTime; 38 | TypePizza _type; 39 | TaillePizza _size; 40 | int _idCmd; 41 | 42 | public: 43 | APizza(); 44 | ~APizza(); 45 | virtual void bakePizza(double const &) const = 0; 46 | virtual std::vector getIngredients() const = 0; 47 | virtual TaillePizza getSize() const = 0; 48 | virtual TypePizza getType() const = 0; 49 | virtual int getIdCmd() const = 0; 50 | virtual void setIdCmd(int const &) = 0; 51 | }; 52 | 53 | #endif /* APIZZA_HH_ */ 54 | -------------------------------------------------------------------------------- /src/Margarita.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Margarita.cpp for Margarita.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 15:50:38 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:40:04 2014 Baptiste Acca 9 | // 10 | 11 | #include "Margarita.hh" 12 | 13 | Margarita::Margarita(int const &idCmd, TaillePizza const &size) 14 | { 15 | this->_size = size; 16 | this->_type = MARGARITA; 17 | this->_cookTime = 1; 18 | this->_idCmd = idCmd; 19 | Ingredient *tmp = new Ingredient(DOE, 1); 20 | this->_ingredients.push_back(tmp); 21 | delete tmp; 22 | tmp = new Ingredient(TOMATO, 1); 23 | this->_ingredients.push_back(tmp); 24 | delete tmp; 25 | tmp = new Ingredient(GRUYERE, 1); 26 | this->_ingredients.push_back(tmp); 27 | delete tmp; 28 | } 29 | 30 | Margarita::Margarita(TaillePizza const &size) 31 | { 32 | this->_size = size; 33 | this->_type = MARGARITA; 34 | this->_cookTime = 1; 35 | Ingredient *tmp = new Ingredient(DOE, 1); 36 | this->_ingredients.push_back(tmp); 37 | delete tmp; 38 | tmp = new Ingredient(TOMATO, 1); 39 | this->_ingredients.push_back(tmp); 40 | delete tmp; 41 | tmp = new Ingredient(GRUYERE, 1); 42 | this->_ingredients.push_back(tmp); 43 | delete tmp; 44 | } 45 | 46 | Margarita::~Margarita() 47 | { 48 | 49 | } 50 | -------------------------------------------------------------------------------- /inc/ANamedPipe.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ANamedPipe.hh for ANamedPipe.hh in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Fri Apr 25 13:13:36 2014 LOEB Thomas 8 | // Last update Fri Apr 25 16:29:41 2014 LOEB Thomas 9 | // 10 | 11 | #ifndef ANAMEDPIPE_HH_ 12 | # define ANAMEDPIPE_HH_ 13 | 14 | # include 15 | 16 | # define NB_PIPE 2 17 | # define SIZE_BUFFER 4096 18 | # define K_TO_R(x) ("k"+x+"_to_r") 19 | # define R_TO_K(x) ("r_to_k"+x) 20 | 21 | class ANamedPipe { 22 | public: 23 | typedef enum Speaker 24 | { 25 | Kitchen = 0, 26 | Reception = 2 27 | } Speaker; 28 | 29 | protected: 30 | std::string _filenames[NB_PIPE]; 31 | int _fds[NB_PIPE * 2]; 32 | std::string _buffer; 33 | 34 | public: 35 | ANamedPipe(unsigned int); 36 | virtual ~ANamedPipe(); 37 | std::string const & getFilename(unsigned int) const; 38 | int getFd(unsigned int) const; 39 | std::string const & getBuffer() const; 40 | void setBuffer(std::string const &); 41 | virtual void mkfifo() = 0; 42 | virtual void unlink() = 0; 43 | virtual void open(ANamedPipe::Speaker) = 0; 44 | virtual void write(ANamedPipe::Speaker) = 0; 45 | virtual void read(ANamedPipe::Speaker) = 0; 46 | virtual void close(ANamedPipe::Speaker) = 0; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile for Makefile in /home/loeb_t/rendu/cpp_plazza 3 | ## 4 | ## Made by LOEB Thomas 5 | ## Login 6 | ## 7 | ## Started on Fri Apr 25 16:38:57 2014 LOEB Thomas 8 | ## Last update Tue Apr 29 15:08:03 2014 abgral_f 9 | ## 10 | 11 | NAME = plazza 12 | 13 | F_SRC = src/ 14 | 15 | F_INC = inc/ 16 | 17 | SRC = $(F_SRC)main.cpp \ 18 | $(F_SRC)ACondVars.cpp \ 19 | $(F_SRC)Americana.cpp \ 20 | $(F_SRC)AMutex.cpp \ 21 | $(F_SRC)ANamedPipe.cpp \ 22 | $(F_SRC)APizza.cpp \ 23 | $(F_SRC)AProcess.cpp \ 24 | $(F_SRC)AThread.cpp \ 25 | $(F_SRC)AThreadPool.cpp \ 26 | $(F_SRC)AUI.cpp \ 27 | $(F_SRC)CondVars.cpp \ 28 | $(F_SRC)Cook.cpp \ 29 | $(F_SRC)Factory.cpp \ 30 | $(F_SRC)Fantasia.cpp \ 31 | $(F_SRC)Ingredient.cpp \ 32 | $(F_SRC)Kitchen.cpp \ 33 | $(F_SRC)Margarita.cpp \ 34 | $(F_SRC)Mutex.cpp \ 35 | $(F_SRC)NamedPipe.cpp \ 36 | $(F_SRC)Order.cpp \ 37 | $(F_SRC)Pizza.cpp \ 38 | $(F_SRC)Plazza.cpp \ 39 | $(F_SRC)Process.cpp \ 40 | $(F_SRC)Reception.cpp \ 41 | $(F_SRC)Regina.cpp \ 42 | $(F_SRC)Thread.cpp \ 43 | $(F_SRC)Parser.cpp \ 44 | 45 | OBJ = $(SRC:.cpp=.o) 46 | 47 | CPPFLAGS= -W -Wall -Werror -Wextra -I$(F_INC) 48 | 49 | all: $(NAME) 50 | 51 | $(NAME): $(OBJ) 52 | g++ -o $(NAME) $(OBJ) -lpthread 53 | 54 | clean: 55 | rm -f $(OBJ) 56 | 57 | fclean: clean 58 | rm -f $(NAME) 59 | 60 | re: fclean all 61 | -------------------------------------------------------------------------------- /src/Order.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Order.cpp for Order.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 18:48:11 2014 Baptiste Acca 8 | // Last update Sun Apr 27 17:51:12 2014 LOEB Thomas 9 | // 10 | 11 | #include "Order.hh" 12 | #include "Factory.hh" 13 | 14 | Order::Order(std::vector pizzas, std::string cmd) { 15 | Factory tmp; 16 | 17 | for (unsigned int i = 0; i < pizzas.size(); ++i) 18 | this->_pizzas.push_back(tmp.createPizza(static_cast((*pizzas[i])[2]), 19 | static_cast((*pizzas[i])[3]), 20 | static_cast((*pizzas[i])[1]))); 21 | this->_cmd = cmd; 22 | this->_time = ::clock(); 23 | } 24 | 25 | Order::~Order() {} 26 | 27 | bool Order::pizzaReady(std::string const & s) { 28 | for (unsigned int i = 0; i < this->_pizzas.size(); ++i) 29 | if (this->_pizzas[i]->getIdCmd() == s[1] && 30 | this->_pizzas[i]->getType() == s[2] && 31 | this->_pizzas[i]->getSize() == s[3]) { 32 | this->_pizzas.erase(this->_pizzas.begin() + i); 33 | if (this->_pizzas.empty() == true) 34 | { 35 | this->_time = ::clock() - this->_time; 36 | return (true); 37 | } 38 | return (false); 39 | } 40 | return (false); 41 | } 42 | 43 | clock_t Order::getTime() const { 44 | return (this->_time); 45 | } 46 | 47 | std::string const & Order::getCmd() const { 48 | return (this->_cmd); 49 | } 50 | -------------------------------------------------------------------------------- /inc/Kitchen.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Kitchen.hh for Kitchen.hh in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:20:55 2014 Baptiste Acca 8 | // Last update Sun Apr 27 16:36:42 2014 Baptiste Acca 9 | // 10 | 11 | #ifndef KITCHEN_HH_ 12 | #define KITCHEN_HH_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include "AThreadPool.hh" 18 | #include "Cook.hh" 19 | #include "Factory.hh" 20 | #include "NamedPipe.hh" 21 | 22 | #define NB_INGREDIENTS 9 23 | #define INGREDIENTS_BASE_NB 5 24 | 25 | class Kitchen : public AThreadPool { 26 | unsigned int _id; 27 | std::vector _cooks; 28 | AThread *_stockManagement; 29 | Ingredient *_stock[NB_INGREDIENTS]; 30 | bool _stop; 31 | ANamedPipe *_namedPipe; 32 | Factory _factory; 33 | fd_set _listenfds; 34 | 35 | public: 36 | static double _multiplier; 37 | static int _nbCooks; 38 | static int _timerFill; 39 | 40 | public: 41 | Kitchen(unsigned int); 42 | virtual ~Kitchen(); 43 | bool isAllFree() const; 44 | virtual void waitOrder(); 45 | virtual void getOrder(); 46 | virtual void giveCooksOccup() const; 47 | virtual void giveCooksIngredients() const; 48 | virtual void givePizza(APizza const *) const; 49 | Ingredient **getStock(); 50 | bool getStop() const; 51 | void setStop(bool const); 52 | ANamedPipe *getNamedPipe() const; 53 | unsigned int getId() const; 54 | }; 55 | 56 | #endif /* KITCHEN_HH_ */ 57 | -------------------------------------------------------------------------------- /src/Americana.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Americana.cpp for Americana.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:04:34 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:40:32 2014 Baptiste Acca 9 | // 10 | 11 | #include "Americana.hh" 12 | 13 | Americana::Americana(int const &idCmd, TaillePizza const &size) 14 | { 15 | this->_size = size; 16 | this->_type = AMERICAINE; 17 | this->_cookTime = 2; 18 | this->_idCmd = idCmd; 19 | Ingredient *tmp = new Ingredient(DOE, 1); 20 | this->_ingredients.push_back(tmp); 21 | delete tmp; 22 | tmp = new Ingredient(TOMATO, 1); 23 | this->_ingredients.push_back(tmp); 24 | delete tmp; 25 | tmp = new Ingredient(GRUYERE, 1); 26 | this->_ingredients.push_back(tmp); 27 | delete tmp; 28 | tmp = new Ingredient(STEAK, 1); 29 | this->_ingredients.push_back(tmp); 30 | delete tmp; 31 | } 32 | 33 | Americana::Americana(TaillePizza const &size) 34 | { 35 | this->_size = size; 36 | this->_type = AMERICAINE; 37 | this->_cookTime = 2; 38 | Ingredient *tmp = new Ingredient(DOE, 1); 39 | this->_ingredients.push_back(tmp); 40 | delete tmp; 41 | tmp = new Ingredient(TOMATO, 1); 42 | this->_ingredients.push_back(tmp); 43 | delete tmp; 44 | tmp = new Ingredient(GRUYERE, 1); 45 | this->_ingredients.push_back(tmp); 46 | delete tmp; 47 | tmp = new Ingredient(STEAK, 1); 48 | this->_ingredients.push_back(tmp); 49 | delete tmp; 50 | } 51 | 52 | Americana::~Americana() 53 | { 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/Cook.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Cook.cpp for Cook.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:17:39 2014 abgral_f 8 | // Last update Sun Apr 27 16:16:51 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include "Kitchen.hh" 13 | 14 | Cook::Cook(Kitchen & atp) : _atp(&atp), _pizza(NULL) {} 15 | 16 | Cook::~Cook() {} 17 | 18 | APizza * Cook::getPizza() const { 19 | return (this->_pizza); 20 | } 21 | 22 | bool Cook::takeIngredients(AMutex *am, Ingredient *ing[NB_INGREDIENTS], APizza *ap) { 23 | am->lock(); 24 | for (unsigned int i = 0; i < ap->getIngredients().size(); ++i) 25 | if (ing[ap->getIngredients()[i]->getType()]->getAmount() <= 0) 26 | return (false); 27 | else 28 | ing[ap->getIngredients()[i]->getType()]->decIng(); 29 | am->unlock(); 30 | return (true); 31 | } 32 | 33 | void Cook::makePizzas(Kitchen *atp) { 34 | while (atp->getStop() == false) 35 | if (this->_pizza == NULL && (this->_pizza = atp->takePizza()) == NULL) { 36 | if (atp->waitPizza(5) == ETIMEDOUT && 37 | atp->isAllFree() == true) 38 | atp->setStop(true); 39 | } else { 40 | if (this->takeIngredients(atp->getMutex(), atp->getStock(), this->_pizza) == true) { 41 | this->_pizza->bakePizza(atp->_multiplier); 42 | atp->givePizza(this->_pizza); 43 | this->_pizza = NULL; 44 | } 45 | atp->freePizza(); 46 | } 47 | } 48 | 49 | Kitchen * Cook::getATP() const { 50 | return (this->_atp); 51 | } 52 | 53 | void *launchCook(void *cook) { 54 | Cook *_cook = static_cast(cook); 55 | 56 | _cook->makePizzas(_cook->getATP()); 57 | return (NULL); 58 | } 59 | -------------------------------------------------------------------------------- /src/Regina.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Regina.cpp for Regina.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:02:03 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:39:41 2014 Baptiste Acca 9 | // 10 | 11 | #include "Regina.hh" 12 | 13 | Regina::Regina(int const &idCmd, TaillePizza const &size) 14 | { 15 | this->_size = size; 16 | this->_type = REGINA; 17 | this->_cookTime = 2; 18 | this->_idCmd = idCmd; 19 | Ingredient *tmp = new Ingredient(DOE, 1); 20 | this->_ingredients.push_back(tmp); 21 | delete tmp; 22 | tmp = new Ingredient(TOMATO, 1); 23 | this->_ingredients.push_back(tmp); 24 | delete tmp; 25 | tmp = new Ingredient(GRUYERE, 1); 26 | this->_ingredients.push_back(tmp); 27 | delete tmp; 28 | tmp = new Ingredient(HAM, 1); 29 | this->_ingredients.push_back(tmp); 30 | delete tmp; 31 | tmp = new Ingredient(MUSHROOMS, 1); 32 | this->_ingredients.push_back(tmp); 33 | delete tmp; 34 | } 35 | 36 | Regina::Regina(TaillePizza const &size) 37 | { 38 | this->_size = size; 39 | this->_type = REGINA; 40 | this->_cookTime = 2; 41 | Ingredient *tmp = new Ingredient(DOE, 1); 42 | this->_ingredients.push_back(tmp); 43 | delete tmp; 44 | tmp = new Ingredient(TOMATO, 1); 45 | this->_ingredients.push_back(tmp); 46 | delete tmp; 47 | tmp = new Ingredient(GRUYERE, 1); 48 | this->_ingredients.push_back(tmp); 49 | delete tmp; 50 | tmp = new Ingredient(HAM, 1); 51 | this->_ingredients.push_back(tmp); 52 | delete tmp; 53 | tmp = new Ingredient(MUSHROOMS, 1); 54 | this->_ingredients.push_back(tmp); 55 | delete tmp; 56 | } 57 | 58 | Regina::~Regina() 59 | { 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Fantasia.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Fantasia.cpp for Fantasia.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:05:48 2014 Baptiste Acca 8 | // Last update Thu Apr 24 17:41:05 2014 Baptiste Acca 9 | // 10 | 11 | #include "Fantasia.hh" 12 | 13 | Fantasia::Fantasia(int const &idCmd, TaillePizza const &size) 14 | { 15 | this->_size = size; 16 | this->_type = FANTASIA; 17 | this->_cookTime = 4; 18 | this->_idCmd = idCmd; 19 | Ingredient *tmp = new Ingredient(DOE, 1); 20 | this->_ingredients.push_back(tmp); 21 | delete tmp; 22 | tmp = new Ingredient(TOMATO, 1); 23 | this->_ingredients.push_back(tmp); 24 | delete tmp; 25 | tmp = new Ingredient(EGGPLANT, 1); 26 | this->_ingredients.push_back(tmp); 27 | delete tmp; 28 | tmp = new Ingredient(GOATCHEESE, 1); 29 | this->_ingredients.push_back(tmp); 30 | delete tmp; 31 | tmp = new Ingredient(CHIEFLOVE, 1); 32 | this->_ingredients.push_back(tmp); 33 | delete tmp; 34 | } 35 | 36 | Fantasia::Fantasia(TaillePizza const &size) 37 | { 38 | this->_size = size; 39 | this->_type = FANTASIA; 40 | this->_cookTime = 4; 41 | Ingredient *tmp = new Ingredient(DOE, 1); 42 | this->_ingredients.push_back(tmp); 43 | delete tmp; 44 | tmp = new Ingredient(TOMATO, 1); 45 | this->_ingredients.push_back(tmp); 46 | delete tmp; 47 | tmp = new Ingredient(EGGPLANT, 1); 48 | this->_ingredients.push_back(tmp); 49 | delete tmp; 50 | tmp = new Ingredient(GOATCHEESE, 1); 51 | this->_ingredients.push_back(tmp); 52 | delete tmp; 53 | tmp = new Ingredient(CHIEFLOVE, 1); 54 | this->_ingredients.push_back(tmp); 55 | delete tmp; 56 | } 57 | 58 | Fantasia::~Fantasia() 59 | { 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Factory.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Factory.cpp for Factory.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Thu Apr 24 17:58:17 2014 Baptiste Acca 8 | // Last update Sun Apr 27 12:59:36 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include "Factory.hh" 13 | #include "Regina.hh" 14 | #include "Americana.hh" 15 | #include "Margarita.hh" 16 | #include "Fantasia.hh" 17 | 18 | Factory::Factory() 19 | { 20 | this->_types[0] = REGINA; 21 | this->_typePtr[0] = &Factory::createRegina; 22 | this->_types[1] = MARGARITA; 23 | this->_typePtr[1] = &Factory::createMargarita; 24 | this->_types[2] = AMERICAINE; 25 | this->_typePtr[2] = &Factory::createAmericana; 26 | this->_types[3] = FANTASIA; 27 | this->_typePtr[3] = &Factory::createFantasia; 28 | } 29 | 30 | Factory::~Factory() 31 | { 32 | 33 | } 34 | 35 | APizza *Factory::createRegina(TaillePizza const &size, int const &idCmd) const 36 | { 37 | return new Regina(idCmd, size); 38 | } 39 | 40 | APizza *Factory::createMargarita(TaillePizza const &size, int const &idCmd) const 41 | { 42 | return new Margarita(idCmd, size); 43 | } 44 | 45 | APizza *Factory::createAmericana(TaillePizza const &size, int const &idCmd) const 46 | { 47 | return new Americana(idCmd, size); 48 | } 49 | 50 | APizza *Factory::createFantasia(TaillePizza const &size, int const &idCmd) const 51 | { 52 | return new Fantasia(idCmd, size); 53 | } 54 | 55 | APizza *Factory::createPizza(TypePizza const &type, TaillePizza const &size, int const &idCmd) const 56 | { 57 | unsigned int i; 58 | 59 | for (i = 0; i < 4 && this->_types[i] != type; i++); 60 | if (i < 4 && this->_types[i] == type) 61 | return (this->*_typePtr[i])(size, idCmd); 62 | return (NULL); 63 | } 64 | -------------------------------------------------------------------------------- /inc/Parser.hh: -------------------------------------------------------------------------------- 1 | // 2 | // Parser.hh for Parser.hh in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 17:12:06 2014 abgral_f 8 | // Last update Sun Apr 27 14:34:20 2014 abgral_f 9 | // 10 | 11 | #ifndef PARSER_HH_ 12 | # define PARSER_HH_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "APizza.hh" 20 | 21 | /* ERRORS */ 22 | 23 | # define WRONG_SYNTHAX "Synthax error : TYPE SIZE NUMBER[; TYPE SIZE NUMBER]" 24 | # define NO_PIZZAS "You cannot command 0 pizza" 25 | 26 | # define REGINA_STR "regina" 27 | # define MARGARITA_STR "margarita" 28 | # define AMERICAINE_STR "americaine" 29 | # define FANTASIA_STR "fantasia" 30 | 31 | # define SIZE_S "S" 32 | # define SIZE_M "M" 33 | # define SIZE_L "L" 34 | # define SIZE_XL "XL" 35 | # define SIZE_XXL "XXL" 36 | 37 | class Parser 38 | { 39 | public: 40 | Parser(); 41 | ~Parser(); 42 | std::vector const checkOrder(std::string &); 43 | void setIdCommand(unsigned int); 44 | private: 45 | void pushNbPizzas(std::string const &); 46 | void countPizzas(unsigned int, bool &, 47 | std::vector const &); 48 | void initToCompare(); 49 | void initTranscription(); 50 | std::vector getWords(std::string const &); 51 | void doTranscription(std::vector const &); 52 | private: 53 | std::string _nbPizzas; 54 | unsigned int _idCommand; 55 | std::vector _listPizzas; 56 | std::vector > _toCompare; 57 | std::vector > _transcription; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/NamedPipe.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // NamedPipe.cpp for NamedPipe.cpp in /home/loeb_t/rendu/cpp_plazza 3 | // 4 | // Made by LOEB Thomas 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:21:03 2014 LOEB Thomas 8 | // Last update Sun Apr 27 18:45:40 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "NamedPipe.hh" 16 | 17 | NamedPipe::NamedPipe(unsigned int noKitchen) : ANamedPipe(noKitchen) { 18 | this->mkfifo(); 19 | } 20 | 21 | NamedPipe::~NamedPipe() { 22 | this->unlink(); 23 | } 24 | 25 | void NamedPipe::mkfifo() { 26 | ::mkfifo(this->_filenames[0].c_str(), RIGHTS); 27 | ::mkfifo(this->_filenames[1].c_str(), RIGHTS); 28 | } 29 | 30 | void NamedPipe::unlink() { 31 | ::unlink(this->_filenames[0].c_str()); 32 | ::unlink(this->_filenames[1].c_str()); 33 | } 34 | 35 | void NamedPipe::open(ANamedPipe::Speaker speaker) { 36 | if (speaker == ANamedPipe::Kitchen) { 37 | this->_fds[speaker] = ::open(this->_filenames[0].c_str(), O_WRONLY); 38 | this->_fds[speaker + 1] = ::open(this->_filenames[1].c_str(), O_RDONLY); 39 | } else { 40 | this->_fds[speaker + 1] = ::open(this->_filenames[0].c_str(), O_RDONLY); 41 | this->_fds[speaker] = ::open(this->_filenames[1].c_str(), O_WRONLY); 42 | } 43 | } 44 | 45 | void NamedPipe::close(ANamedPipe::Speaker speaker) { 46 | ::close(this->_fds[speaker]); 47 | ::close(this->_fds[speaker + 1]); 48 | } 49 | 50 | void NamedPipe::write(ANamedPipe::Speaker speaker) { 51 | ::write(this->_fds[speaker], this->_buffer.c_str(), this->_buffer.length()); 52 | } 53 | 54 | void NamedPipe::read(ANamedPipe::Speaker speaker) { 55 | char buffer[SIZE_BUFFER + 1]; 56 | int ret; 57 | 58 | ret = ::read(this->_fds[speaker + 1], buffer, SIZE_BUFFER); 59 | buffer[ret] = '\0'; 60 | this->_buffer = buffer; 61 | } 62 | -------------------------------------------------------------------------------- /src/Kitchen.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Kitchen.cpp for Kitchen.cpp in /home/acca_b/rendu/cpp_plazza 3 | // 4 | // Made by Baptiste Acca 5 | // Login 6 | // 7 | // Started on Fri Apr 25 15:20:51 2014 Baptiste Acca 8 | // Last update Sun Apr 27 18:17:26 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include 13 | #include "Kitchen.hh" 14 | #include "Static.hh" 15 | 16 | Kitchen::Kitchen(unsigned int id) 17 | { 18 | unsigned int i; 19 | 20 | for (i = 0; i < NB_INGREDIENTS ; ++i) 21 | this->_stock[i] = new Ingredient(static_cast(i), INGREDIENTS_BASE_NB); 22 | for (i = 0; static_cast(i) < Kitchen::_nbCooks; ++i) 23 | this->_cooks.push_back(new Cook(*this)); 24 | this->_id = id; 25 | this->_stockManagement = new Thread(); 26 | this->_stop = false; 27 | this->_namedPipe = new NamedPipe(id); 28 | for (i = 0; static_cast(i) < Kitchen::_nbCooks; ++i) 29 | this->_cooks[i]->create(&launchCook, this->_cooks[i]); 30 | } 31 | 32 | Kitchen::~Kitchen() 33 | { 34 | for (unsigned int i = 0; static_cast(i) < Kitchen::_nbCooks; ++i) 35 | this->_cooks[i]->join(); 36 | delete[](this->_stock); 37 | delete (this->_stockManagement); 38 | delete (this->_namedPipe); 39 | } 40 | 41 | bool Kitchen::isAllFree() const { 42 | for (unsigned int i = 0; i < this->_cooks.size(); ++i) 43 | if (this->_cooks[i]->getPizza() != NULL) 44 | return (false); 45 | return (true); 46 | } 47 | 48 | void *incIngredients(void *data) 49 | { 50 | Kitchen *kitchen; 51 | 52 | kitchen = static_cast(data); 53 | while (kitchen->getStop() == false) 54 | { 55 | usleep(Kitchen::_timerFill * 1000); 56 | kitchen->getMutex()->lock(); 57 | for (unsigned int i = 0; i < NB_INGREDIENTS; ++i) 58 | { 59 | if (kitchen->getStock()[i]->getAmount() < NB_INGREDIENTS) 60 | kitchen->getStock()[i]->incIng(); 61 | } 62 | kitchen->getMutex()->unlock(); 63 | } 64 | return (NULL); 65 | } 66 | 67 | void Kitchen::waitOrder() { 68 | int max = this->_namedPipe->getFd(ANamedPipe::Kitchen + 1); 69 | struct timeval tv; 70 | 71 | this->_stockManagement->create(&incIngredients, this); 72 | while (this->getStop() == false) { 73 | FD_ZERO(&this->_listenfds); 74 | FD_SET(max, &this->_listenfds); 75 | tv.tv_sec = 1; 76 | tv.tv_usec = 0; 77 | if (select(max + 1, &this->_listenfds, NULL, NULL, &tv) > 0) 78 | if (FD_ISSET(max, &this->_listenfds)) 79 | this->getOrder(); 80 | } 81 | this->_stockManagement->join(); 82 | } 83 | 84 | void Kitchen::getOrder() { 85 | this->_namedPipe->read(ANamedPipe::Kitchen); 86 | std::string const ret = this->_namedPipe->getBuffer(); 87 | if (ret[0] == '0') 88 | { 89 | APizza *newPizza = this->_factory.createPizza(static_cast(ret[2]), 90 | static_cast(ret[3]), 91 | static_cast(ret[1])); 92 | this->_mutex->lock(); 93 | this->_pizzas.push_back(newPizza); 94 | this->_mutex->unlock(); 95 | } 96 | else if (ret[0] == '1') 97 | this->giveCooksOccup(); 98 | else if (ret[0] == '2') 99 | this->giveCooksIngredients(); 100 | } 101 | 102 | void Kitchen::giveCooksOccup() const { 103 | std::ostringstream pizzaLeft; 104 | 105 | pizzaLeft << ((this->_cooks.size() * 2) - this->_pizzas.size()) << std::endl; 106 | this->_namedPipe->setBuffer(pizzaLeft.str()); 107 | this->_namedPipe->write(ANamedPipe::Kitchen); 108 | } 109 | 110 | void Kitchen::giveCooksIngredients() const { 111 | std::ostringstream ingrStatus; 112 | 113 | for (unsigned int i = 0; i < NB_INGREDIENTS ; i++) 114 | ingrStatus << this->_stock[i]->getAmount(); 115 | ingrStatus << std::endl; 116 | this->_namedPipe->setBuffer(ingrStatus.str()); 117 | this->_namedPipe->write(ANamedPipe::Kitchen); 118 | } 119 | 120 | void Kitchen::givePizza(APizza const *pizza) const { 121 | std::ostringstream pizzaReady; 122 | 123 | pizzaReady << '0' << pizza->getIdCmd() << pizza->getType() << pizza->getSize() << std::endl; 124 | this->_namedPipe->setBuffer(pizzaReady.str()); 125 | this->_namedPipe->write(ANamedPipe::Kitchen); 126 | } 127 | 128 | Ingredient **Kitchen::getStock() { 129 | return this->_stock; 130 | } 131 | 132 | bool Kitchen::getStop() const { 133 | return this->_stop; 134 | } 135 | 136 | void Kitchen::setStop(bool const stop) { 137 | this->_stop = stop; 138 | } 139 | 140 | ANamedPipe *Kitchen::getNamedPipe() const { 141 | return this->_namedPipe; 142 | } 143 | 144 | unsigned int Kitchen::getId() const { 145 | return this->_id; 146 | } 147 | -------------------------------------------------------------------------------- /src/Reception.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Reception.cpp for Reception.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Thu Apr 24 16:06:07 2014 abgral_f 8 | // Last update Sun Apr 27 18:46:25 2014 LOEB Thomas 9 | // 10 | 11 | #include 12 | #include "Reception.hh" 13 | #include "Parser.hh" 14 | #include "Process.hh" 15 | 16 | Reception::Reception() {} 17 | 18 | Reception::~Reception() {} 19 | 20 | void Reception::getOrder(std::vector & kitchens) 21 | { 22 | Parser p; 23 | std::vector pizzas; 24 | 25 | if (!std::getline(std::cin, this->_line, '\n')) 26 | this->_line = "/closed"; 27 | if (this->_line != "/closed") { 28 | p.setIdCommand(this->_orders.size() + 1); 29 | try { 30 | pizzas = p.checkOrder(this->_line); 31 | this->_orders.push_back(new Order(pizzas, this->_line)); 32 | this->algorithm(kitchens, pizzas); 33 | } catch (std::logic_error le) { 34 | std::cerr << le.what() << std::endl; 35 | } 36 | } 37 | } 38 | 39 | int Reception::getCooksOccup(Kitchen * k) 40 | { 41 | std::string cmd("1"); 42 | k->getNamedPipe()->setBuffer(cmd); 43 | k->getNamedPipe()->write(ANamedPipe::Reception); 44 | k->getNamedPipe()->read(ANamedPipe::Reception); 45 | std::string const ret = k->getNamedPipe()->getBuffer(); 46 | return (getNb(ret)); 47 | } 48 | 49 | bool Reception::getIngredients(Kitchen * k) 50 | { 51 | std::string cmd("2"); 52 | k->getNamedPipe()->setBuffer(cmd); 53 | k->getNamedPipe()->write(ANamedPipe::Reception); 54 | k->getNamedPipe()->read(ANamedPipe::Reception); 55 | std::string const ret = k->getNamedPipe()->getBuffer(); 56 | for (unsigned int i = 0; i < NB_INGREDIENTS ; ++i) 57 | if (ret[i] == '0') 58 | return (false); 59 | return (true); 60 | } 61 | 62 | void Reception::createKitchen(std::vector & ks) { 63 | Process p; 64 | Kitchen * k; 65 | unsigned int idx; 66 | unsigned int i; 67 | 68 | if (p.fork() == 0) { 69 | idx = ks.size() + 1; 70 | k = new Kitchen(idx); 71 | ks.push_back(k); 72 | k->getNamedPipe()->open(ANamedPipe::Kitchen); 73 | k->waitOrder(); 74 | for (i = 0; i < ks.size() && ks[i]->getId() != idx; ++i); 75 | ks.erase(ks.begin() + i); 76 | k->getNamedPipe()->close(ANamedPipe::Kitchen); 77 | k->getNamedPipe()->close(ANamedPipe::Reception); 78 | delete (k); 79 | } else if (p.getPid() > 0) { 80 | k->getNamedPipe()->open(ANamedPipe::Reception); 81 | } 82 | } 83 | 84 | void Reception::algorithm(std::vector & ks, std::vector const & ps) 85 | { 86 | int idxK; 87 | int size_min; 88 | int tmp; 89 | unsigned int j ; 90 | 91 | for (unsigned int i = 0; i < ps.size(); ++i) { 92 | size_min = Kitchen::_nbCooks * 2; 93 | idxK = -1; 94 | for (j = 0; j < ks.size(); ++j) 95 | if ((tmp = this->getCooksOccup(ks[j])) < size_min && 96 | this->getIngredients(ks[j]) == true) { 97 | size_min = tmp; 98 | idxK = j; 99 | } 100 | if (idxK == -1) { 101 | idxK = j; 102 | this->createKitchen(ks); 103 | } 104 | ks[idxK]->getNamedPipe()->setBuffer(*ps[i]); 105 | ks[idxK]->getNamedPipe()->write(ANamedPipe::Reception); 106 | } 107 | } 108 | 109 | void Reception::listen(std::vector & kitchens) { 110 | struct timeval tv; 111 | int max = 0; 112 | 113 | FD_ZERO(&this->_listenfds); 114 | FD_SET(0, &this->_listenfds); 115 | for (unsigned int i = 0; i < kitchens.size(); ++i) 116 | { 117 | if (kitchens[i]->getNamedPipe()->getFd(ANamedPipe::Reception + 1) > max) 118 | max = kitchens[i]->getNamedPipe()->getFd(ANamedPipe::Reception + 1); 119 | FD_SET(kitchens[i]->getNamedPipe()->getFd(ANamedPipe::Reception + 1), &this->_listenfds); 120 | } 121 | tv.tv_sec = 1; 122 | tv.tv_usec = 0; 123 | if (select(max + 1, &this->_listenfds, NULL, NULL, &tv) > 0) 124 | { 125 | if (FD_ISSET(0, &this->_listenfds)) 126 | getOrder(kitchens); 127 | for (unsigned int i = 0; i < kitchens.size(); ++i) 128 | if (FD_ISSET(kitchens[i]->getNamedPipe()->getFd(ANamedPipe::Reception + 1), &this->_listenfds)) 129 | { 130 | kitchens[i]->getNamedPipe()->read(ANamedPipe::Reception); 131 | std::string const ret = kitchens[i]->getNamedPipe()->getBuffer(); 132 | if (this->_orders[ret[1]]->pizzaReady(ret) == true) 133 | { 134 | std::cout << "Command \"" 135 | << this->_orders[ret[1]]->getCmd() 136 | << "\" done in " 137 | << static_cast(this->_orders[ret[1]]->getTime() / CLOCKS_PER_SEC) 138 | << " second(s)" 139 | << std::endl; 140 | this->_orders.erase(this->_orders.begin() + ret[1]); 141 | } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/Parser.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Parser.cpp for Parser.cpp in /home/abgral_f/rendu/cpp_plazza 3 | // 4 | // Made by abgral_f 5 | // Login 6 | // 7 | // Started on Fri Apr 25 17:14:42 2014 abgral_f 8 | // Last update Sun Apr 27 18:53:23 2014 abgral_f 9 | // 10 | 11 | #include "Parser.hh" 12 | 13 | Parser::Parser() 14 | { 15 | 16 | } 17 | 18 | Parser::~Parser() 19 | { 20 | 21 | } 22 | 23 | void Parser::initToCompare() 24 | { 25 | std::vector type; 26 | std::vector size; 27 | 28 | type.push_back(REGINA_STR); 29 | type.push_back(MARGARITA_STR); 30 | type.push_back(AMERICAINE_STR); 31 | type.push_back(FANTASIA_STR); 32 | size.push_back(SIZE_S); 33 | size.push_back(SIZE_M); 34 | size.push_back(SIZE_L); 35 | size.push_back(SIZE_XL); 36 | size.push_back(SIZE_XXL); 37 | this->_toCompare.push_back(type); 38 | this->_toCompare.push_back(size); 39 | } 40 | 41 | void Parser::initTranscription() 42 | { 43 | std::vector type; 44 | std::vector size; 45 | 46 | type.push_back(REGINA); 47 | type.push_back(MARGARITA); 48 | type.push_back(AMERICAINE); 49 | type.push_back(FANTASIA); 50 | size.push_back(S); 51 | size.push_back(M); 52 | size.push_back(L); 53 | size.push_back(XL); 54 | size.push_back(XXL); 55 | this->_transcription.push_back(type); 56 | this->_transcription.push_back(size); 57 | } 58 | 59 | std::vector Parser::getWords(std::string const &line) 60 | { 61 | std::istringstream tmp(line); 62 | std::vector words; 63 | std::string word; 64 | 65 | while (42) 66 | { 67 | tmp >> word; 68 | if (tmp == 0) 69 | break; 70 | words.push_back(word); 71 | } 72 | return (words); 73 | } 74 | 75 | void Parser::pushNbPizzas(std::string const &line) 76 | { 77 | std::istringstream tmp(this->_nbPizzas); 78 | unsigned int count; 79 | unsigned int nb_pizzas; 80 | 81 | tmp >> nb_pizzas; 82 | count = 0; 83 | if (nb_pizzas == 0) 84 | throw std::logic_error(NO_PIZZAS); 85 | while (count != nb_pizzas) 86 | { 87 | this->_listPizzas.push_back(new std::string(line)); 88 | count++; 89 | } 90 | } 91 | 92 | void Parser::countPizzas(unsigned int i, bool &check, 93 | std::vector const &words) 94 | { 95 | unsigned int count; 96 | 97 | if (words[i].size() < 2) 98 | throw std::logic_error(WRONG_SYNTHAX); 99 | count = 1; 100 | this->_nbPizzas = "0"; 101 | while (words[i][count] != '\0') 102 | { 103 | 104 | if (words[i][count] >= '0' && words[i][count] <= '9') 105 | this->_nbPizzas += words[i][count]; 106 | else if (words[i][count] != ';') 107 | throw std::logic_error(WRONG_SYNTHAX); 108 | else 109 | { 110 | check = true; 111 | break; 112 | } 113 | count++; 114 | } 115 | } 116 | 117 | void Parser::doTranscription(std::vector const &words) 118 | { 119 | std::string tmp; 120 | unsigned int count; 121 | unsigned int i = 0; 122 | bool check = true; 123 | 124 | while (check == true) 125 | { 126 | tmp = ""; 127 | check = false; 128 | count = 0; 129 | tmp += count; 130 | tmp += this->_idCommand; 131 | if (i == words.size()) 132 | throw std::logic_error(WRONG_SYNTHAX); 133 | while (count != this->_toCompare[0].size() && words[i] != this->_toCompare[0][count]) 134 | count++; 135 | if (count == this->_toCompare[0].size()) 136 | throw std::logic_error(WRONG_SYNTHAX); 137 | tmp += this->_transcription[0][count]; 138 | i++; 139 | count = 0; 140 | if (i == words.size()) 141 | throw std::logic_error(WRONG_SYNTHAX); 142 | while (count != this->_toCompare[1].size() && words[i] != this->_toCompare[1][count]) 143 | count++; 144 | if (count == this->_toCompare[1].size()) 145 | throw std::logic_error(WRONG_SYNTHAX); 146 | tmp += this->_transcription[1][count]; 147 | i++; 148 | if (i == words.size()) 149 | throw std::logic_error(WRONG_SYNTHAX); 150 | if (words[i][0] != 'x') 151 | throw std::logic_error(WRONG_SYNTHAX); 152 | this->countPizzas(i, check, words); 153 | i++; 154 | if (check == false) 155 | { 156 | if (i != words.size()) 157 | if (words[i] == ";") 158 | check = true; 159 | i++; 160 | } 161 | this->pushNbPizzas(tmp); 162 | } 163 | } 164 | 165 | std::vector const Parser::checkOrder(std::string &line) 166 | { 167 | this->initToCompare(); 168 | this->initTranscription(); 169 | this->doTranscription(this->getWords(line)); 170 | return (this->_listPizzas); 171 | } 172 | 173 | void Parser::setIdCommand(unsigned int idCommand) 174 | { 175 | this->_idCommand = idCommand; 176 | } 177 | --------------------------------------------------------------------------------