/*
 * 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 <limits.h>
#include <string>
#include "../lib.h"

struct parameter_bundle;
struct result_bundle;

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);

