1/*
2 * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _KERNEL_USER_EVENT_H
7#define _KERNEL_USER_EVENT_H
8
9
10#include <signal.h>
11
12#include <SupportDefs.h>
13
14#include <DPC.h>
15#include <thread.h>
16
17
18namespace BKernel {
19
20
21struct Team;
22struct Thread;
23
24
25struct UserEvent : public BReferenceable {
26	virtual						~UserEvent();
27
28	virtual	status_t			Fire() = 0;
29};
30
31
32struct SignalEvent : UserEvent, private DPCCallback {
33	virtual						~SignalEvent();
34
35			void				SetUserValue(union sigval userValue);
36
37	virtual	status_t			Fire();
38
39protected:
40			struct EventSignal;
41
42protected:
43								SignalEvent(EventSignal* signal);
44
45protected:
46			EventSignal*		fSignal;
47			int32				fPendingDPC;
48};
49
50
51struct TeamSignalEvent : SignalEvent {
52	static	TeamSignalEvent*	Create(Team* team, uint32 signalNumber,
53									int32 signalCode, int32 errorCode);
54
55	virtual	status_t			Fire();
56
57protected:
58	virtual	void				DoDPC(DPCQueue* queue);
59
60private:
61								TeamSignalEvent(Team* team,
62									EventSignal* signal);
63
64private:
65			Team*				fTeam;
66};
67
68
69struct ThreadSignalEvent : SignalEvent {
70	static	ThreadSignalEvent*	Create(Thread* thread, uint32 signalNumber,
71									int32 signalCode, int32 errorCode,
72									pid_t sendingTeam);
73
74	virtual	status_t			Fire();
75
76protected:
77	virtual	void				DoDPC(DPCQueue* queue);
78
79private:
80								ThreadSignalEvent(Thread* thread,
81									EventSignal* signal);
82
83private:
84			Thread*				fThread;
85};
86
87
88struct CreateThreadEvent : UserEvent, private DPCCallback {
89	static	CreateThreadEvent*	Create(
90									const ThreadCreationAttributes& attributes);
91
92	virtual	status_t			Fire();
93
94private:
95								CreateThreadEvent(
96									const ThreadCreationAttributes& attributes);
97
98	virtual	void				DoDPC(DPCQueue* queue);
99
100private:
101			ThreadCreationAttributes fCreationAttributes;
102			char				fThreadName[B_OS_NAME_LENGTH];
103			int32				fPendingDPC;
104};
105
106
107}	// namespace BKernel
108
109
110using BKernel::CreateThreadEvent;
111using BKernel::SignalEvent;
112using BKernel::TeamSignalEvent;
113using BKernel::ThreadSignalEvent;
114using BKernel::UserEvent;
115
116
117#endif	// _KERNEL_USER_EVENT_H
118