Partial clean-up.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31896 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström
2009-07-29 08:39:38 +00:00
parent 568b1f0baf
commit 3f4b183da1
4 changed files with 340 additions and 312 deletions
+208 -160
View File
@@ -1,72 +1,79 @@
// license: public domain // license: public domain
// authors: jonas.sundstrom@kirilla.com // authors: Jonas Sundström, jonas@kirilla.com
#include "GenericThread.h" #include "GenericThread.h"
#include <string.h> #include <string.h>
GenericThread::GenericThread(const char * a_thread_name, int32 a_priority, BMessage * a_message)
GenericThread::GenericThread(const char* thread_name, int32 priority,
BMessage* message)
: :
m_thread_data_store (a_message), fThreadDataStore(message),
m_thread_id (spawn_thread (private_thread_function, a_thread_name, a_priority, this)), fThreadId(spawn_thread (_ThreadFunction, thread_name, priority, this)),
m_execute_unit (create_sem(1, "m_execute_unit")), fExecuteUnitSem(create_sem(1, "fExecuteUnitSem")),
m_quit_requested (false), fQuitRequested(false),
m_thread_is_paused (false) fThreadIsPaused(false)
{ {
if (m_thread_data_store == NULL) if (fThreadDataStore == NULL)
m_thread_data_store = new BMessage(); fThreadDataStore = new BMessage();
} }
GenericThread::~GenericThread() GenericThread::~GenericThread()
{ {
kill_thread(m_thread_id); kill_thread(fThreadId);
delete_sem(m_execute_unit); delete_sem(fExecuteUnitSem);
} }
status_t status_t
GenericThread::ThreadFunction (void) GenericThread::ThreadFunction()
{ {
status_t status = B_OK; status_t status = B_OK;
status = ThreadStartup(); // Subclass and override this function status = ThreadStartup();
if (status != B_OK) // Subclass and override this function
{
ThreadStartupFailed (status); if (status != B_OK) {
return (status); ThreadStartupFailed(status);
return status;
// is this the right thing to do? // is this the right thing to do?
} }
while(1) while (1) {
{ if (HasQuitBeenRequested()) {
if (HasQuitBeenRequested()) status = ThreadShutdown();
{ // Subclass and override this function
status = ThreadShutdown(); // Subclass and override this function
if (status != B_OK) if (status != B_OK) {
{ ThreadShutdownFailed(status);
ThreadShutdownFailed (status); return status;
return (status);
// what do we do?
} }
delete this; // destructor delete this;
} }
BeginUnit(); BeginUnit();
status = ExecuteUnit(); // Subclass and override status = ExecuteUnit();
// Subclass and override
if (status != B_OK) if (status != B_OK)
ExecuteUnitFailed (status); // Subclass and override ExecuteUnitFailed (status);
// Subclass and override
EndUnit(); EndUnit();
} }
return (B_OK); return B_OK;
} }
status_t status_t
GenericThread::ThreadStartup (void) GenericThread::ThreadStartup()
{ {
// This function is virtual. // This function is virtual.
// Subclass and override this function. // Subclass and override this function.
@@ -76,7 +83,7 @@ GenericThread::ThreadStartup (void)
status_t status_t
GenericThread::ExecuteUnit (void) GenericThread::ExecuteUnit()
{ {
// This function is virtual. // This function is virtual.
@@ -87,8 +94,9 @@ GenericThread::ExecuteUnit (void)
return B_OK; return B_OK;
} }
status_t status_t
GenericThread::ThreadShutdown (void) GenericThread::ThreadShutdown()
{ {
// This function is virtual. // This function is virtual.
// Subclass and override this function. // Subclass and override this function.
@@ -96,8 +104,9 @@ GenericThread::ThreadShutdown (void)
return B_OK; return B_OK;
} }
void void
GenericThread::ThreadStartupFailed (status_t a_status) GenericThread::ThreadStartupFailed(status_t status)
{ {
// This function is virtual. // This function is virtual.
// Subclass and override this function. // Subclass and override this function.
@@ -105,8 +114,9 @@ GenericThread::ThreadStartupFailed (status_t a_status)
Quit(); Quit();
} }
void void
GenericThread::ExecuteUnitFailed (status_t a_status) GenericThread::ExecuteUnitFailed(status_t status)
{ {
// This function is virtual. // This function is virtual.
// Subclass and override this function. // Subclass and override this function.
@@ -114,8 +124,9 @@ GenericThread::ExecuteUnitFailed (status_t a_status)
Quit(); Quit();
} }
void void
GenericThread::ThreadShutdownFailed (status_t a_status) GenericThread::ThreadShutdownFailed(status_t status)
{ {
// This function is virtual. // This function is virtual.
// Subclass and override this function. // Subclass and override this function.
@@ -123,266 +134,303 @@ GenericThread::ThreadShutdownFailed (status_t a_status)
// (is this good default behaviour?) // (is this good default behaviour?)
} }
status_t status_t
GenericThread::Start (void) GenericThread::Start()
{ {
status_t status = B_OK; status_t status = B_OK;
if (IsPaused()) if (IsPaused()) {
{ status = release_sem(fExecuteUnitSem);
status = release_sem (m_execute_unit);
if (status != B_OK) if (status != B_OK)
return status; return status;
m_thread_is_paused = false; fThreadIsPaused = false;
} }
status = resume_thread (m_thread_id); status = resume_thread(fThreadId);
return status; return status;
} }
int32 int32
GenericThread::private_thread_function (void * a_simple_thread_ptr) GenericThread::_ThreadFunction(void* simple_thread_ptr)
{ {
status_t status = B_OK; status_t status = B_OK;
status = ((GenericThread *) a_simple_thread_ptr)-> ThreadFunction(); status = ((GenericThread*) simple_thread_ptr)->ThreadFunction();
return (status); return status;
} }
BMessage *
GenericThread::GetDataStore (void) BMessage*
GenericThread::GetDataStore()
{ {
return (m_thread_data_store); return fThreadDataStore;
} }
void void
GenericThread::SetDataStore (BMessage * a_message) GenericThread::SetDataStore(BMessage* message)
{ {
m_thread_data_store = a_message; fThreadDataStore = message;
} }
status_t status_t
GenericThread::Pause (bool a_do_block, bigtime_t a_timeout) GenericThread::Pause(bool doBlock, bigtime_t timeout)
{ {
status_t status = B_OK; status_t status = B_OK;
if (a_do_block) if (doBlock)
status = acquire_sem(m_execute_unit); status = acquire_sem(fExecuteUnitSem);
// thread will wait on semaphore // thread will wait on semaphore
else else
status = acquire_sem_etc(m_execute_unit, 1, B_RELATIVE_TIMEOUT, a_timeout); status = acquire_sem_etc(fExecuteUnitSem, 1, B_RELATIVE_TIMEOUT,
timeout);
// thread will timeout // thread will timeout
if (status == B_OK) if (status == B_OK) {
{ fThreadIsPaused = true;
m_thread_is_paused = true; return B_OK;
return (B_OK);
} }
return status; return status;
} }
void void
GenericThread::Quit (void) GenericThread::Quit()
{ {
m_quit_requested = true; fQuitRequested = true;
} }
bool bool
GenericThread::HasQuitBeenRequested (void) GenericThread::HasQuitBeenRequested()
{ {
return (m_quit_requested); return fQuitRequested;
} }
bool bool
GenericThread::IsPaused (void) GenericThread::IsPaused()
{ {
return (m_thread_is_paused); return fThreadIsPaused;
} }
status_t
GenericThread::Suspend (void)
{
return (suspend_thread(m_thread_id));
}
status_t status_t
GenericThread::Resume (void) GenericThread::Suspend()
{ {
release_sem(m_execute_unit); // to counteract Pause() return suspend_thread(fThreadId);
m_thread_is_paused = false; }
status_t
GenericThread::Resume()
{
release_sem(fExecuteUnitSem);
// to counteract Pause()
fThreadIsPaused = false;
return (resume_thread(m_thread_id)); // to counteract Suspend() return resume_thread(fThreadId);
// to counteract Suspend()
} }
status_t status_t
GenericThread::Kill (void) GenericThread::Kill()
{ {
return (kill_thread(m_thread_id)); return kill_thread(fThreadId);
} }
void void
GenericThread::ExitWithReturnValue (status_t a_return_value) GenericThread::ExitWithReturnValue(status_t return_value)
{ {
exit_thread(a_return_value); exit_thread(return_value);
} }
status_t
GenericThread::SetExitCallback (void (*a_callback)(void*), void * a_data)
{
return (on_exit_thread(a_callback, a_data));
}
status_t status_t
GenericThread::WaitForThread (status_t * a_exit_value) GenericThread::SetExitCallback(void (*callback)(void*), void* data)
{ {
return (wait_for_thread(m_thread_id, a_exit_value)); return on_exit_thread(callback, data);
} }
status_t
GenericThread::Rename (char * a_name)
{
return (rename_thread(m_thread_id, a_name));
}
status_t status_t
GenericThread::SendData (int32 a_code, void * a_buffer, size_t a_buffer_size) GenericThread::WaitForThread(status_t* exitValue)
{ {
return (send_data(m_thread_id, a_code, a_buffer, a_buffer_size)); return wait_for_thread(fThreadId, exitValue);
} }
status_t
GenericThread::Rename(char* name)
{
return rename_thread(fThreadId, name);
}
status_t
GenericThread::SendData(int32 code, void* buffer, size_t buffer_size)
{
return send_data(fThreadId, code, buffer, buffer_size);
}
int32 int32
GenericThread::ReceiveData (thread_id * a_sender, void * a_buffer, size_t a_buffer_size) GenericThread::ReceiveData(thread_id* sender, void* buffer, size_t buffer_size)
{ {
return (receive_data(a_sender, a_buffer, a_buffer_size)); return receive_data(sender, buffer, buffer_size);
} }
bool bool
GenericThread::HasData (void) GenericThread::HasData()
{ {
return (has_data(m_thread_id)); return has_data(fThreadId);
}
status_t
GenericThread::SetPriority (int32 a_new_priority)
{
return (set_thread_priority(m_thread_id, a_new_priority));
} }
status_t
GenericThread::SetPriority(int32 newPriority)
{
return set_thread_priority(fThreadId, newPriority);
}
void void
GenericThread::Snooze (bigtime_t a_microseconds) GenericThread::Snooze(bigtime_t microseconds)
{ {
Suspend(); Suspend();
snooze(a_microseconds); snooze(microseconds);
Resume(); Resume();
} }
void void
GenericThread::SnoozeUntil (bigtime_t a_microseconds, int a_timebase) GenericThread::SnoozeUntil(bigtime_t microseconds, int timebase)
{ {
Suspend(); Suspend();
snooze_until(a_microseconds, a_timebase); snooze_until(microseconds, timebase);
Resume(); Resume();
} }
status_t status_t
GenericThread::GetInfo (thread_info * a_thread_info) GenericThread::GetInfo(thread_info* threadInfo)
{ {
return (get_thread_info(m_thread_id, a_thread_info)); return get_thread_info(fThreadId, threadInfo);
} }
thread_id thread_id
GenericThread::GetThread (void) GenericThread::GetThread()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.thread); return threadInfo.thread;
} }
team_id team_id
GenericThread::GetTeam (void) GenericThread::GetTeam()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.team); return threadInfo.team;
} }
char *
GenericThread::GetName (void) char*
GenericThread::GetName()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return strdup(t_thread_info.name); return strdup(threadInfo.name);
} }
thread_state thread_state
GenericThread::GetState (void) GenericThread::GetState()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.state); return threadInfo.state;
} }
sem_id sem_id
GenericThread::GetSemaphore (void) GenericThread::GetSemaphore()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.sem); return threadInfo.sem;
} }
int32 int32
GenericThread::GetPriority (void) GenericThread::GetPriority()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.priority); return threadInfo.priority;
} }
bigtime_t bigtime_t
GenericThread::GetUserTime (void) GenericThread::GetUserTime()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.user_time); return threadInfo.user_time;
} }
bigtime_t bigtime_t
GenericThread::GetKernelTime (void) GenericThread::GetKernelTime()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.kernel_time); return threadInfo.kernel_time;
} }
void *
GenericThread::GetStackBase (void) void*
GenericThread::GetStackBase()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.stack_base); return threadInfo.stack_base;
} }
void *
GenericThread::GetStackEnd (void) void*
GenericThread::GetStackEnd()
{ {
thread_info t_thread_info; thread_info threadInfo;
GetInfo (& t_thread_info); GetInfo(&threadInfo);
return (t_thread_info.stack_end); return threadInfo.stack_end;
} }
void void
GenericThread::BeginUnit (void) GenericThread::BeginUnit()
{ {
acquire_sem(m_execute_unit); // thread can not be paused until it releases semaphore acquire_sem(fExecuteUnitSem);
// thread can not be paused until it releases semaphore
} }
void void
GenericThread::EndUnit (void) GenericThread::EndUnit()
{ {
release_sem(m_execute_unit); // thread can now be paused release_sem(fExecuteUnitSem);
// thread can now be paused
} }
+67 -63
View File
@@ -1,83 +1,87 @@
#ifndef __GENERIC_THREAD_H__ #ifndef __GENERIC_THREAD_H__
#define __GENERIC_THREAD_H__ #define __GENERIC_THREAD_H__
#include <OS.h>
#include <Message.h> #include <Message.h>
class GenericThread class GenericThread
{ {
public: public:
GenericThread (const char * a_thread_name = "generic_thread", int32 a_priority = B_NORMAL_PRIORITY, BMessage * a_message = NULL); GenericThread(const char*
virtual ~GenericThread (void); thread_name = "generic_thread",
int32 priority = B_NORMAL_PRIORITY,
BMessage* message = NULL);
virtual ~GenericThread();
BMessage * GetDataStore (void); BMessage* GetDataStore();
void SetDataStore (BMessage * a_message); void SetDataStore(BMessage* message);
status_t Start (void); status_t Start();
status_t Pause (bool a_do_block = TRUE, bigtime_t a_timeout = 0); status_t Pause(bool doBlock = TRUE, bigtime_t timeout = 0);
void Quit (void); void Quit();
bool IsPaused (void); bool IsPaused();
bool HasQuitBeenRequested (void); bool HasQuitBeenRequested();
status_t Suspend (void);
status_t Resume (void);
status_t Kill (void);
void ExitWithReturnValue (status_t a_return_value);
status_t SetExitCallback (void (* a_callback)(void *), void * a_data);
status_t WaitForThread (status_t * a_exit_value);
status_t Rename (char * a_name);
status_t SendData (int32 a_code, void * a_buffer, size_t a_buffer_size);
int32 ReceiveData (thread_id * a_sender, void * a_buffer, size_t a_buffer_size);
bool HasData (void);
status_t SetPriority (int32 a_new_priority); status_t Suspend();
status_t Resume();
status_t Kill();
void ExitWithReturnValue(status_t returnValue);
status_t SetExitCallback(void (* callback)(void*),
void* data);
status_t WaitForThread(status_t* exitValue);
status_t Rename(char* name);
status_t SendData(int32 code, void* buffer,
size_t bufferSize);
int32 ReceiveData(thread_id* sender, void* buffer,
size_t bufferSize);
bool HasData();
status_t SetPriority(int32 newPriority);
void Snooze (bigtime_t a_microseconds); void Snooze(bigtime_t microseconds);
void SnoozeUntil (bigtime_t a_microseconds, int a_timebase = B_SYSTEM_TIMEBASE); void SnoozeUntil(bigtime_t microseconds,
int timebase = B_SYSTEM_TIMEBASE);
status_t GetInfo (thread_info * a_thread_info); status_t GetInfo(thread_info* threadInfo);
thread_id GetThread (void); thread_id GetThread();
team_id GetTeam (void); team_id GetTeam();
char * GetName (void); char* GetName();
thread_state GetState (void); thread_state GetState();
sem_id GetSemaphore (void); sem_id GetSemaphore();
int32 GetPriority (void); int32 GetPriority();
bigtime_t GetUserTime (void); bigtime_t GetUserTime();
bigtime_t GetKernelTime (void); bigtime_t GetKernelTime();
void * GetStackBase (void); void* GetStackBase();
void * GetStackEnd (void); void* GetStackEnd();
protected: protected:
virtual status_t ThreadFunction();
virtual status_t ThreadStartup();
virtual status_t ExecuteUnit();
virtual status_t ThreadShutdown();
virtual void ThreadStartupFailed(status_t status);
virtual void ExecuteUnitFailed(status_t status);
virtual void ThreadShutdownFailed(status_t status);
virtual status_t ThreadFunction (void); void BeginUnit();
virtual status_t ThreadStartup (void); void EndUnit();
virtual status_t ExecuteUnit (void);
virtual status_t ThreadShutdown (void);
virtual void ThreadStartupFailed (status_t a_status);
virtual void ExecuteUnitFailed (status_t a_status);
virtual void ThreadShutdownFailed (status_t a_status);
void BeginUnit (void); // acquire m_execute_cycle BMessage* fThreadDataStore;
void EndUnit (void); // release m_execute_cycle
BMessage * m_thread_data_store;
private: private:
static status_t _ThreadFunction(void* simpleThreadPtr);
static status_t private_thread_function (void * a_simple_thread_ptr);
thread_id m_thread_id; thread_id fThreadId;
sem_id fExecuteUnitSem;
sem_id m_execute_unit; // acq./relase within tread_function.. For Pause() bool fQuitRequested;
bool fThreadIsPaused;
bool m_quit_requested;
bool m_thread_is_paused;
}; };
#endif #endif // __GENERIC_THREAD_H__
+29 -54
View File
@@ -1,42 +1,39 @@
/* /*
* Copyright 2003-2006, Haiku, Inc. All Rights Reserved. * Copyright 2003-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Jonas Sundström, jonas.sundstrom@kirilla.com * Jonas Sundström, [email protected]
* Peter Folk <[email protected]>
*/ */
#include "ZipperThread.h" #include "ZipperThread.h"
#include "ZipOMaticWindow.h"
#include "ZipOMaticMisc.h"
#include <Debug.h> #include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Message.h> #include <Message.h>
#include <Path.h> #include <Path.h>
#include <Volume.h> #include <Volume.h>
#include <signal.h> #include "ZipOMaticMisc.h"
#include <unistd.h> #include "ZipOMaticWindow.h"
#include <errno.h>
const char* kZipperThreadName = "ZipperThread";
ZipperThread::ZipperThread (BMessage* refsMessage, BWindow* window) ZipperThread::ZipperThread (BMessage* refsMessage, BWindow* window)
: GenericThread(kZipperThreadName, B_NORMAL_PRIORITY, refsMessage), :
GenericThread("ZipperThread", B_NORMAL_PRIORITY, refsMessage),
fWindowMessenger(window), fWindowMessenger(window),
fZipProcess(-1), fZipProcess(-1),
m_std_in(-1), fStdIn(-1),
m_std_out(-1), fStdOut(-1),
m_std_err(-1), fStdErr(-1),
fOutputFile(NULL) fOutputFile(NULL)
{ {
PRINT(("ZipperThread()\n")); fThreadDataStore = new BMessage(*refsMessage);
m_thread_data_store = new BMessage(*refsMessage);
// leak? // leak?
// prevents bug with B_SIMPLE_DATA // prevents bug with B_SIMPLE_DATA
// (drag&drop messages) // (drag&drop messages)
@@ -51,8 +48,6 @@ ZipperThread::~ZipperThread()
status_t status_t
ZipperThread::ThreadStartup() ZipperThread::ThreadStartup()
{ {
PRINT(("ZipperThread::ThreadStartup()\n"));
BString archiveName = "Archive.zip"; BString archiveName = "Archive.zip";
// do all refs have the same parent dir? // do all refs have the same parent dir?
@@ -62,12 +57,12 @@ ZipperThread::ThreadStartup()
entry_ref lastRef; entry_ref lastRef;
bool sameFolder = true; bool sameFolder = true;
status_t status = m_thread_data_store->GetInfo("refs", &type, &refCount); status_t status = fThreadDataStore->GetInfo("refs", &type, &refCount);
if (status != B_OK) if (status != B_OK)
return status; return status;
for (int index = 0; index < refCount; index++) { for (int index = 0; index < refCount; index++) {
m_thread_data_store->FindRef("refs", index, &ref); fThreadDataStore->FindRef("refs", index, &ref);
if (index > 0) { if (index > 0) {
BEntry entry(&ref); BEntry entry(&ref);
@@ -114,8 +109,8 @@ ZipperThread::ThreadStartup()
argv[2] = strdup(archiveName.String()); argv[2] = strdup(archiveName.String());
// files to zip // files to zip
for (int index = 0; index < refCount ; index++) { for (int index = 0; index < refCount; index++) {
m_thread_data_store->FindRef("refs", index, &ref); fThreadDataStore->FindRef("refs", index, &ref);
if (sameFolder) { if (sameFolder) {
// just the file name // just the file name
@@ -130,7 +125,7 @@ ZipperThread::ThreadStartup()
argv[argc] = NULL; argv[argc] = NULL;
fZipProcess = _PipeCommand(argc, argv, m_std_in, m_std_out, m_std_err); fZipProcess = _PipeCommand(argc, argv, fStdIn, fStdOut, fStdErr);
delete [] argv; delete [] argv;
@@ -139,7 +134,7 @@ ZipperThread::ThreadStartup()
resume_thread(fZipProcess); resume_thread(fZipProcess);
fOutputFile = fdopen(m_std_out, "r"); fOutputFile = fdopen(fStdOut, "r");
if (fOutputFile == NULL) if (fOutputFile == NULL)
return errno; return errno;
@@ -148,8 +143,6 @@ ZipperThread::ThreadStartup()
_SendMessageToWindow('strt', "archive_filename", archiveName.String()); _SendMessageToWindow('strt', "archive_filename", archiveName.String());
_SendMessageToWindow('outp', "zip_output", "Preparing to archive"); _SendMessageToWindow('outp', "zip_output", "Preparing to archive");
PRINT(("\n"));
return B_OK; return B_OK;
} }
@@ -157,8 +150,6 @@ ZipperThread::ThreadStartup()
status_t status_t
ZipperThread::ExecuteUnit() ZipperThread::ExecuteUnit()
{ {
//PRINT(("ZipperThread::ExecuteUnit()\n"));
// read output from /bin/zip // read output from /bin/zip
// send it to window // send it to window
char buffer[4096]; char buffer[4096];
@@ -188,11 +179,9 @@ ZipperThread::ExecuteUnit()
status_t status_t
ZipperThread::ThreadShutdown() ZipperThread::ThreadShutdown()
{ {
PRINT(("ZipperThread::ThreadShutdown()\n")); close(fStdIn);
close(fStdOut);
close(m_std_in); close(fStdErr);
close(m_std_out);
close(m_std_err);
return B_OK; return B_OK;
} }
@@ -239,13 +228,6 @@ ZipperThread::_MakeShellSafe(BString* string)
} }
status_t
ZipperThread::ProcessRefs(BMessage* msg)
{
return B_OK;
}
thread_id thread_id
ZipperThread::_PipeCommand(int argc, const char** argv, int& in, int& out, ZipperThread::_PipeCommand(int argc, const char** argv, int& in, int& out,
int& err, const char** envp) int& err, const char** envp)
@@ -288,10 +270,9 @@ ZipperThread::_PipeCommand(int argc, const char** argv, int& in, int& out,
// execute command // execute command
thread = load_image(argc, argv, envp); thread = load_image(argc, argv, envp);
} else {
PRINT(("load_image() thread_id: %ld\n", ret));
} else
thread = errno; thread = errno;
}
// Restore old FDs // Restore old FDs
dup2(oldIn, STDIN_FILENO); dup2(oldIn, STDIN_FILENO);
@@ -317,7 +298,8 @@ err1:
void void
ZipperThread::_SendMessageToWindow(uint32 what, const char* name, const char* value) ZipperThread::_SendMessageToWindow(uint32 what, const char* name,
const char* value)
{ {
BMessage msg(what); BMessage msg(what);
if (name != NULL && value != NULL) if (name != NULL && value != NULL)
@@ -330,8 +312,6 @@ ZipperThread::_SendMessageToWindow(uint32 what, const char* name, const char* va
status_t status_t
ZipperThread::SuspendExternalZip() ZipperThread::SuspendExternalZip()
{ {
PRINT(("ZipperThread::SuspendExternalZip()\n"));
thread_info info; thread_info info;
status_t status = get_thread_info(fZipProcess, &info); status_t status = get_thread_info(fZipProcess, &info);
@@ -345,8 +325,6 @@ ZipperThread::SuspendExternalZip()
status_t status_t
ZipperThread::ResumeExternalZip() ZipperThread::ResumeExternalZip()
{ {
PRINT(("ZipperThread::ResumeExternalZip()\n"));
thread_info info; thread_info info;
status_t status = get_thread_info(fZipProcess, &info); status_t status = get_thread_info(fZipProcess, &info);
@@ -360,8 +338,6 @@ ZipperThread::ResumeExternalZip()
status_t status_t
ZipperThread::InterruptExternalZip() ZipperThread::InterruptExternalZip()
{ {
PRINT(("ZipperThread::InterruptExternalZip()\n"));
thread_info info; thread_info info;
status_t status = get_thread_info(fZipProcess, &info); status_t status = get_thread_info(fZipProcess, &info);
@@ -379,8 +355,6 @@ ZipperThread::InterruptExternalZip()
status_t status_t
ZipperThread::WaitOnExternalZip() ZipperThread::WaitOnExternalZip()
{ {
PRINT(("ZipperThread::WaitOnExternalZip()\n"));
thread_info info; thread_info info;
status_t status = get_thread_info(fZipProcess, &info); status_t status = get_thread_info(fZipProcess, &info);
@@ -389,3 +363,4 @@ ZipperThread::WaitOnExternalZip()
return status; return status;
} }
+36 -35
View File
@@ -1,60 +1,61 @@
/* /*
* Copyright 2003-2006, Haiku, Inc. All Rights Reserved. * Copyright 2003-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Jonas Sundström, jonas.sundstrom@kirilla.com * Jonas Sundström, [email protected]
*/ */
#ifndef ZIPPER_THREAD_H #ifndef _ZIPPER_THREAD_H
#define ZIPPER_THREAD_H #define _ZIPPER_THREAD_H
#include "GenericThread.h"
#include <Messenger.h>
#include <stdio.h> #include <stdio.h>
class BMessage; #include <Message.h>
class BWindow; #include <Messenger.h>
#include <Window.h>
#include "GenericThread.h"
class ZipperThread : public GenericThread { class ZipperThread : public GenericThread {
public: public:
ZipperThread(BMessage* refsMessage, BWindow* window); ZipperThread(BMessage* refsMessage,
BWindow* window);
~ZipperThread(); ~ZipperThread();
status_t SuspendExternalZip(); status_t SuspendExternalZip();
status_t ResumeExternalZip(); status_t ResumeExternalZip();
status_t InterruptExternalZip(); status_t InterruptExternalZip();
status_t WaitOnExternalZip(); status_t WaitOnExternalZip();
private: protected:
virtual status_t ThreadStartup(); virtual status_t ThreadStartup();
virtual status_t ExecuteUnit(); virtual status_t ExecuteUnit();
virtual status_t ThreadShutdown(); virtual status_t ThreadShutdown();
virtual void ThreadStartupFailed(status_t a_status); virtual void ThreadStartupFailed(status_t status);
virtual void ExecuteUnitFailed(status_t a_status); virtual void ExecuteUnitFailed(status_t status);
virtual void ThreadShutdownFailed(status_t a_status); virtual void ThreadShutdownFailed(status_t status);
status_t ProcessRefs(BMessage* msg); private:
void _MakeShellSafe(BString* string); void _MakeShellSafe(BString* string);
thread_id _PipeCommand(int argc, const char** argv, thread_id _PipeCommand(int argc, const char** argv,
int& in, int& out, int& err, int& in, int& out, int& err,
const char** envp = (const char**)environ); const char** envp = (const char**)environ);
void _SendMessageToWindow(uint32 what, void _SendMessageToWindow(uint32 what,
const char* name = NULL, const char* value = NULL); const char* name = NULL,
const char* value = NULL);
BMessenger fWindowMessenger; BMessenger fWindowMessenger;
thread_id fZipProcess; thread_id fZipProcess;
int m_std_in; int fStdIn;
int m_std_out; int fStdOut;
int m_std_err; int fStdErr;
FILE* fOutputFile; FILE* fOutputFile;
}; };
#endif // ZIPPER_THREAD_H #endif // _ZIPPER_THREAD_H