/*
 * Copyright 2010, Intel Corporation
 *
 * This file is part of PowerTOP
 *
 * This program file is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program in a file named COPYING; if not, write to the
 * Free Software Foundation, Inc,
 * 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 * or just google for it.
 *
 * Authors:
 *	Arjan van de Ven <arjan@linux.intel.com>
 */
#pragma once


#include <vector>
#include <climits>
#include <string>
#include "../lib.h"

struct parameter_bundle;
struct result_bundle;

/*
 * # subclasses of device
 *
 * | subclass           | filename                              |
 * | ------------------ | ------------------------------------- |
 * | cpudevice          | src/cpu/cpudevice.h                   |
 * | ahci               | src/devices/ahci.h                    |
 * | alsa               | src/devices/alsa.h                    |
 * | backlight          | src/devices/backlight.h               |
 * | devfreq            | src/devices/devfreq.h                 |
 * | i915gpu            | src/devices/i915-gpu.h                |
 * | network            | src/devices/network.h                 |
 * | rfkill             | src/devices/rfkill.h                  |
 * | runtime_pmdevice   | src/devices/runtime_pm.h              |
 * | thinkpad_fan       | src/devices/thinkpad-fan.h            |
 * | thinkpad_light     | src/devices/thinkpad-light.h          |
 * | usbdevice          | src/devices/usb.h                     |
 * | xegpu              | src/devices/xe-gpu.h                  |
 */
class device {
public:
	bool cached_valid = false;
	bool hide = false;

	std::string guilty;
	std::string real_path;

	virtual void start_measurement(void);
	virtual void end_measurement(void);

	device(void);

	virtual ~device() {};

	void register_sysfs_path(const std::string &path);

	virtual double	utilization(void) const; /* percentage */

	virtual std::string util_units(void) const { return "%"; };

	virtual std::string class_name(void) const { return "abstract device";};
	virtual std::string device_name(void) const { return "abstract device";};

	virtual std::string human_name(void) { return device_name(); };

	virtual double power_usage([[maybe_unused]] struct result_bundle *results, [[maybe_unused]] struct parameter_bundle *bundle) { return 0.0; };

	virtual bool show_in_list(void) const {return !hide;};

	virtual bool power_valid(void) const { return true;};

	virtual void register_power_with_devlist([[maybe_unused]] struct result_bundle *results, [[maybe_unused]] struct parameter_bundle *bundle) { ; };

	virtual int grouping_prio(void) const { return 0; }; /* priority of this device class if multiple classes match to the same underlying device. 0 is lowest */

	virtual void collect_json_fields(std::string &_js);
	std::string serialize() { JSON_START(); collect_json_fields(_js); JSON_END(); }
};

extern std::vector<class device *> all_devices;

extern void devices_start_measurement(void);
extern void devices_end_measurement(void);
extern void show_report_devices(void);
extern void report_devices(void);


extern void create_all_devices(void);
extern void clear_all_devices(void);

