xref: /haiku/src/apps/powerstatus/DriverInterface.h (revision 981f1b1135291a4fca290fbdf69910dc2f24abdd)
1 /*
2  * Copyright 2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Clemens Zeidler, haiku@Clemens-Zeidler.de
7  */
8 
9 #ifndef DRIVER_INTERFACE_H
10 #define DRIVER_INTERFACE_H
11 
12 #include <Locker.h>
13 #include <ObjectList.h>
14 #include <Handler.h>
15 
16 #include "device/power_managment.h"
17 
18 typedef BObjectList<BHandler> WatcherList;
19 
20 const uint32 kMsgUpdate = 'updt';
21 
22 
23 struct battery_info
24 {
25 	int8		state;
26 	int32		capacity;
27 	int32		full_capacity;
28 	time_t		time_left;
29 	int32		current_rate;
30 };
31 
32 
33 /*! Handle a list of watcher and broadcast a messages to them. */
34 class Monitor
35 {
36 public:
37 	virtual				~Monitor();
38 
39 	virtual status_t	StartWatching(BHandler* target);
40 	virtual status_t	StopWatching(BHandler* target);
41 
42 	virtual void		Broadcast(uint32 message);
43 
44 protected:
45 	WatcherList			fWatcherList;
46 
47 };
48 
49 
50 class PowerStatusDriverInterface : public Monitor
51 {
52 public:
53 						PowerStatusDriverInterface();
54 						~PowerStatusDriverInterface();
55 	virtual status_t	StartWatching(BHandler* target);
56 	virtual status_t	StopWatching(BHandler* target);
57 
58 	virtual status_t	Connect() = 0;
59 	virtual void		Disconnect();
60 
61 	virtual status_t 	GetBatteryInfo(battery_info* status, int32 index) = 0;
62 	virtual status_t 	GetExtendedBatteryInfo(acpi_extended_battery_info* info,
63 							int32 index) = 0;
64 
65 	virtual int32		GetBatteryCount() = 0;
66 
67 protected:
68 	virtual void		_WatchPowerStatus() = 0;
69 
70 	vint32				fIsWatching;
71 private:
72 	static int32		_ThreadWatchPowerFunction(void* data);
73 
74 	thread_id			fThreadId;
75 
76 	BLocker				fListLocker;
77 };
78 
79 
80 #endif
81