nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "Nux.h" 00024 00025 #include "Layout.h" 00026 #if defined(NUX_OS_WINDOWS) 00027 #include "NuxGraphics/GraphicsDisplay.h" 00028 #elif defined(NUX_OS_LINUX) 00029 #include "NuxGraphics/GraphicsDisplay.h" 00030 #endif 00031 #include "NuxGraphics/GraphicsEngine.h" 00032 #include "ClientArea.h" 00033 #include "WindowCompositor.h" 00034 #include "TimerProc.h" 00035 #include "WindowCompositor.h" 00036 #include "WindowThread.h" 00037 #include "SystemThread.h" 00038 00039 namespace nux 00040 { 00041 00042 NUX_IMPLEMENT_OBJECT_TYPE (SystemThread); 00043 00044 00045 SystemThread::SystemThread (AbstractThread *Parent/* = 0*/) 00046 : AbstractThread (Parent) 00047 { 00048 00049 } 00050 00051 SystemThread::~SystemThread() 00052 { 00053 } 00054 00055 ThreadState SystemThread::Start (void *arg) 00056 { 00057 if (!m_Parent) 00058 { 00059 return NThread::Start(); 00060 } 00061 else 00062 { 00063 if (m_Parent->Type().IsObjectType (SystemThread::StaticObjectType) ) 00064 return static_cast<SystemThread *> (m_Parent)->StartChildThread (this, true); 00065 00066 if (m_Parent->Type().IsObjectType (WindowThread::StaticObjectType) ) 00067 return static_cast<WindowThread *> (m_Parent)->StartChildThread (this, true); 00068 00069 nuxAssertMsg (0, TEXT ("[WindowThread::Start] This should not happen.") ); 00070 return THREAD_START_ERROR; 00071 } 00072 } 00073 00074 t_u32 SystemThread::Run (void *arg) 00075 { 00076 if (m_UserInitFunc) 00077 { 00078 (*m_UserInitFunc) (this, m_InitData); 00079 } 00080 00081 if (m_Parent) 00082 { 00083 if (m_Parent->Type().IsObjectType (SystemThread::StaticObjectType) ) 00084 static_cast<SystemThread *> (m_Parent)->ChildHasFinished (this); 00085 00086 if (m_Parent->Type().IsObjectType (WindowThread::StaticObjectType) ) 00087 static_cast<WindowThread *> (m_Parent)->ChildHasFinished (this); 00088 } 00089 00090 SetThreadState (THREADSTOP); 00091 TerminateAllChildThread(); 00092 return 0; 00093 } 00094 00095 ThreadState SystemThread::StartChildThread (NThread *thread, bool Modal) 00096 { 00097 ThreadState state = thread->NThread::Start(); 00098 //if(state == THREADRUNNING) 00099 AddChildThread (thread); 00100 return state; 00101 } 00102 00103 void SystemThread::AddChildThread (NThread *thread) 00104 { 00105 nuxAssert (thread); 00106 std::list<NThread *>::iterator it; 00107 it = find (m_ChildThread.begin(), m_ChildThread.end(), thread); 00108 00109 if (it == m_ChildThread.end() ) 00110 { 00111 m_ChildThread.push_back (thread); 00112 } 00113 } 00114 00115 void SystemThread::RemoveChildThread (NThread *window) 00116 { 00117 nuxAssert (window); 00118 std::list<NThread *>::iterator it; 00119 it = find (m_ChildThread.begin(), m_ChildThread.end(), window); 00120 00121 if (it != m_ChildThread.end() ) 00122 { 00123 m_ChildThread.erase (it); 00124 } 00125 } 00126 00127 void SystemThread::ChildHasFinished (NThread *thread) 00128 { 00129 RemoveChildThread (thread); 00130 00131 if (thread->Type().IsObjectType (WindowThread::StaticObjectType) ) 00132 { 00133 //SuspendChildGraphics(static_cast<WindowThread*>(thread)); 00134 } 00135 00136 thread->SetThreadState (THREADSTOP); 00137 } 00138 00139 void SystemThread::TerminateAllChildThread() 00140 { 00141 std::list<NThread *>::iterator it; 00142 00143 for (it = m_ChildThread.begin(); it != m_ChildThread.end(); it++) 00144 { 00145 (*it)->SetThreadState (THREADSTOP); 00146 } 00147 00148 m_ChildThread.clear(); 00149 } 00150 00151 bool SystemThread::ThreadCtor() 00152 { 00153 SetThreadState (THREADRUNNING); 00154 00155 return true; 00156 } 00157 00158 bool SystemThread::ThreadDtor() 00159 { 00160 return true; 00161 } 00162 00163 }