1/* 2 * Copyright 2009-2015, 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(int32 index, 62 battery_info* status) = 0; 63 virtual status_t GetExtendedBatteryInfo(int32 index, 64 acpi_extended_battery_info* info) = 0; 65 66 virtual int32 GetBatteryCount() = 0; 67 68protected: 69 virtual void _WatchPowerStatus() = 0; 70 71protected: 72 int32 fIsWatching; 73 sem_id fWaitSem; 74 75private: 76 static int32 _ThreadWatchPowerFunction(void* data); 77 78 thread_id fThread; 79 BLocker fListLocker; 80}; 81 82 83#endif // DRIVER_INTERFACE_H 84