xref: /haiku/src/add-ons/tracker/zipomatic/GenericThread.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 #ifndef __GENERIC_THREAD_H__
2 #define __GENERIC_THREAD_H__
3 
4 
5 #include <Message.h>
6 
7 
8 class GenericThread
9 {
10 public:
11 							GenericThread(const char*
12 								thread_name = "generic_thread",
13 								int32 priority = B_NORMAL_PRIORITY,
14 								BMessage* message = NULL);
15 	virtual					~GenericThread();
16 
17 			BMessage*		GetDataStore();
18 			void			SetDataStore(BMessage* message);
19 
20 			status_t		Start();
21 			status_t		Pause(bool doBlock = TRUE, bigtime_t timeout = 0);
22 			void			Quit();
23 			bool			IsPaused();
24 			bool			HasQuitBeenRequested();
25 
26 			status_t		Suspend();
27 			status_t		Resume();
28 			status_t		Kill();
29 
30 			void			ExitWithReturnValue(status_t returnValue);
31 			status_t		SetExitCallback(void (*callback)(void*),
32 								void* data);
33 			status_t		WaitForThread(status_t* exitValue);
34 
35 			status_t		Rename(char* name);
36 
37 			status_t		SendData(int32 code, void* buffer,
38 								size_t bufferSize);
39 			int32			ReceiveData(thread_id* sender, void* buffer,
40 								size_t bufferSize);
41 			bool			HasData();
42 
43 			status_t		SetPriority(int32 newPriority);
44 
45 			void			Snooze(bigtime_t microseconds);
46 			void			SnoozeUntil(bigtime_t microseconds,
47 								int timebase = B_SYSTEM_TIMEBASE);
48 
49 			status_t		GetInfo(thread_info* threadInfo);
50 			thread_id		GetThread();
51 			team_id			GetTeam();
52 			char*			GetName();
53 			thread_state	GetState();
54 			sem_id			GetSemaphore();
55 			int32			GetPriority();
56 			bigtime_t		GetUserTime();
57 			bigtime_t		GetKernelTime();
58 			void*			GetStackBase();
59 			void*			GetStackEnd();
60 
61 protected:
62 	virtual	status_t		ThreadFunction();
63 	virtual	status_t		ThreadStartup();
64 	virtual	status_t		ExecuteUnit();
65 	virtual	status_t		ThreadShutdown();
66 
67 	virtual	void			ThreadStartupFailed(status_t status);
68 	virtual	void			ExecuteUnitFailed(status_t status);
69 	virtual	void			ThreadShutdownFailed(status_t status);
70 
71 			void			BeginUnit();
72 			void			EndUnit();
73 
74 			BMessage*		fThreadDataStore;
75 
76 private:
77 	static	status_t		_ThreadFunction(void* simpleThreadPtr);
78 
79 			thread_id		fThreadId;
80 			sem_id			fExecuteUnitSem;
81 			bool			fQuitRequested;
82 			bool			fThreadIsPaused;
83 
84 };
85 
86 #endif	// __GENERIC_THREAD_H__
87 
88