From e7cc0e7100a1da010bfd19d0bd2c46ca610fe82c Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 5 Jun 2014 21:40:07 +0200 Subject: [PATCH] [DEV] Change main application start (done only for X11) --- sources/ewol/context/Application.cpp | 0 sources/ewol/context/Application.h | 33 ++++++++++++++++++++++++++++ sources/ewol/context/Context.cpp | 17 +++++++++----- sources/ewol/context/Context.h | 26 ++++++++-------------- sources/ewol/context/X11/Context.cpp | 8 +++---- sources/ewol/ewol.h | 5 +++-- sources/ewol/widget/Windows.h | 2 +- 7 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 sources/ewol/context/Application.cpp create mode 100644 sources/ewol/context/Application.h diff --git a/sources/ewol/context/Application.cpp b/sources/ewol/context/Application.cpp new file mode 100644 index 00000000..e69de29b diff --git a/sources/ewol/context/Application.h b/sources/ewol/context/Application.h new file mode 100644 index 00000000..224a756a --- /dev/null +++ b/sources/ewol/context/Application.h @@ -0,0 +1,33 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EWOL_CONTEXT_APPLICATION_H__ +#define __EWOL_CONTEXT_APPLICATION_H__ + +namespace ewol { + class Context; + namespace context { + class Application { + protected: + size_t m_nbStepInit; + public: + size_t getNbStepInit() { + return m_nbStepInit; + } + public: + Application() : + m_nbStepInit(1) {}; + virtual ~Application() {}; + public: + virtual bool init(ewol::Context& _context, size_t _initId) = 0; + virtual void unInit(ewol::Context& _context) = 0; + }; + }; +}; + +#endif diff --git a/sources/ewol/context/Context.cpp b/sources/ewol/context/Context.cpp index 9e5db504..73d9fa1b 100644 --- a/sources/ewol/context/Context.cpp +++ b/sources/ewol/context/Context.cpp @@ -165,7 +165,7 @@ void ewol::Context::processEvents() { case eSystemMessage::msgInit: // this is due to the openGL context /*bool returnVal = */ - APP_Init(*this, m_initStepId, m_initTotalStep); + m_application->init(*this, m_initStepId); m_initStepId++; break; case eSystemMessage::msgRecalculateSize: @@ -287,7 +287,9 @@ void ewol::Context::setArchiveDir(int _mode, const char* _str) { -ewol::Context::Context(int32_t _argc, const char* _argv[]) : +ewol::Context::Context(ewol::context::Application* _application, int32_t _argc, const char* _argv[]) : + //m_application(std::make_shared(_application)), + m_application(_application), m_objectManager(*this), m_previousDisplayTime(0), m_input(*this), @@ -302,8 +304,10 @@ ewol::Context::Context(int32_t _argc, const char* _argv[]) : m_FpsFlush( "Flush ", false), m_windowsCurrent(nullptr), m_windowsSize(320,480), - m_initStepId(0), - m_initTotalStep(1) { + m_initStepId(0) { + if (m_application == nullptr) { + EWOL_CRITICAL("Can not start context with no Application ==> rtfm ..."); + } m_commandLine.parse(_argc, _argv); EWOL_INFO(" == > Ewol system init (BEGIN)"); // Add basic ewol translation: @@ -388,7 +392,8 @@ ewol::Context::~Context() { m_objectManager.removeAllRemovedObject(); } while (m_resourceManager.checkResourceToRemove() == true); // call application to uninit - APP_UnInit(*this); + m_application->unInit(*this); + m_application.reset(); // clean all messages m_msgSystem.clean(); // an other cycle of removing ... @@ -580,7 +585,7 @@ bool ewol::Context::OS_Draw(bool _displayEveryTime) { // set the curent interface : lockContext(); processEvents(); - if (m_initStepId < m_initTotalStep) { + if (m_initStepId < m_application->getNbStepInit()) { ewol::eSystemMessage *data = new ewol::eSystemMessage(); if (data == nullptr) { EWOL_ERROR("allocation error of message"); diff --git a/sources/ewol/context/Context.h b/sources/ewol/context/Context.h index d23908e5..3abd3de1 100644 --- a/sources/ewol/context/Context.h +++ b/sources/ewol/context/Context.h @@ -17,12 +17,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include namespace ewol { /** @@ -39,6 +41,12 @@ namespace ewol { }; class Context/* : private ewol::object::RemoveEvent */{ + private: + std::shared_ptr m_application; //!< Application handle + public: + std::shared_ptr getApplication() { + return m_application; + } private: ewol::context::CommandLine m_commandLine; //!< Start command line information public: @@ -70,7 +78,7 @@ namespace ewol { return m_resourceManager; }; public: - Context(int32_t _argc=0, const char* _argv[]=nullptr); + Context(ewol::context::Application* _application, int32_t _argc=0, const char* _argv[]=nullptr); virtual ~Context(); protected: /** @@ -363,21 +371,5 @@ namespace ewol { Context& getContext(); }; -//!< must be define in CPP by the application ... this are the main init and unInit of the Application -/** - * @brief main application function initialisation - * @param[in] _context curent context property - * @param[in] _initId current init step - * @param[out] _nbInitStep total number of step - * @return true, all OK - * @return false, an error occured - */ -bool APP_Init(ewol::Context& _context, size_t _initId, size_t& _nbInitStep); -/** - * @brief main application function un-initialisation - */ -void APP_UnInit(ewol::Context& _context); - - #endif diff --git a/sources/ewol/context/X11/Context.cpp b/sources/ewol/context/X11/Context.cpp index 8b50d314..bf926d37 100644 --- a/sources/ewol/context/X11/Context.cpp +++ b/sources/ewol/context/X11/Context.cpp @@ -142,8 +142,8 @@ class X11Interface : public ewol::Context { enum ewol::context::cursorDisplay m_currentCursor; //!< select the current cursor to display : char32_t m_lastKeyPressed; //!< The last element key presed... public: - X11Interface(int32_t _argc, const char* _argv[]) : - ewol::Context(_argc, _argv), + X11Interface(ewol::context::Application* _application, int32_t _argc, const char* _argv[]) : + ewol::Context(_application, _argc, _argv), m_display(nullptr), m_originX(0), m_originY(0), @@ -1343,9 +1343,9 @@ class X11Interface : public ewol::Context { * @param std IO * @return std IO */ -int ewol::run(int _argc, const char *_argv[]) { +int ewol::run(ewol::context::Application* _application, int _argc, const char *_argv[]) { etk::setArgZero(_argv[0]); - X11Interface* interface = new X11Interface(_argc, _argv); + X11Interface* interface = new X11Interface(_application, _argc, _argv); if (nullptr == interface) { EWOL_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); return -2; diff --git a/sources/ewol/ewol.h b/sources/ewol/ewol.h index fc3acc2a..438f4549 100644 --- a/sources/ewol/ewol.h +++ b/sources/ewol/ewol.h @@ -10,7 +10,7 @@ #define __EWOL_H__ #include -#include +#include namespace ewol { /** @@ -20,11 +20,12 @@ namespace ewol { * Does not exist in the android platform, then ewol call other start * and stop function, to permit to have only one code * @note The main can not be in the ewol, due to the fact thet is an librairy + * @param[in] _application just created instance of the applicationo * @param[in] _argc Standard argc * @param[in] _argv Standard argv * @return normal error int for the application error management */ - int32_t run(int32_t _argc, const char* _argv[]); + int32_t run(ewol::context::Application* _application, int32_t _argc = 0, const char* _argv[] = NULL); /** * @brief get EWOL version * @return The string that describe ewol version diff --git a/sources/ewol/widget/Windows.h b/sources/ewol/widget/Windows.h index e176a404..295f2887 100644 --- a/sources/ewol/widget/Windows.h +++ b/sources/ewol/widget/Windows.h @@ -19,7 +19,7 @@ namespace ewol { namespace widget { /** - * @ingroup ewolWidgetGroup + * @brief Windows basic interface */ class Windows : public ewol::Widget { protected: