<commit_before>/*
 * Copyright (c) 2014 Citrix Systems, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "project.h"

static const char *current_display_size_path = "/xc_tools/switcher/current_display_size";
static const char *display_size_path = "switcher/display_size";

static const unsigned int width_for_bad_edid = 1024;
static const unsigned int height_for_bad_edid = 768;

static void
set_current_display_size(unsigned int x, unsigned int y)
{
    char buf[256];

    snprintf(buf, 256, "%d %d", x, y);
    /* surfman_info ("setting %s to %s\n", current_display_size_path, buf); */
    xenstore_write (buf, current_display_size_path, buf);
}

/* XXX: This will have to go */
#define plugin_monitor_info_t(_name_, _x_)                                              \
union                                                                                   \
{                                                                                       \
    surfman_monitor_info_t  __surfman_monitor_info;                                     \
    char __surfman_monitor_buff[sizeof (surfman_monitor_info_t) +                       \
                                sizeof (surfman_monitor_mode_t) * (_x_)];               \
} __ ## _name_;                                                                         \
surfman_monitor_info_t * _name_  = (surfman_monitor_info_t*)&(__ ## _name_)

static int
get_resolution_from_monitor(struct plugin *plugin, surfman_monitor_t monitor,
                            unsigned int *w, unsigned *h)
{
    plugin_monitor_info_t(info, 20);
    unsigned internal_w, internal_h;
    int ret;

    info->mode_count = 0;
    ret = PLUGIN_CALL (plugin, get_monitor_info, monitor, info, 20);
    if (ret)
    {
        surfman_warning ("%s: get_monitor_info method failed.", plugin->name);
        return ret;
    }

    if (info->mode_count <= 0)
        return 0;

    internal_w = info->current_mode->htimings[SURFMAN_TIMING_ACTIVE];
    internal_h = info->current_mode->vtimings[SURFMAN_TIMING_ACTIVE];

    if (internal_w && internal_w < 3000 && internal_h && internal_w < 3000)
    {
        *w = internal_w;
        *h = internal_h;
        return 1;
    }
    return 0;
}

static void resolution_xs_read(unsigned int domid, unsigned int *w, unsigned int *h)
{
    char *tmp = NULL;
    unsigned int internal_w, internal_h;

    tmp = xenstore_dom_read (domid, "%s", display_size_path);
    if (tmp)<commit_msg>get_resolution_from_monitor: avoid returning success on failure<commit_after>/*
 * Copyright (c) 2014 Citrix Systems, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "project.h"

static const char *current_display_size_path = "/xc_tools/switcher/current_display_size";
static const char *display_size_path = "switcher/display_size";

static const unsigned int width_for_bad_edid = 1024;
static const unsigned int height_for_bad_edid = 768;

static void
set_current_display_size(unsigned int x, unsigned int y)
{
    char buf[256];

    snprintf(buf, 256, "%d %d", x, y);
    /* surfman_info ("setting %s to %s\n", current_display_size_path, buf); */
    xenstore_write (buf, current_display_size_path, buf);
}

/* XXX: This will have to go */
#define plugin_monitor_info_t(_name_, _x_)                                              \
union                                                                                   \
{                                                                                       \
    surfman_monitor_info_t  __surfman_monitor_info;                                     \
    char __surfman_monitor_buff[sizeof (surfman_monitor_info_t) +                       \
                                sizeof (surfman_monitor_mode_t) * (_x_)];               \
} __ ## _name_;                                                                         \
surfman_monitor_info_t * _name_  = (surfman_monitor_info_t*)&(__ ## _name_)

static int
get_resolution_from_monitor(struct plugin *plugin, surfman_monitor_t monitor,
                            unsigned int *w, unsigned *h)
{
    plugin_monitor_info_t(info, 20);
    unsigned internal_w, internal_h;
    int ret;

    info->mode_count = 0;
    ret = PLUGIN_CALL (plugin, get_monitor_info, monitor, info, 20);
    if (ret)
    {
        surfman_warning ("%s: get_monitor_info method failed with error %d.",
                         plugin->name, ret);
        return 0;
    }

    if (info->mode_count <= 0)
        return 0;

    internal_w = info->current_mode->htimings[SURFMAN_TIMING_ACTIVE];
    internal_h = info->current_mode->vtimings[SURFMAN_TIMING_ACTIVE];

    if (internal_w && internal_w < 3000 && internal_h && internal_w < 3000)
    {
        *w = internal_w;
        *h = internal_h;
        return 1;
    }
    return 0;
}

static void resolution_xs_read(unsigned int domid, unsigned int *w, unsigned int *h)
{
    char *tmp = NULL;
    unsigned int internal_w, internal_h;

    tmp = xenstore_dom_read (domid, "%s", display_size_path);
    if (tmp)
{'fraction_non_alphanumeric': 0.08180118416952321, 'fraction_numerical': 0.014802119040199438, 'mean_word_length': 2.211105552776388, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3916664', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1783, 'n_words': 576}