1/* 2 * Copyright 2009, 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#ifndef DRIVER_INTERFACE_H 9#define DRIVER_INTERFACE_H 10 11 12#include <Handler.h> 13#include <Locker.h> 14#include <ObjectList.h> 15#include <Referenceable.h> 16 17#include "device/power_managment.h" 18 19 20typedef BObjectList<BHandler> WatcherList; 21 22const uint32 kMsgUpdate = 'updt'; 23 24 25struct battery_info { 26 int8 state; 27 int32 capacity; 28 int32 full_capacity; 29 time_t time_left; 30 int32 current_rate; 31}; 32 33 34/*! Handle a list of watcher and broadcast a messages to them. */ 35class Monitor { 36public: 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 44protected: 45 WatcherList fWatcherList; 46}; 47 48 49class PowerStatusDriverInterface : public Monitor, public BReferenceable { 50public: 51 PowerStatusDriverInterface(); 52 ~PowerStatusDriverInterface(); 53 54 virtual status_t StartWatching(BHandler* target); 55 virtual status_t StopWatching(BHandler* target); 56 virtual void Broadcast(uint32 message); 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 67protected: 68 virtual void _WatchPowerStatus() = 0; 69 70 vint32 fIsWatching; 71 sem_id fWaitSem; 72 73private: 74 static int32 _ThreadWatchPowerFunction(void* data); 75 76 thread_id fThread; 77 BLocker fListLocker; 78}; 79 80 81#endif // DRIVER_INTERFACE_H 82