xref: /haiku/src/apps/debuganalyzer/model_loader/ModelLoader.h (revision b6b0567fbd186f8ce8a0c90bdc7a7b5b4c649678)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef MAIN_MODEL_LOADER_H
6 #define MAIN_MODEL_LOADER_H
7 
8 
9 #include "AbstractModelLoader.h"
10 #include "Model.h"
11 
12 
13 class BDataIO;
14 class BDebugEventInputStream;
15 class DataSource;
16 struct system_profiler_thread_added;
17 
18 
19 class ModelLoader : public AbstractModelLoader {
20 public:
21 								ModelLoader(DataSource* dataSource,
22 									const BMessenger& target,
23 									void* targetCookie);
24 
25 protected:
26 								~ModelLoader();
27 
28 public:
29 			Model*				DetachModel();
30 
31 protected:
32 	virtual	status_t			PrepareForLoading();
33 	virtual	status_t			Load();
34 	virtual	void				FinishLoading(bool success);
35 
36 private:
37 			// shorthands for the longish structure names
38 			typedef system_profiler_thread_enqueued_in_run_queue
39 				thread_enqueued_in_run_queue;
40 			typedef system_profiler_thread_removed_from_run_queue
41 				thread_removed_from_run_queue;
42 
43 private:
44 			status_t			_Load();
45 			status_t			_ReadDebugEvents(void** _eventData,
46 									size_t* _size);
47 			status_t			_ProcessEvent(uint32 event, uint32 cpu,
48 									const void* buffer, size_t size);
49 
50 	inline	void				_UpdateLastEventTime(bigtime_t time);
51 
52 			void				_HandleTeamAdded(
53 									system_profiler_team_added* event);
54 			void				_HandleTeamRemoved(
55 									system_profiler_team_removed* event);
56 			void				_HandleTeamExec(
57 									system_profiler_team_exec* event);
58 			void				_HandleThreadAdded(
59 									system_profiler_thread_added* event);
60 			void				_HandleThreadRemoved(
61 									system_profiler_thread_removed* event);
62 			void				_HandleThreadScheduled(
63 									system_profiler_thread_scheduled* event);
64 			void				_HandleThreadEnqueuedInRunQueue(
65 									thread_enqueued_in_run_queue* event);
66 			void				_HandleThreadRemovedFromRunQueue(
67 									thread_removed_from_run_queue* event);
68 			void				_HandleWaitObjectInfo(
69 									system_profiler_wait_object_info* event);
70 
71 			Model::ThreadSchedulingState* _AddThread(
72 									system_profiler_thread_added* event);
73 			void				_AddThreadWaitObject(Model::ThreadSchedulingState* thread,
74 									uint32 type, addr_t object);
75 
76 private:
77 			Model*				fModel;
78 			DataSource*			fDataSource;
79 			bigtime_t			fBaseTime;
80 			Model::SchedulingState fState;
81 };
82 
83 
84 #endif	// MAIN_MODEL_LOADER_H
85