/**
 * Copyright © 2016 IBM Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "config.h"

#include "hwmonio.hpp"
#include "mainloop.hpp"
#include "sysfs.hpp"

#include <CLI/CLI.hpp>
#include <iostream>
#include <memory>

static void exit_with_error(const std::string& help, const char* err)
{
    std::cerr << "ERROR: " << err << std::endl << help << std::endl;
    exit(-1);
}

int main(int argc, char** argv)
{
    // Read arguments.
    std::string syspath = "";
    std::string devpath = "";
    std::string sensor_id = "";

    CLI::App app{"OpenBMC Hwmon Daemon"};
    app.add_option("-p,--path", syspath, "sysfs location to monitor");
    app.add_option("-o,--dev-path", devpath, "device path to monitor");
    app.add_option("-i,--sensor-id", sensor_id, "dbus sensor instance id");

    CLI11_PARSE(app, argc, argv);

    // Parse out path argument.
    auto path = devpath;
    auto param = path;
    if (!path.empty())
    {
        // This path may either be a device path (starts with
        // /devices), or an open firmware device tree path.
        if (path.substr(0, 8) == "/devices")
        {
            path = sysfs::findHwmonFromDevPath(path);
        }
        else
        {
            path = sysfs::findHwmonFromOFPath(path);
        }
    }

    if (path.empty())
    {
        path = syspath;
        param = path;
    }

    if (path.empty())
    {
        exit_with_error(app.help("", CLI::AppFormatMode::All),
                        "Path not specified or invalid.");
    }

    // Determine the physical device sysfs path.
    auto calloutPath = sysfs::findCalloutPath(path);
    if (calloutPath.empty())
    {
        exit_with_error(app.help("", CLI::AppFormatMode::All),
                        "Unable to determine callout path.");
    }

    hwmonio::HwmonIO io(path);
    MainLoop loop(sdbusplus::bus::new_default(), param, path, calloutPath,
                  BUSNAME_PREFIX, SENSOR_ROOT, sensor_id, &io);
    loop.run();

    return 0;
}

// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
