<commit_before>/*
 * Copyright 2014 The Imaging Source Europe GmbH
 *
 * 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 "v4l2_utils.h"

#include "v4l2_property_mapping.h"
#include "utils.h"
#include "logging.h"

#if HAVE_UDEV
#include <libudev.h>
#endif

#include <glob.h>

#include <vector>
#include <algorithm>

using namespace tcam;

uint32_t tcam::convert_v4l2_flags (uint32_t v4l2_flags)
{
    uint32_t internal_flags = 0;

    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_DISABLED))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_DISABLED);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_GRABBED))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_GRABBED);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_READ_ONLY))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_READ_ONLY);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_UPDATE))
    {}
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_INACTIVE))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_INACTIVE);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_SLIDER))
    {}
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_WRITE_ONLY))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_WRITE_ONLY);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_VOLATILE))
    {}
    // if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_HAS_PAYLOAD))
    // {}

    return internal_flags;
}

TCAM_PROPERTY_ID tcam::find_v4l2_mapping (int v4l2_id)
{
    auto f = [v4l2_id] (int p)
        {
            if (v4l2_id == p)
                return true;
            return false;
        };

    for (const auto& m : v4l2_mappings)
    {
        auto match = std::find_if(m.v4l2_id.begin(), m.v4l2_id.end(), f);

        if (match != m.v4l2_id.end())
            return m.id;
    }
    return TCAM_PROPERTY_INVALID;
}

std::shared_ptr<Property> tcam::create_property (int fd,
                                                 struct v4l2_queryctrl* queryctrl,
                                                 struct v4l2_ext_control* ctrl,
                                                 std::shared_ptr<PropertyImpl> impl)
{

    // assure we have the typ
    Property::VALUE_TYPE type;

    switch (queryctrl->type)
    {
        case V4L2_CTRL_TYPE_BOOLEAN:
        {
            type = Property::BOOLEAN;
            break;
        }
        case V4L2_CTRL_TYPE_INTEGER:
        {
            type = Property::INTEGER;
            break;
        }
        case V4L2_CTRL_TYPE_STRING:
        {
            type = Property::STRING;
            break;
        }
        case V4L2_CTRL_TYPE_INTEGER_MENU:
        case V4L2_CTRL_TYPE_MENU:
        {
            type = Property::ENUM;
            break;
        }
        case V4L2_CTRL_TYPE_BUTTON:
        {
            type = Property::BUTTON;
            break;
        }
        default:
        {
            type = Property::UNDEFINED;
            break;
        }
    }

    auto prop_id = find_v4l2_mapping (ctrl->id);

    auto ctrl_m = get_control_reference(prop_id);

    TCAM_PROPERTY_TYPE type_to_use;
    tcam_device_property cp = {};

    if (ctrl_m.id == TCAM_PROPERTY_INVALID)
    {
        tcam_log(TCAM_LOG_WARNING, "Unable to find std property. Passing raw property identifier through. '%s'(%x)", (char*)queryctrl->name, queryctrl->id);
        // pass through and do not associate with anything existing
        type_to_use = value_type_to_ctrl_type(type);
        memcpy(cp.name, (char*)queryctrl->name, sizeof(cp.name));
        cp.type = value_type_to_ctrl_type(type);
        // generate id so that identfication of passed through properties is guaranteed
        cp.id = generate_unique_property_id();
    }
    else
    {
        type_to_use = ctrl_m.type_to_use;
        cp = create_empty_property(ctrl_m.id);
    }

    uint32_t flags = convert_v4l2_flags(queryctrl->flags);

    switch (type_to_use)
    {
        case TCAM_PROPERTY_TYPE_BOOLEAN:
        {
            if (queryctrl->default_value == 0)
            {
                cp.value.b.default_value = false;
            }
            else if (queryctrl->default_value > 0)
            {
                cp.value.b.default_value = true;
            }
            else
            {
                tcam_log(TCAM_LOG_ERROR,
                        "Boolean '%s' has impossible default value: %d Setting to false",
                        cp.name,
                        queryctrl->default_value);
                cp.value.b.default_value = false;
            }

            if (ctrl->value == 0)
            {
                cp.value.b.value = false;
            }
            else if (ctrl->value > 0)
            {
                cp.value.b.value = true;
            }
            else
            {
                tcam_log(TCAM_LOG_ERROR,
                        "Boolean '%s' has impossible value: %d Setting to false",
                        cp.name,
                        ctrl->value);
                cp.value.b.value = false;
            }
            cp.flags = flags;

            return std::make_shared<Property>(PropertyBoolean(impl, cp, type));
        }
        case TCAM_PROPERTY_TYPE_INTEGER:
        {
            cp.value.i.min = queryctrl->minimum;
            cp.value.i.max = queryctrl->maximum;
            cp.value.i.step = queryctrl->step;

            if (cp.value.i.min > cp.value.i.max)
            {
                tcam_log(TCAM_LOG_ERROR,
                         "Range boundaries for property '%s' are faulty. Ignoring property as a precaution.",
                         cp.name);
                return nullptr;
            }

            if (cp.value.i.step == 0)
            {
                tcam_log(TCAM_LOG_WARNING,
                         "Detected stepsize 0 for property %s. Setting to 1.",
                         cp.name);

                cp.value.i.step = 1;
            }

            cp.value.i.default_value = queryctrl->default_value;
            cp.value.i.value = ctrl->value;
            cp.flags = flags;

            return std::make_shared<Property>(PropertyInteger(impl, cp, type));
        }
        // case TCAM_CTRL_TYPE_DOUBLE:
        // {
        // Does not exist in v4l2
        // }
        case TCAM_PROPERTY_TYPE_STRING:
        {
            memcpy(cp.value.s.value,(char*)queryctrl->name, sizeof(cp.value.s.value));
            memcpy(cp.value.s.default_value, (char*)queryctrl->name, sizeof(cp.value.s.default_value));
            cp.flags = flags;

            return std::make_shared<Property>(PropertyString(impl, cp, type));
        }
        case TCAM_PROPERTY_TYPE_ENUMERATION:
        {
            cp.value.i.min = queryctrl->minimum;
            cp.value.i.max = queryctrl->maximum;
            cp.value.i.step = 0;
            cp.value.i.default_value = queryctrl->default_value;
            cp.value.i.value = ctrl->value;
            cp.flags = flags;

            struct v4l2_querymenu qmenu = {};

            qmenu.id = queryctrl->id;

            std::map<std::string, int> m;

            for (int i = 0; i <= queryctrl->maximum; i++)
            {
                qmenu.index = i;
                if (tcam_xioctl(fd, VIDIOC_QUERYMENU, &qmenu))
                    continue;

                std::string map_string((char*) qmenu.name);
                m.emplace(map_string, i);
            }

            return std::make_shared<Property>(PropertyEnumeration(impl, cp, m, type));
        }
        case TCAM_PROPERTY_TYPE_BUTTON:
        {
            cp.flags = flags;

            return std::make_shared<Property>(PropertyButton(impl, cp, type));
        }
        default:
        {
            std::string s = "Unknown V4L2 Control type: ";
            s.append((char*)queryctrl->name);
            tcam_log(TCAM_LOG_ERROR, s.c_str());
            break;
        }
    }
    return nullptr;
}

std::vector<DeviceInfo> tcam::get_v4l2_device_list ()
{
    std::vector<DeviceInfo> device_list;

    struct udev* udev = udev_new();
    if (!udev)
    {
        return device_list;
    }

    /* Create a list of the devices in the 'video4linux' subsystem. */
    struct udev_enumerate* enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "video4linux");
    udev_enumerate_scan_devices(enumerate);
    struct udev_list_entry* devices = udev_enumerate_get_list_entry(enumerate);
    struct udev_list_entry* dev_list_entry;

    auto device_is_known = [&device_list] (const DeviceInfo& info)
        {
            for (const auto& dev : device_list)
            {
                if (dev.get_serial() == info.get_serial())
                {
                    return true;
                }
            }
            return false;
        };

    udev_list_entry_foreach(dev_list_entry, devices)
    {
        const char* path;
        char needed_path[100];

        /* Get the filename of the /sys entry for the device
           and create a udev_device object (dev) representing it */
        path = udev_list_entry_get_name(dev_list_entry);
        struct udev_device* dev = udev_device_new_from_syspath(udev, path);

        /* The device pointed to by dev contains information about
           the hidraw device. In order to get information about the
           USB device, get the parent device with the
           subsystem/devtype pair of "usb"/"usb_device". This will
           be several levels up the tree, but the function will find
           it.*/

        /* we need to copy the devnode (/dev/videoX) before the path
           is changed to the path of the usb device behind it (/sys/class/....) */
        strcpy(needed_path, udev_device_get_devnode(dev));

        struct udev_device* parent_device = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device");

        /* skip this device if we can't get the usb parent */
        if (!parent_device)
        {
            continue;
        }

        /* From here, we can call get_sysattr_value() for each file
           in the device's /sys entry. The strings passed into these
           functions (idProduct, idVendor, serial, etc.) correspond
           directly to the files in the directory which represents
           the USB device. Note that USB strings are Unicode, UCS2
           encoded, but the strings returned from
           udev_device_get_sysattr_value() are UTF-8 encoded. */

        static const char* TCAM_VENDOR_ID_STRING = "199e";

        if (strcmp(udev_device_get_sysattr_value(parent_device, "idVendor"), TCAM_VENDOR_ID_STRING) == 0)
        {
            tcam_device_info info = {};
            info.type = TCAM_DEVICE_TYPE_V4L2;
            strncpy(info.identifier, needed_path, sizeof(info.identifier));

            if (udev_device_get_sysattr_value(parent_device, "idProduct") != NULL)
            {
                strncpy(info.additional_identifier, udev_device_get_sysattr_value(parent_device, "idProduct"), sizeof(info.additional_identifier));
            }

            if (udev_device_get_sysattr_value(parent_device, "product") != NULL)
            {
                strncpy(info.name, udev_device_get_sysattr_value(parent_device, "product"), sizeof(info.name));
            }
            if (udev_device_get_sysattr_value(parent_device, "serial") != NULL)
            {
                std::string tmp = udev_device_get_sysattr_value(parent_device, "serial");
                tmp.erase(remove_if(tmp.begin(), tmp.end(), isspace), tmp.end());
                strncpy(info.serial_number, tmp.c_str(), sizeof(info.serial_number));
            }

            auto new_dev = DeviceInfo(info);
            if (!device_is_known(new_dev))
            {
                device_list.push_back(new_dev);
            }
        }

        udev_device_unref(dev);
    }

    /* Free the enumerator object */
    udev_enumerate_unref(enumerate);

    udev_unref(udev);

    return device_list;
}
<commit_msg>v4l2: Filter empty enums<commit_after>/*
 * Copyright 2014 The Imaging Source Europe GmbH
 *
 * 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 "v4l2_utils.h"

#include "v4l2_property_mapping.h"
#include "utils.h"
#include "logging.h"

#if HAVE_UDEV
#include <libudev.h>
#endif

#include <glob.h>

#include <vector>
#include <algorithm>

using namespace tcam;

uint32_t tcam::convert_v4l2_flags (uint32_t v4l2_flags)
{
    uint32_t internal_flags = 0;

    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_DISABLED))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_DISABLED);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_GRABBED))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_GRABBED);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_READ_ONLY))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_READ_ONLY);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_UPDATE))
    {}
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_INACTIVE))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_INACTIVE);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_SLIDER))
    {}
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_WRITE_ONLY))
    {
        internal_flags = set_bit(internal_flags, TCAM_PROPERTY_FLAG_WRITE_ONLY);
    }
    if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_VOLATILE))
    {}
    // if (is_bit_set(v4l2_flags, V4L2_CTRL_FLAG_HAS_PAYLOAD))
    // {}

    return internal_flags;
}

TCAM_PROPERTY_ID tcam::find_v4l2_mapping (int v4l2_id)
{
    auto f = [v4l2_id] (int p)
        {
            if (v4l2_id == p)
                return true;
            return false;
        };

    for (const auto& m : v4l2_mappings)
    {
        auto match = std::find_if(m.v4l2_id.begin(), m.v4l2_id.end(), f);

        if (match != m.v4l2_id.end())
            return m.id;
    }
    return TCAM_PROPERTY_INVALID;
}

std::shared_ptr<Property> tcam::create_property (int fd,
                                                 struct v4l2_queryctrl* queryctrl,
                                                 struct v4l2_ext_control* ctrl,
                                                 std::shared_ptr<PropertyImpl> impl)
{

    // assure we have the typ
    Property::VALUE_TYPE type;

    switch (queryctrl->type)
    {
        case V4L2_CTRL_TYPE_BOOLEAN:
        {
            type = Property::BOOLEAN;
            break;
        }
        case V4L2_CTRL_TYPE_INTEGER:
        {
            type = Property::INTEGER;
            break;
        }
        case V4L2_CTRL_TYPE_STRING:
        {
            type = Property::STRING;
            break;
        }
        case V4L2_CTRL_TYPE_INTEGER_MENU:
        case V4L2_CTRL_TYPE_MENU:
        {
            type = Property::ENUM;
            break;
        }
        case V4L2_CTRL_TYPE_BUTTON:
        {
            type = Property::BUTTON;
            break;
        }
        default:
        {
            type = Property::UNDEFINED;
            break;
        }
    }

    auto prop_id = find_v4l2_mapping (ctrl->id);

    auto ctrl_m = get_control_reference(prop_id);

    TCAM_PROPERTY_TYPE type_to_use;
    tcam_device_property cp = {};

    if (ctrl_m.id == TCAM_PROPERTY_INVALID)
    {
        tcam_log(TCAM_LOG_WARNING, "Unable to find std property. Passing raw property identifier through. '%s'(%x)", (char*)queryctrl->name, queryctrl->id);
        // pass through and do not associate with anything existing
        type_to_use = value_type_to_ctrl_type(type);
        memcpy(cp.name, (char*)queryctrl->name, sizeof(cp.name));
        cp.type = value_type_to_ctrl_type(type);
        // generate id so that identfication of passed through properties is guaranteed
        cp.id = generate_unique_property_id();
    }
    else
    {
        type_to_use = ctrl_m.type_to_use;
        cp = create_empty_property(ctrl_m.id);
    }

    uint32_t flags = convert_v4l2_flags(queryctrl->flags);

    switch (type_to_use)
    {
        case TCAM_PROPERTY_TYPE_BOOLEAN:
        {
            if (queryctrl->default_value == 0)
            {
                cp.value.b.default_value = false;
            }
            else if (queryctrl->default_value > 0)
            {
                cp.value.b.default_value = true;
            }
            else
            {
                tcam_log(TCAM_LOG_ERROR,
                        "Boolean '%s' has impossible default value: %d Setting to false",
                        cp.name,
                        queryctrl->default_value);
                cp.value.b.default_value = false;
            }

            if (ctrl->value == 0)
            {
                cp.value.b.value = false;
            }
            else if (ctrl->value > 0)
            {
                cp.value.b.value = true;
            }
            else
            {
                tcam_log(TCAM_LOG_ERROR,
                        "Boolean '%s' has impossible value: %d Setting to false",
                        cp.name,
                        ctrl->value);
                cp.value.b.value = false;
            }
            cp.flags = flags;

            return std::make_shared<Property>(PropertyBoolean(impl, cp, type));
        }
        case TCAM_PROPERTY_TYPE_INTEGER:
        {
            cp.value.i.min = queryctrl->minimum;
            cp.value.i.max = queryctrl->maximum;
            cp.value.i.step = queryctrl->step;

            if (cp.value.i.min > cp.value.i.max)
            {
                tcam_log(TCAM_LOG_ERROR,
                         "Range boundaries for property '%s' are faulty. Ignoring property as a precaution.",
                         cp.name);
                return nullptr;
            }

            if (cp.value.i.step == 0)
            {
                tcam_log(TCAM_LOG_WARNING,
                         "Detected stepsize 0 for property %s. Setting to 1.",
                         cp.name);

                cp.value.i.step = 1;
            }

            cp.value.i.default_value = queryctrl->default_value;
            cp.value.i.value = ctrl->value;
            cp.flags = flags;

            return std::make_shared<Property>(PropertyInteger(impl, cp, type));
        }
        // case TCAM_CTRL_TYPE_DOUBLE:
        // {
        // Does not exist in v4l2
        // }
        case TCAM_PROPERTY_TYPE_STRING:
        {
            memcpy(cp.value.s.value,(char*)queryctrl->name, sizeof(cp.value.s.value));
            memcpy(cp.value.s.default_value, (char*)queryctrl->name, sizeof(cp.value.s.default_value));
            cp.flags = flags;

            return std::make_shared<Property>(PropertyString(impl, cp, type));
        }
        case TCAM_PROPERTY_TYPE_ENUMERATION:
        {
            cp.value.i.min = queryctrl->minimum;
            cp.value.i.max = queryctrl->maximum;
            cp.value.i.step = 0;
            cp.value.i.default_value = queryctrl->default_value;
            cp.value.i.value = ctrl->value;
            cp.flags = flags;

            struct v4l2_querymenu qmenu = {};

            qmenu.id = queryctrl->id;

            std::map<std::string, int> m;

            for (int i = 0; i <= queryctrl->maximum; i++)
            {
                qmenu.index = i;
                if (tcam_xioctl(fd, VIDIOC_QUERYMENU, &qmenu))
                    continue;

                std::string map_string((char*) qmenu.name);
                m.emplace(map_string, i);
            }

            if (m.empty())
            {
                tcam_debug("Enum %s does not have any entries. Ignoring.", cp.name);
                return nullptr;
            }

            return std::make_shared<Property>(PropertyEnumeration(impl, cp, m, type));
        }
        case TCAM_PROPERTY_TYPE_BUTTON:
        {
            cp.flags = flags;

            return std::make_shared<Property>(PropertyButton(impl, cp, type));
        }
        default:
        {
            std::string s = "Unknown V4L2 Control type: ";
            s.append((char*)queryctrl->name);
            tcam_log(TCAM_LOG_ERROR, s.c_str());
            break;
        }
    }
    return nullptr;
}

std::vector<DeviceInfo> tcam::get_v4l2_device_list ()
{
    std::vector<DeviceInfo> device_list;

    struct udev* udev = udev_new();
    if (!udev)
    {
        return device_list;
    }

    /* Create a list of the devices in the 'video4linux' subsystem. */
    struct udev_enumerate* enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "video4linux");
    udev_enumerate_scan_devices(enumerate);
    struct udev_list_entry* devices = udev_enumerate_get_list_entry(enumerate);
    struct udev_list_entry* dev_list_entry;

    auto device_is_known = [&device_list] (const DeviceInfo& info)
        {
            for (const auto& dev : device_list)
            {
                if (dev.get_serial() == info.get_serial())
                {
                    return true;
                }
            }
            return false;
        };

    udev_list_entry_foreach(dev_list_entry, devices)
    {
        const char* path;
        char needed_path[100];

        /* Get the filename of the /sys entry for the device
           and create a udev_device object (dev) representing it */
        path = udev_list_entry_get_name(dev_list_entry);
        struct udev_device* dev = udev_device_new_from_syspath(udev, path);

        /* The device pointed to by dev contains information about
           the hidraw device. In order to get information about the
           USB device, get the parent device with the
           subsystem/devtype pair of "usb"/"usb_device". This will
           be several levels up the tree, but the function will find
           it.*/

        /* we need to copy the devnode (/dev/videoX) before the path
           is changed to the path of the usb device behind it (/sys/class/....) */
        strcpy(needed_path, udev_device_get_devnode(dev));

        struct udev_device* parent_device = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device");

        /* skip this device if we can't get the usb parent */
        if (!parent_device)
        {
            continue;
        }

        /* From here, we can call get_sysattr_value() for each file
           in the device's /sys entry. The strings passed into these
           functions (idProduct, idVendor, serial, etc.) correspond
           directly to the files in the directory which represents
           the USB device. Note that USB strings are Unicode, UCS2
           encoded, but the strings returned from
           udev_device_get_sysattr_value() are UTF-8 encoded. */

        static const char* TCAM_VENDOR_ID_STRING = "199e";

        if (strcmp(udev_device_get_sysattr_value(parent_device, "idVendor"), TCAM_VENDOR_ID_STRING) == 0)
        {
            tcam_device_info info = {};
            info.type = TCAM_DEVICE_TYPE_V4L2;
            strncpy(info.identifier, needed_path, sizeof(info.identifier));

            if (udev_device_get_sysattr_value(parent_device, "idProduct") != NULL)
            {
                strncpy(info.additional_identifier, udev_device_get_sysattr_value(parent_device, "idProduct"), sizeof(info.additional_identifier));
            }

            if (udev_device_get_sysattr_value(parent_device, "product") != NULL)
            {
                strncpy(info.name, udev_device_get_sysattr_value(parent_device, "product"), sizeof(info.name));
            }
            if (udev_device_get_sysattr_value(parent_device, "serial") != NULL)
            {
                std::string tmp = udev_device_get_sysattr_value(parent_device, "serial");
                tmp.erase(remove_if(tmp.begin(), tmp.end(), isspace), tmp.end());
                strncpy(info.serial_number, tmp.c_str(), sizeof(info.serial_number));
            }

            auto new_dev = DeviceInfo(info);
            if (!device_is_known(new_dev))
            {
                device_list.push_back(new_dev);
            }
        }

        udev_device_unref(dev);
    }

    /* Free the enumerator object */
    udev_enumerate_unref(enumerate);

    udev_unref(udev);

    return device_list;
}
<|endoftext|>


<commit_before>#include "../common/std_headers.h"
#include "./polyfit.h"

/* ----------------------------------------------------------------------
   Evaluate polynomials
*/

double getValue(Polyfit1 const &u, double t)
{
  return u.c0 + t*(u.c1);
}
double getDerivative(Polyfit1 const &u, double t)
{
  return u.c1;
}

double getValue(Polyfit3 const &u, double t)
{
  return u.c0 + t*(u.c1 + (t*(u.c2 + t*u.c3)));
}
double getDerivative(Polyfit3 const &u, double t)
{
  return u.c1 + 2.0*u.c2*t + 3.0*u.c3*t*t;
}

double getValue(Polyfit5 const &u, double t)
{
  return u.c0 + t*(u.c1 + (t*(u.c2 + t*(u.c3 + t*(u.c4 + t*(u.c5))))));
}
double getDerivative(Polyfit5 const &u, double t)
{
  return u.c1 + t*(2.0*u.c2 + t*(3.0*u.c3 + t*(4.0*u.c4 + t*(5.0*u.c5))));
}

/*
  Fit a polynomial to some X and Y data. That is, return a Polyfit{1,3,5} p so that getValue(p, X) approximates Y.
 */

Polyfit1 mkPolyfit1(arma::Col<double> xs, arma::Col<double> ys)
{
  if (xs.n_elem != ys.n_elem) throw runtime_error("incompatible arrays");
  if (xs.n_elem < 2) throw runtime_error ("not enough data");

  arma::mat xsm = arma::mat(xs.n_elem, 2);
  arma::mat ysm = arma::mat(ys.n_elem, 1);

  for (size_t ri=0; ri<xs.n_elem; ri++) {
    double x = xs(ri);
    double y = ys(ri);
    xsm(ri, 0) = 1;
    xsm(ri, 1) = x;
    ysm(ri, 0) = y;
  }

  // Throws runtime_error if no solution
  arma::mat coeffs = arma::solve(xsm, ysm);
  return Polyfit1(coeffs(0,0), coeffs(1,0));
}

Polyfit3 mkPolyfit3(arma::Col<double> xs, arma::Col<double> ys)
{
  if (xs.n_elem != ys.n_elem) throw runtime_error("incompatible arrays");
  if (xs.n_elem < 4) throw runtime_error ("not enough data");

  arma::mat xsm = arma::mat(xs.n_elem, 4);
  arma::mat ysm = arma::mat(ys.n_elem, 1);

  for (size_t ri=0; ri<xs.n_elem; ri++) {
    double x = xs(ri);
    double y = ys(ri);
    xsm(ri, 0) = 1;
    xsm(ri, 1) = x;
    xsm(ri, 2) = x*x;
    xsm(ri, 3) = x*x*x;
    ysm(ri, 0) = y;
  }

  // Throws runtime_error if no solution
  arma::mat coeffs = arma::solve(xsm, ysm);
  return Polyfit3(coeffs(0,0), coeffs(1,0), coeffs(2,0), coeffs(3,0));
}

Polyfit5 mkPolyfit5(arma::Col<double> xs, arma::Col<double> ys)
{
  if (xs.n_elem != ys.n_elem) throw runtime_error("incompatible arrays");
  if (xs.n_elem < 6) throw runtime_error("not enough data");

  arma::mat xsm = arma::mat(xs.n_elem, 6);
  arma::mat ysm = arma::mat(ys.n_elem, 1);

  for (size_t ri=0; ri<xs.n_elem; ri++) {
    double x = xs(ri);
    double y = ys(ri);
    xsm(ri, 0) = 1;
    xsm(ri, 1) = x;
    xsm(ri, 2) = x*x;
    xsm(ri, 3) = x*x*x;
    xsm(ri, 4) = x*x*x*x;
    xsm(ri, 5) = x*x*x*x*x;
    ysm(ri, 0) = y;
  }

  // Throws runtime_error if no solution
  arma::mat coeffs = arma::solve(xsm, ysm);
  return Polyfit5(coeffs(0,0), coeffs(1,0), coeffs(2,0), coeffs(3,0), coeffs(4,0), coeffs(5,0));
}
<commit_msg>Delete polyfit.cc<commit_after><|endoftext|>


<commit_before>/*  This file is part of the Vc library.

    Copyright (C) 2010 Matthias Kretz <kretz@kde.org>

    Vc 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 3 of
    the License, or (at your option) any later version.

    Vc 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 Vc.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef VC_MIC_PREFETCH_TCC
#define VC_MIC_PREFETCH_TCC

Vc_NAMESPACE_BEGIN(Internal)

Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchForOneRead(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_NTA);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchClose(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T0);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchMid(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T1);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchFar(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T2);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchForModify(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T0);
}

Vc_NAMESPACE_END

#endif // VC_MIC_PREFETCH_TCC
<commit_msg>the MIC has vprefetche[012] for prefetchForModify<commit_after>/*  This file is part of the Vc library.

    Copyright (C) 2010 Matthias Kretz <kretz@kde.org>

    Vc 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 3 of
    the License, or (at your option) any later version.

    Vc 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 Vc.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef VC_MIC_PREFETCH_TCC
#define VC_MIC_PREFETCH_TCC

Vc_NAMESPACE_BEGIN(Internal)

Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchForOneRead(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_NTA);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchClose(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T0);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchMid(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T1);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchFar(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T2);
}
Vc_ALWAYS_INLINE void HelperImpl<Vc::MICImpl>::prefetchForModify(const void *addr)
{
    _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_ET0);
}

Vc_NAMESPACE_END

#endif // VC_MIC_PREFETCH_TCC
<|endoftext|>


<commit_before>/* This source file is part of the Tomviz project, https://tomviz.org/.
   It is released under the 3-Clause BSD License, see "LICENSE". */

#include "SaveLoadTemplateReaction.h"

#include "ActiveObjects.h"
#include "ModuleManager.h"
#include "Pipeline.h"
#include "RecentFilesMenu.h"
#include "Utilities.h"

#include <QApplication>
#include <QDebug>
#include <QInputDialog>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>

namespace tomviz {

SaveLoadTemplateReaction::SaveLoadTemplateReaction(QAction* parentObject, bool load, QString filename)
  : pqReaction(parentObject), m_load(load), m_filename(filename)
{}

void SaveLoadTemplateReaction::onTriggered()
{
  if (m_load) {
    loadTemplate(m_filename);
  } else {
    saveTemplate();
  }
}

bool SaveLoadTemplateReaction::saveTemplate()
{
  bool ok;
  QString text = QInputDialog::getText(tomviz::mainWidget(), tr("Save Pipeline Template"),
                                         tr("Template Name:"), QLineEdit::Normal, QString(), &ok);
  QString fileName = text.replace(" ", "_");
  if (ok && !text.isEmpty()) {
    QString path = QApplication::applicationDirPath() +
                    "/../share/tomviz/templates/" + fileName + ".tvsm";
    return SaveLoadTemplateReaction::saveTemplate(path);
  }
  return false;
}

bool SaveLoadTemplateReaction::loadTemplate(const QString& fileName)
{
  QString path = QApplication::applicationDirPath() +
                 "/../share/tomviz/templates/" + fileName + ".tvsm";
  QFile openFile(path);
  if (!openFile.open(QIODevice::ReadOnly)) {
    qWarning("Could not open template.");
    return false;
  }

  QJsonParseError error;
  auto contents = openFile.readAll();
  auto doc = QJsonDocument::fromJson(contents, &error);

  // Get the parent data source, as well as the active (i.e. data and output)
  auto activeParent = ActiveObjects::instance().activeParentDataSource();
  auto activeData = ActiveObjects::instance().activeDataSource();
  ModuleManager::instance().removeAllModules(activeData);

  // Read in the template file and apply it to the current data source
  activeParent->deserialize(doc.object());
  // Load the default modules on the output if there are none
  bool noModules = ModuleManager::instance().findModulesGeneric(activeData, nullptr).isEmpty();
  if (noModules && activeData != activeParent) {
    activeParent->pipeline()->addDefaultModules(activeData);
    std::cout << "Default mods problem" << std::endl;
  }

  return true;
}

bool SaveLoadTemplateReaction::saveTemplate(const QString& fileName)
{
  QFileInfo info(fileName);
  QFile saveFile(fileName);
  if (!saveFile.open(QIODevice::WriteOnly)) {
    qWarning("Couldn't open save file.");
    return false;
  }

  DataSource* activeParent = ActiveObjects::instance().activeParentDataSource();
  QJsonObject state = activeParent->serialize();
  QJsonObject json;
  // Save any modules loaded on the parent data source
  if (state.contains("modules")) {
    json["modules"] = state.value("modules");
  }

  if (state.contains("operators")) {
    QJsonArray ops;
    foreach (QJsonValue val, state["operators"].toArray()) {
      QJsonObject temp;
      foreach (QString key, val.toObject().keys()) {
        qDebug() << "Key: " << key << endl;
        // Save the operators
        if (key != QString("dataSources")) {
          qDebug() << "Not dataSources: " << key << endl;
          temp.insert(key, val.toObject().value(key));
        } else {
          // If there are modules loaded on the child data source, save those as well
          QJsonValue dataSources = val.toObject().value("dataSources");
          QJsonObject modules = {{"modules", dataSources.toArray()[0].toObject().value("modules")}};
          QJsonArray arr = { modules };
          temp.insert("dataSources", arr);
        }
      }
      ops.push_back(temp);
    }
    json["operators"] = ops;
  }

  QJsonDocument doc(json);
  auto writeSuccess = saveFile.write(doc.toJson());
  return !json.isEmpty() && writeSuccess != -1;
}

} // namespace tomviz
<commit_msg>Do not remove modules before loading template<commit_after>/* This source file is part of the Tomviz project, https://tomviz.org/.
   It is released under the 3-Clause BSD License, see "LICENSE". */

#include "SaveLoadTemplateReaction.h"

#include "ActiveObjects.h"
#include "ModuleManager.h"
#include "Pipeline.h"
#include "RecentFilesMenu.h"
#include "Utilities.h"

#include <QApplication>
#include <QDebug>
#include <QInputDialog>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>

namespace tomviz {

SaveLoadTemplateReaction::SaveLoadTemplateReaction(QAction* parentObject, bool load, QString filename)
  : pqReaction(parentObject), m_load(load), m_filename(filename)
{}

void SaveLoadTemplateReaction::onTriggered()
{
  if (m_load) {
    loadTemplate(m_filename);
  } else {
    saveTemplate();
  }
}

bool SaveLoadTemplateReaction::saveTemplate()
{
  bool ok;
  QString text = QInputDialog::getText(tomviz::mainWidget(), tr("Save Pipeline Template"),
                                         tr("Template Name:"), QLineEdit::Normal, QString(), &ok);
  QString fileName = text.replace(" ", "_");
  if (ok && !text.isEmpty()) {
    QString path = QApplication::applicationDirPath() +
                    "/../share/tomviz/templates/" + fileName + ".tvsm";
    return SaveLoadTemplateReaction::saveTemplate(path);
  }
  return false;
}

bool SaveLoadTemplateReaction::loadTemplate(const QString& fileName)
{
  QString path = QApplication::applicationDirPath() +
                 "/../share/tomviz/templates/" + fileName + ".tvsm";
  QFile openFile(path);
  if (!openFile.open(QIODevice::ReadOnly)) {
    qWarning("Could not open template.");
    return false;
  }

  QJsonParseError error;
  auto contents = openFile.readAll();
  auto doc = QJsonDocument::fromJson(contents, &error);

  // Get the parent data source, as well as the active (i.e. data and output)
  auto activeParent = ActiveObjects::instance().activeParentDataSource();
  auto activeData = ActiveObjects::instance().activeDataSource();

  // Read in the template file and apply it to the current data source
  activeParent->deserialize(doc.object());
  // Load the default modules on the output if there are none
  bool noModules = ModuleManager::instance().findModulesGeneric(activeData, nullptr).isEmpty();
  if (noModules && activeData != activeParent) {
    activeParent->pipeline()->addDefaultModules(activeData);
    std::cout << "Default mods problem" << std::endl;
  }

  return true;
}

bool SaveLoadTemplateReaction::saveTemplate(const QString& fileName)
{
  QFileInfo info(fileName);
  QFile saveFile(fileName);
  if (!saveFile.open(QIODevice::WriteOnly)) {
    qWarning("Couldn't open save file.");
    return false;
  }

  DataSource* activeParent = ActiveObjects::instance().activeParentDataSource();
  QJsonObject state = activeParent->serialize();
  QJsonObject json;
  // Save any modules loaded on the parent data source
  if (state.contains("modules")) {
    json["modules"] = state.value("modules");
  }

  if (state.contains("operators")) {
    QJsonArray ops;
    foreach (QJsonValue val, state["operators"].toArray()) {
      QJsonObject temp;
      foreach (QString key, val.toObject().keys()) {
        qDebug() << "Key: " << key << endl;
        // Save the operators
        if (key != QString("dataSources")) {
          qDebug() << "Not dataSources: " << key << endl;
          temp.insert(key, val.toObject().value(key));
        } else {
          // If there are modules loaded on the child data source, save those as well
          QJsonValue dataSources = val.toObject().value("dataSources");
          QJsonObject modules = {{"modules", dataSources.toArray()[0].toObject().value("modules")}};
          QJsonArray arr = { modules };
          temp.insert("dataSources", arr);
        }
      }
      ops.push_back(temp);
    }
    json["operators"] = ops;
  }

  QJsonDocument doc(json);
  auto writeSuccess = saveFile.write(doc.toJson());
  return !json.isEmpty() && writeSuccess != -1;
}

} // namespace tomviz
<|endoftext|>


<commit_before>#include"ics3/ics3.hpp"

#include"core.hpp"
#include"ics3/eeprom.hpp"
#include"ics3/parameter.hpp"
#include"ics3/id.hpp"

static inline ics::Angle::rawType getReceiveAngle(const ics::Core::Container& rx) noexcept {
  return static_cast<ics::Angle::rawType>((rx[4] << 7) | rx[5]);
}

static inline ics::Core::value getCmd(const int head, const ics::ID& id) {
  return head | id.get();
}

ics::ICS3::ICS3(const std::string& path, const Baudrate& baudrate)
: core {Core::getCore(path, baudrate.getSpeed())}
{}

ics::Angle ics::ICS3::move(const ID& id, Angle angle) {
  static Core::Container tx(3), rx(6); // cache for runtime speed
  const uint16_t send {angle.getRaw()};
  tx[0] = getCmd(0x80, id);
  tx[1] = 0x7F & (send >> 7);
  tx[2] = 0x7F & send;
  core->communicate(tx, rx); // throw std::runtime_error
  angle.rawData = getReceiveAngle(rx); // avoid invalid check. need friend
  return angle;
}

ics::Angle ics::ICS3::free(const ID& id, Angle unit) {
  static Core::Container tx(3), rx(6); // cache for runtime speed
  tx[0] = getCmd(0x80, id); // tx[1] == tx[2] == 0
  core->communicate(tx, rx); // throw std::runtime_error
  unit.rawData = getReceiveAngle(rx); // avoid invalid check. need friend
  return unit;
}

ics::Parameter ics::ICS3::get(const ID& id, const Parameter& type) {
  Core::Container tx(2), rx(5);
  tx[0] = getCmd(0xA0, id);
  tx[1] = type.getSubcommand();
  core->communicate(tx, rx); // throw std::runtime_error
  return Parameter::newParameter(type, rx[4]);
}

void ics::ICS3::set(const ID& id, const Parameter& param) {
  Core::Container tx(3), rx(6);
  tx[0] = getCmd(0xC0, id);
  tx[1] = param.getSubcommand();
  tx[2] = param.get();
  core->communicate(tx, rx); // throw std::runtime_error
}

ics::EepRom ics::ICS3::getRom(const ID& id) {
  Core::Container tx(2), rx(68);
  tx[0] = getCmd(0xA0, id); // tx[1] == 0
  core->communicate(tx, rx); // throw std::runtime_error
  std::array<uint8_t, 64> romData;
  std::copy(rx.cbegin() + 4, rx.cend(), romData.begin());
  return EepRom {romData}; // need friend
}

void ics::ICS3::setRom(const ID& id, const EepRom& rom) {
  Core::Container tx(66), rx(68);
  tx[0] = getCmd(0xC0, id); // tx[1] == 0
  rom.write(tx.begin() + 2);
  core->communicate(tx, rx); // throw std::runtime_error
}

ics::ID ics::ICS3::getID() {
  constexpr Core::IDContainerTx tx {0xFF, 0x00, 0x00, 0x00};
  Core::IDContainerRx rx;
  core->communicateID(tx, rx);
  return ID {static_cast<uint8_t>(0x1F & rx[4])};
}

void ics::ICS3::setID(const ID& id) {
  const Core::IDContainerTx tx {getCmd(0xE0, id), 1, 1, 1};
  Core::IDContainerRx rx;
  core->communicateID(tx, rx);
}
<commit_msg>Update get method with const tx<commit_after>#include"ics3/ics3.hpp"

#include"core.hpp"
#include"ics3/eeprom.hpp"
#include"ics3/parameter.hpp"
#include"ics3/id.hpp"

static inline ics::Angle::rawType getReceiveAngle(const ics::Core::Container& rx) noexcept {
  return static_cast<ics::Angle::rawType>((rx[4] << 7) | rx[5]);
}

static inline ics::Core::value getCmd(const int head, const ics::ID& id) {
  return head | id.get();
}

ics::ICS3::ICS3(const std::string& path, const Baudrate& baudrate)
: core {Core::getCore(path, baudrate.getSpeed())}
{}

ics::Angle ics::ICS3::move(const ID& id, Angle angle) {
  static Core::Container tx(3), rx(6); // cache for runtime speed
  const uint16_t send {angle.getRaw()};
  tx[0] = getCmd(0x80, id);
  tx[1] = 0x7F & (send >> 7);
  tx[2] = 0x7F & send;
  core->communicate(tx, rx); // throw std::runtime_error
  angle.rawData = getReceiveAngle(rx); // avoid invalid check. need friend
  return angle;
}

ics::Angle ics::ICS3::free(const ID& id, Angle unit) {
  static Core::Container tx(3), rx(6); // cache for runtime speed
  tx[0] = getCmd(0x80, id); // tx[1] == tx[2] == 0
  core->communicate(tx, rx); // throw std::runtime_error
  unit.rawData = getReceiveAngle(rx); // avoid invalid check. need friend
  return unit;
}

ics::Parameter ics::ICS3::get(const ID& id, const Parameter& type) {
  const Core::Container tx {getCmd(0xA0, id), type.getSubcommand()};
  Core::Container rx(5);
  core->communicate(tx, rx); // throw std::runtime_error
  return Parameter::newParameter(type, rx[4]);
}

void ics::ICS3::set(const ID& id, const Parameter& param) {
  Core::Container tx(3), rx(6);
  tx[0] = getCmd(0xC0, id);
  tx[1] = param.getSubcommand();
  tx[2] = param.get();
  core->communicate(tx, rx); // throw std::runtime_error
}

ics::EepRom ics::ICS3::getRom(const ID& id) {
  Core::Container tx(2), rx(68);
  tx[0] = getCmd(0xA0, id); // tx[1] == 0
  core->communicate(tx, rx); // throw std::runtime_error
  std::array<uint8_t, 64> romData;
  std::copy(rx.cbegin() + 4, rx.cend(), romData.begin());
  return EepRom {romData}; // need friend
}

void ics::ICS3::setRom(const ID& id, const EepRom& rom) {
  Core::Container tx(66), rx(68);
  tx[0] = getCmd(0xC0, id); // tx[1] == 0
  rom.write(tx.begin() + 2);
  core->communicate(tx, rx); // throw std::runtime_error
}

ics::ID ics::ICS3::getID() {
  constexpr Core::IDContainerTx tx {0xFF, 0x00, 0x00, 0x00};
  Core::IDContainerRx rx;
  core->communicateID(tx, rx);
  return ID {static_cast<uint8_t>(0x1F & rx[4])};
}

void ics::ICS3::setID(const ID& id) {
  const Core::IDContainerTx tx {getCmd(0xE0, id), 1, 1, 1};
  Core::IDContainerRx rx;
  core->communicateID(tx, rx);
}
<|endoftext|>


<commit_before>#include "translate.hxx"

#include <list>
#if TEST_LAYOUT
#include <stdio.h>
#endif

#include <osl/process.h>
#include <unotools/bootstrap.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/ucbhelper.hxx>
#include <vcl/svapp.hxx>

#include "proplist.hxx"

namespace layoutimpl
{
namespace css = ::com::sun::star;
using namespace css;
using ::rtl::OUString;
using ::utl::LocalFileHelper;
using ::utl::UCBContentHelper;
using ::utl::Bootstrap;

static std::list<OUString>
getLocaleSubdirList( lang::Locale const& rLocale )
{
    std::list<OUString> aSubdirs;
    aSubdirs.push_front( OUString::createFromAscii( "." ) );
    aSubdirs.push_front( OUString::createFromAscii( "en_US" ) );
    if ( rLocale.Language.getLength() )
        aSubdirs.push_front( rLocale.Language );
    if ( rLocale.Country.getLength() )
    {
        OUString aLocaleCountry = rLocale.Language
            + OUString::createFromAscii( "_" )
            + rLocale.Country;
        aSubdirs.push_front( aLocaleCountry );
        if ( rLocale.Variant.getLength() )
            aSubdirs.push_front( aLocaleCountry
                                 + OUString::createFromAscii( "." )
                                 + rLocale.Variant );
    }
    return aSubdirs;
}

static bool
fileExists( String const& aFile )
{
    String aUrl;
    LocalFileHelper::ConvertPhysicalNameToURL( aFile, aUrl );
    return UCBContentHelper::Exists( aUrl );
}

static OUString
getFirstExisting( OUString const& aDir, std::list<OUString> const& aSubDirs,
                  OUString const& aXMLName )
{
    static OUString const aSlash = OUString::createFromAscii( "/" );
    String aResult;
    for ( std::list<OUString>::const_iterator i = aSubDirs.begin();
          i != aSubDirs.end(); i++ )
    {
        String aFile = aDir + aSlash + *i + aSlash + aXMLName;
#if TEST_LAYOUT
        printf( "testing: %s\n", OUSTRING_CSTR( aFile ) );
#endif
        if ( fileExists( aFile ) )
            return aFile;
    }
    return OUString();
}

/*  FIXME: IWBN to share code with impimagetree.cxx, also for reading
  from zip files.  */
OUString
readRightTranslation( OUString const& aXMLName )
{
    String aXMLFile;
    std::list<OUString> aSubdirs
        = getLocaleSubdirList( Application::GetSettings().GetUILocale() );
#if TEST_LAYOUT // read from cwd first
    OUString aCurrentWorkingUrl;
    osl_getProcessWorkingDir( &aCurrentWorkingUrl.pData );
    String aCurrentWorkingDir;
    LocalFileHelper::ConvertURLToPhysicalName( aCurrentWorkingUrl, aCurrentWorkingDir );
    aXMLFile = getFirstExisting( aCurrentWorkingDir, aSubdirs, aXMLName );
    if ( aXMLFile.Len() )
        ;
    else
#endif /* TEST_LAYOUT */
    {
        OUString aShareUrl;
        Bootstrap::locateSharedData( aShareUrl );
        OUString aXMLUrl = aShareUrl + OUString::createFromAscii( "/layout" );
        String aXMLDir;
        LocalFileHelper::ConvertURLToPhysicalName( aXMLUrl, aXMLDir );
        aXMLFile = getFirstExisting( aXMLDir, aSubdirs, aXMLName );
    }

#if TEST_LAYOUT
    printf( "FOUND:%s\n", OUSTRING_CSTR ( OUString (aXMLFile) ) );
#endif /* TEST_LAYOUT */
    return aXMLFile;
}

} // namespace layoutimpl
<commit_msg>INTEGRATION: CWS sb87 (1.2.14); FILE MERGED 2008/04/10 07:25:27 sb 1.2.14.1: #i87730# use tools::getProcessWorkingDir instead of osl_getProcessWorkingDir (in TEST_LAYOUT code; enabling it would require to link against TOOLSLIB)<commit_after>#include "translate.hxx"

#include <list>
#if TEST_LAYOUT
#include <stdio.h>
#include "tools/getprocessworkingdir.hxx"
#endif

#include <unotools/bootstrap.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/ucbhelper.hxx>
#include <vcl/svapp.hxx>

#include "proplist.hxx"

namespace layoutimpl
{
namespace css = ::com::sun::star;
using namespace css;
using ::rtl::OUString;
using ::utl::LocalFileHelper;
using ::utl::UCBContentHelper;
using ::utl::Bootstrap;

static std::list<OUString>
getLocaleSubdirList( lang::Locale const& rLocale )
{
    std::list<OUString> aSubdirs;
    aSubdirs.push_front( OUString::createFromAscii( "." ) );
    aSubdirs.push_front( OUString::createFromAscii( "en_US" ) );
    if ( rLocale.Language.getLength() )
        aSubdirs.push_front( rLocale.Language );
    if ( rLocale.Country.getLength() )
    {
        OUString aLocaleCountry = rLocale.Language
            + OUString::createFromAscii( "_" )
            + rLocale.Country;
        aSubdirs.push_front( aLocaleCountry );
        if ( rLocale.Variant.getLength() )
            aSubdirs.push_front( aLocaleCountry
                                 + OUString::createFromAscii( "." )
                                 + rLocale.Variant );
    }
    return aSubdirs;
}

static bool
fileExists( String const& aFile )
{
    String aUrl;
    LocalFileHelper::ConvertPhysicalNameToURL( aFile, aUrl );
    return UCBContentHelper::Exists( aUrl );
}

static OUString
getFirstExisting( OUString const& aDir, std::list<OUString> const& aSubDirs,
                  OUString const& aXMLName )
{
    static OUString const aSlash = OUString::createFromAscii( "/" );
    String aResult;
    for ( std::list<OUString>::const_iterator i = aSubDirs.begin();
          i != aSubDirs.end(); i++ )
    {
        String aFile = aDir + aSlash + *i + aSlash + aXMLName;
#if TEST_LAYOUT
        printf( "testing: %s\n", OUSTRING_CSTR( aFile ) );
#endif
        if ( fileExists( aFile ) )
            return aFile;
    }
    return OUString();
}

/*  FIXME: IWBN to share code with impimagetree.cxx, also for reading
  from zip files.  */
OUString
readRightTranslation( OUString const& aXMLName )
{
    String aXMLFile;
    std::list<OUString> aSubdirs
        = getLocaleSubdirList( Application::GetSettings().GetUILocale() );
#if TEST_LAYOUT // read from cwd first
    OUString aCurrentWorkingUrl;
    tools::getProcessWorkingDir( &aCurrentWorkingUrl );
    String aCurrentWorkingDir;
    LocalFileHelper::ConvertURLToPhysicalName( aCurrentWorkingUrl, aCurrentWorkingDir );
    aXMLFile = getFirstExisting( aCurrentWorkingDir, aSubdirs, aXMLName );
    if ( aXMLFile.Len() )
        ;
    else
#endif /* TEST_LAYOUT */
    {
        OUString aShareUrl;
        Bootstrap::locateSharedData( aShareUrl );
        OUString aXMLUrl = aShareUrl + OUString::createFromAscii( "/layout" );
        String aXMLDir;
        LocalFileHelper::ConvertURLToPhysicalName( aXMLUrl, aXMLDir );
        aXMLFile = getFirstExisting( aXMLDir, aSubdirs, aXMLName );
    }

#if TEST_LAYOUT
    printf( "FOUND:%s\n", OUSTRING_CSTR ( OUString (aXMLFile) ) );
#endif /* TEST_LAYOUT */
    return aXMLFile;
}

} // namespace layoutimpl
<|endoftext|>


<commit_before>#include "SPECIFIC.H"

#include "GPU.H"
#include "PSXPCINPUT.H"
#include "REQUEST.H"
#include "SOUND.H"
#include "SAVEGAME.H"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "..\SPEC_PSX\SPECIFIC.H"

static struct REQUESTER PauseReq = { 0xA4, 0x08, 0x03, 0x00, 0x05, 0x08, 0x03, 0x0A, 0x00, { 0xDE, 0xDF, 0xE0, 0x00, 0x00 } };
static struct REQUESTER AdjustReq = { 0xE6, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00, 0x00, 0x00, 0x00 } };
static struct REQUESTER QuitReq = { 0xE2, 0x08, 0x02, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,{ 0xA0, 0xA1, 0x00, 0x00, 0x00 } };
static struct REQUESTER StatisticsReq = { 0xB2, 0x08, 0x01, 0x01, 0x05, 0x00, 0x00, 0x00, 0x01,{ 0xEE, 0x00, 0x00, 0x00, 0x00 } };

static unsigned short PadStrings[5][8] =
{
	{ 0x00BC, 0x00BE, 0x00BD, 0x00BF, 0x00C1, 0x00C2, 0x00C0, 0x00C3 },
	{ 0x00BE, 0x00BD, 0x00BF, 0x00BC, 0x00C2, 0x00C1, 0x00C3, 0x00C0 },
	{ 0x00BD, 0x00BF, 0x00BE, 0x00BC, 0x00C0, 0x00C3, 0x00C1, 0x00C2 },
	{ 0x00BF, 0x00BC, 0x00C1, 0x00BE, 0x00BD, 0x00C2, 0x00C0, 0x00C3 },
	{ 0x00C0, 0x00C1, 0x00C3, 0x00C2, 0x00BE, 0x00BF, 0x00BC, 0x00BD }
};

static unsigned char PauseMenuNum;
unsigned short AnimComp;
short AnimatingTexturesVOffset;
struct REQUESTER SettingsReq = { 0xE0, 0x08, 0x05, 0x00, 0x05, 0x00, 0x03, 0x03, 0x00,{ 0xE4, 0xE5, 0xE7, 0xE3, 0xEB } };
struct REQUESTER ConfigReq = { 0xE7, 0x08, 0x03, 0x01, 0x05, 0x00, 0x00, 0x02, 0x01,{ 0xED, 0xE8, 0xE9, 0x00, 0x00 } };
unsigned char SoundFXVolume;
unsigned short nAnimTextureRanges;
unsigned short* AnimTextureRanges;
unsigned short nAnimUVRanges;
int GtSFXEnabled;
short AnimatingTexturesV[16][8][3];

void DisplayStatsUCunt()//61928(<), 625A8(<) (F)
{
	Requester(&StatisticsReq);
}

short S_Death()//61658, 622C8
{
	S_Warn("[S_Death] - Unimplemented!\n");
	return 0;
}

void gInit()//615CC, 6210C
{
	S_Warn("[gInit] - Unimplemented!\n");
}

int DoPauseMenu()//60F34, 61A68
{
	S_Warn("[DoPauseMenu] - Unimplemented!\n");
	return 0;
}

void DisplayConfig(int x, int y)//6080C, 61340
{
	S_Warn("[DisplayConfig] - Unimplemented!\n");
}

void S_ExitSystem(char* exit_message)//607C8, *
{
	printf(exit_message);
	exit(EXIT_FAILURE);
}

void S_Warn(char* warning_message)
{
	printf(warning_message);
#ifndef NDEBUG
	//assert(0);
#endif
}

int S_SoundStopAllSamples()//91D34, 93D80
{
	int ret;

	if (GtSFXEnabled == 0)
	{
		return 0;
	}

	return ret;
}

long S_DumpScreen()//607A8(<), 61320(<) (F)
{
	return GPU_FlipNoIdle();
}

void S_control_screen_position()//6068C(<), 61204(<)
{
	if (input & 1)
	{
		savegame.ScreenY--;

		if ((savegame.ScreenY << 16) < 0)
		{
			savegame.ScreenY = 0;
		}
	}
	else if (input & 2)
	{
		//loc_606D0
		savegame.ScreenY++;

		if (savegame.ScreenY > 40)
		{
			savegame.ScreenY = 40;
		}
	}

	//loc_60708
	if (input & 4)
	{
		savegame.ScreenX--;

		if (savegame.ScreenX < -10)
		{
			savegame.ScreenX = -10;
		}

	}
	else if (input & 8)
	{
		//loc_60750
		savegame.ScreenX++;

		if (savegame.ScreenX > 32)
		{
			savegame.ScreenX = 32;
		}
	}

	//loc_60784
	GPU_SetScreenPosition(savegame.ScreenX, savegame.ScreenY);
}

void S_AnimateTextures(long num_frames)
{
	S_Warn("[S_AnimateTextures] - Unimplemented!\n");
}

void S_SetupClutAdder(long unk)
{
	S_Warn("[S_SetupClutAdder] - Unimplemented!\n");
}

void S_DrawFootPrints()
{
	S_Warn("[S_DrawFootPrints] - Unimplemented!\n");
}

void S_DrawSparks()
{
	S_Warn("[S_DrawSparks] - Unimplemented!\n");
}<commit_msg>fixed the previous fix that fixed the fix of the other previous fix-fixer fix<commit_after>#include "SPECIFIC.H"

#include "GPU.H"
#include "PSXPCINPUT.H"
#include "REQUEST.H"
#include "SOUND.H"
#include "SAVEGAME.H"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

static struct REQUESTER PauseReq = { 0xA4, 0x08, 0x03, 0x00, 0x05, 0x08, 0x03, 0x0A, 0x00, { 0xDE, 0xDF, 0xE0, 0x00, 0x00 } };
static struct REQUESTER AdjustReq = { 0xE6, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00, 0x00, 0x00, 0x00 } };
static struct REQUESTER QuitReq = { 0xE2, 0x08, 0x02, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,{ 0xA0, 0xA1, 0x00, 0x00, 0x00 } };
static struct REQUESTER StatisticsReq = { 0xB2, 0x08, 0x01, 0x01, 0x05, 0x00, 0x00, 0x00, 0x01,{ 0xEE, 0x00, 0x00, 0x00, 0x00 } };

static unsigned short PadStrings[5][8] =
{
	{ 0x00BC, 0x00BE, 0x00BD, 0x00BF, 0x00C1, 0x00C2, 0x00C0, 0x00C3 },
	{ 0x00BE, 0x00BD, 0x00BF, 0x00BC, 0x00C2, 0x00C1, 0x00C3, 0x00C0 },
	{ 0x00BD, 0x00BF, 0x00BE, 0x00BC, 0x00C0, 0x00C3, 0x00C1, 0x00C2 },
	{ 0x00BF, 0x00BC, 0x00C1, 0x00BE, 0x00BD, 0x00C2, 0x00C0, 0x00C3 },
	{ 0x00C0, 0x00C1, 0x00C3, 0x00C2, 0x00BE, 0x00BF, 0x00BC, 0x00BD }
};

static unsigned char PauseMenuNum;
unsigned short AnimComp;
short AnimatingTexturesVOffset;
struct REQUESTER SettingsReq = { 0xE0, 0x08, 0x05, 0x00, 0x05, 0x00, 0x03, 0x03, 0x00,{ 0xE4, 0xE5, 0xE7, 0xE3, 0xEB } };
struct REQUESTER ConfigReq = { 0xE7, 0x08, 0x03, 0x01, 0x05, 0x00, 0x00, 0x02, 0x01,{ 0xED, 0xE8, 0xE9, 0x00, 0x00 } };
unsigned char SoundFXVolume;
unsigned short nAnimTextureRanges;
unsigned short* AnimTextureRanges;
unsigned short nAnimUVRanges;
int GtSFXEnabled;
short AnimatingTexturesV[16][8][3];

void DisplayStatsUCunt()//61928(<), 625A8(<) (F)
{
	Requester(&StatisticsReq);
}

short S_Death()//61658, 622C8
{
	S_Warn("[S_Death] - Unimplemented!\n");
	return 0;
}

void gInit()//615CC, 6210C
{
	S_Warn("[gInit] - Unimplemented!\n");
}

int DoPauseMenu()//60F34, 61A68
{
	S_Warn("[DoPauseMenu] - Unimplemented!\n");
	return 0;
}

void DisplayConfig(int x, int y)//6080C, 61340
{
	S_Warn("[DisplayConfig] - Unimplemented!\n");
}

void S_ExitSystem(char* exit_message)//607C8, *
{
	printf(exit_message);
	exit(EXIT_FAILURE);
}

void S_Warn(char* warning_message)
{
	printf(warning_message);
#ifndef NDEBUG
	//assert(0);
#endif
}

int S_SoundStopAllSamples()//91D34, 93D80
{
	int ret;

	if (GtSFXEnabled == 0)
	{
		return 0;
	}

	return ret;
}

long S_DumpScreen()//607A8(<), 61320(<) (F)
{
	return GPU_FlipNoIdle();
}

void S_control_screen_position()//6068C(<), 61204(<)
{
	if (input & 1)
	{
		savegame.ScreenY--;

		if ((savegame.ScreenY << 16) < 0)
		{
			savegame.ScreenY = 0;
		}
	}
	else if (input & 2)
	{
		//loc_606D0
		savegame.ScreenY++;

		if (savegame.ScreenY > 40)
		{
			savegame.ScreenY = 40;
		}
	}

	//loc_60708
	if (input & 4)
	{
		savegame.ScreenX--;

		if (savegame.ScreenX < -10)
		{
			savegame.ScreenX = -10;
		}

	}
	else if (input & 8)
	{
		//loc_60750
		savegame.ScreenX++;

		if (savegame.ScreenX > 32)
		{
			savegame.ScreenX = 32;
		}
	}

	//loc_60784
	GPU_SetScreenPosition(savegame.ScreenX, savegame.ScreenY);
}

void S_AnimateTextures(long num_frames)
{
	S_Warn("[S_AnimateTextures] - Unimplemented!\n");
}

void S_SetupClutAdder(long unk)
{
	S_Warn("[S_SetupClutAdder] - Unimplemented!\n");
}

void S_DrawFootPrints()
{
	S_Warn("[S_DrawFootPrints] - Unimplemented!\n");
}

void S_DrawSparks()
{
	S_Warn("[S_DrawSparks] - Unimplemented!\n");
}<|endoftext|>


<commit_before><commit_msg>ATO-418 - Add: addopt format for the multi-pad canvas * title size and labels font size   * 2x2 pads   * 3x3 pads<commit_after><|endoftext|>


<commit_before><commit_msg>ATO-83 - Bug fix in the alarm alias definition makeAnchorAlias * < instead of > * fix: syntax error in the message<commit_after><|endoftext|>


<commit_before>

#ifndef _CONF_H_
#define _CONF_H_

#include "utility.hpp"

#define VE_VERSION "V2015-0101"
#define VE_INFO "vdceye Manager 2015 R1"

#ifdef WIN32
#define VE_NVR_CLIENT
#else
#define VE_NVR
#endif

/* NVR Client feature */
#ifdef VE_NVR_CLIENT
#define VE_RECORDER_MGR_CLIENT_SUPPORT
#endif

/* NVR feature */
#ifdef VE_NVR
#define VE_RECORDER_MGR_SERVER_SUPPORT
#endif

#define CONF_NAME_MAX 128
/* support Camera num */
#define CONF_MAP_MAX 4096
#define CONF_USER_PASSWORD_MAX 1024
#define CONF_PATH_MAX 1024
/* 0xFF FFFF to 0xFFFF FFFF is for status for the map */
#define CONF_MAP_INVALID_MIN 0xFFFFFF
#define CONF_KEY_STR_MAX 16

/* Support VMS(site, recorder) num */
#define CONF_VMS_NUM_MAX 128
#define CONF_VIEW_NUM_MAX 128
/* IP camera Group max num */
#define CONF_VGROUP_NUM_MAX 128

#define VSC_CONF_KEY "ConfVSCSystem"
#define VSC_CONF_LIC_KEY "ConfVSCLicense"
#define VSC_CONF_CHANNEL_KEY "ConfVSCDevice"
#define VSC_CONF_VIPC_KEY "ConfVSCVIPC"
#define VSC_CONF_VMS_KEY "ConfVSCVms"
#define VSC_CONF_VIEW_KEY "ConfVSCView"
#define VSC_CONF_VGROUP_KEY "ConfVSCVGroup"
#define VSC_CONF_HDFS_RECORD_KEY "ConfVSCHdfsRec"
#define VSC_CONF_PARAM_MAX 1024
#define VSC_CONF_PARAM_S_MAX 128
/* Max camera in one view */
#define VSC_CONF_VIEW_CH_MAX 256
/* Max camera in one Group */
#define VSC_CONF_VGROUP_CH_MAX 256

typedef enum
{
    VSC_DEVICE_CAM = 1,
    VSC_DEVICE_RECORDER,

    VSC_DEVICE_LAST
} VSCDeviceType;

/* Device Type */
typedef enum
{
    VSC_SUB_DEVICE_USB_CAM = 1,
    VSC_SUB_DEVICE_FILE,
    VSC_SUB_DEVICE_RTSP,
    VSC_SUB_DEVICE_ONVIF,
    VSC_SUB_DEVICE_ONVIF_RECODER,

    VSC_SUB_DEVICE_LAST
} VSCDeviceSubType;

typedef enum
{
    VSC_VMS_RECORDER = 1,
    VSC_VMS_SITE,
    VSC_VMS_VIRTUL_IPC,

    VSC_VMS_LAST
} VSCVmsType;

typedef enum
{
    VSC_SUB_VMS_PG = 1,
    VSC_SUB_VMS_ZB,
    VSC_SUB_VIPC_FILE,
    VSC_SUB_VIPC_LIVE,

    VSC_SUB_VMS_LAST
} VSCVmsSubType;

/* Control command */
typedef enum
{
    LAYOUT_MODE_1 = 1,
    LAYOUT_MODE_2X2,
    LAYOUT_MODE_3X3,
    LAYOUT_MODE_4X4,
    LAYOUT_MODE_6,
    LAYOUT_MODE_8,
    LAYOUT_MODE_12p1,
    LAYOUT_MODE_5x5,
    LAYOUT_MODE_6x6,
    LAYOUT_MODE_8x8,
    LAYOUT_MODE_ONE,
    LAYOUT_MODE_LAST
} VideoWallLayoutMode;

#pragma pack(push,  1 )
typedef struct __VSCConfSystemKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfSystemKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_KEY);
    }
}VSCConfSystemKey;

typedef struct __VSCConfLicenseKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfLicenseKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_LIC_KEY);
    }
}VSCConfLicenseKey;

typedef struct __VSCConfDeviceKey {
    u32 nId;
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfDeviceKey(u32 id)
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_CHANNEL_KEY);
        nId = id;
    }
}VSCConfDeviceKey;

typedef struct __VSCConfVIPCKey {
    u32 nId;
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfVIPCKey(u32 id)
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VIPC_KEY);
        nId = id;
    }
}VSCConfVIPCKey;

typedef struct __VSCConfVmsKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfVmsKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VMS_KEY);
    }
}VSCConfVmsKey;

typedef struct __VSCConfViewKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfViewKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VIEW_KEY);
    }
}VSCConfViewKey;

/* Camera Group key */
typedef struct __VSCConfGroupKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfGroupKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VGROUP_KEY);
    }
}VSCConfVGroupKey;

/* HDFS Reocrd key */
typedef struct __VSCConfHdfsRecordKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfHdfsRecordKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_HDFS_RECORD_KEY);
    }
}VSCConfHdfsRecordKey;

typedef struct __VSCConfData__ {
    u32 DeviceMap[CONF_MAP_MAX];
    u32 Language;
    u32 DeviceNum;
    u32 VIPCMap[CONF_MAP_MAX];
    u32 VIPCNum;
}VSCConfData__;

typedef struct __VSCConfData {
    union {
        VSCConfData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCConfData;

typedef struct __VSCDeviceData__ {
	u32 nId;
	VSCDeviceType nType;
	VSCDeviceSubType nSubType;

	s8 Name[CONF_NAME_MAX];
	s8 Param[VSC_CONF_PARAM_MAX];

	s8 IP[VSC_CONF_PARAM_MAX];
	s8 Port[VSC_CONF_PARAM_MAX];
	s8 User[VSC_CONF_PARAM_MAX];
	s8 Password[VSC_CONF_PARAM_MAX];

	/* Camera Param */
	s8 RtspLocation[VSC_CONF_PARAM_MAX];
	s8 FileLocation[VSC_CONF_PARAM_MAX];
	s8 OnvifAddress[VSC_CONF_PARAM_MAX];
	s8 CameraIndex[VSC_CONF_PARAM_MAX];/* This is For USB Camera */

	u32 UseProfileToken;/* 1 stand for use, 0 stand for do not use */
	s8 OnvifProfileToken[VSC_CONF_PARAM_MAX];

	/* Recording */
	u32 Recording;/* 1 stand for recording, 0 stand for do record */
	u32 GroupId;
	u32 HdfsRecording;/* 1 stand for recording, 0 stand for do record */
}VSCDeviceData__;

typedef struct __VSCConfHdfsRecordData__ {
	s8 NameNode[VSC_CONF_PARAM_MAX];
	s8 Port[VSC_CONF_PARAM_MAX];
	s8 User[VSC_CONF_PARAM_MAX];
	s8 Password[VSC_CONF_PARAM_MAX];
	int FileInterval;/* In Seconds */
}VSCConfHdfsRecordData__;

typedef struct __VSCVmsDataItem__ {
	u32 nId;
	VSCVmsType nType;
	VSCVmsSubType nSubType;

	s8 Name[CONF_NAME_MAX];
	s8 Param[VSC_CONF_PARAM_MAX];

	s8 IP[VSC_CONF_PARAM_MAX];
	s8 Port[VSC_CONF_PARAM_MAX];
	s8 User[VSC_CONF_PARAM_MAX];
	s8 Password[VSC_CONF_PARAM_MAX];

	s8 OnvifAddress[VSC_CONF_PARAM_MAX];
	u32 GroupId;
	u32 Used;/* 1 stand for used, 0 stand for not used */
}VSCVmsDataItem;

typedef struct __VSCViewDataItem__ {
	u32 nId;
	s8 Name[CONF_NAME_MAX];
	/* Map for this view */
	u32 Map[VSC_CONF_VIEW_CH_MAX];
	VideoWallLayoutMode Mode;
	u32 Used;/* 1 stand for used, 0 stand for not used */
}VSCViewDataItem;

/* IP Camera Group */
typedef struct __VSCVGroupDataItem__ {
	u32 nId;
	s8 Name[CONF_NAME_MAX];
	/* Map for this group */
	u32 Map[VSC_CONF_VGROUP_CH_MAX];
	u32 Used;/* 1 stand for used, 0 stand for not used */
}VSCVGroupDataItem;

typedef struct __VSCVIPCDataItem__ {
	u32 nId;
	VSCVmsType nType;
	VSCVmsSubType nSubType;

	s8 Name[CONF_NAME_MAX];
	s8 Param[VSC_CONF_PARAM_S_MAX];
	s32 nStreamId;

	s8 IP[VSC_CONF_PARAM_S_MAX];
	s8 Port[VSC_CONF_PARAM_S_MAX];
	s8 User[VSC_CONF_PARAM_S_MAX];
	s8 Password[VSC_CONF_PARAM_S_MAX];

	s8 OnvifAddress[VSC_CONF_PARAM_S_MAX];
}VSCVIPCDataItem__;

typedef struct __VSCVmsData__ {
	VSCVmsDataItem vms[CONF_VMS_NUM_MAX];
}VSCVmsData__;

typedef struct __VSCViewData__ {
	VSCViewDataItem view[CONF_VIEW_NUM_MAX];
}VSCViewData__;

typedef struct __VSCVGroupData__ {
	VSCVGroupDataItem group[CONF_VGROUP_NUM_MAX];
}VSCVGroupData__;

typedef struct __VSCDeviceData {
    union {
        VSCDeviceData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCDeviceData;

typedef struct __VSCVmsData {
    union {
        VSCVmsData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCVmsData;

typedef struct __VSCViewData {
    union {
        VSCViewData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCViewData;

typedef struct __VSCVGroupData {
    union {
        VSCVGroupData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCVGroupData;

typedef struct __VSCVIPCData {
    union {
        VSCVIPCDataItem__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCVIPCData;

typedef struct __VSCHdfsRecordData {
    union {
        VSCConfHdfsRecordData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCHdfsRecordData;

inline void VSCVmsDataItemDefault(VSCVmsDataItem &item)
{
    sprintf(item.Name, "Recorder");

    strcpy(item.IP, "192.168.0.1");
    strcpy(item.Port, "80");
    strcpy(item.User, "admin");
    strcpy(item.Password, "admin");
    strcpy(item.Param, "none");
    item.Used = 0;
    item.nId = 0;
    item.GroupId = 0;
}

inline void VSCViewDataItemDefault(VSCViewDataItem &item)
{
    memset(&item, 0, sizeof(VSCViewDataItem));
    sprintf(item.Name, "View");
    item.Mode = LAYOUT_MODE_3X3;
}

inline void VSCVGroupDataItemDefault(VSCVGroupDataItem &item)
{
    memset(&item, 0, sizeof(VSCVGroupDataItem));
    sprintf(item.Name, "Group");
}

inline void VSCVIPCDataItemDefault(VSCVIPCDataItem__ &item)
{
    sprintf(item.Name, "Virutal IPC");

    strcpy(item.IP, "192.168.0.1");
    strcpy(item.Port, "8000");
    strcpy(item.User, "admin");
    strcpy(item.Password, "admin");
    item.nStreamId = 1;
}

inline void VSCHdfsRecordDataItemDefault(VSCConfHdfsRecordData__ &item)
{
    strcpy(item.NameNode, "default");
    strcpy(item.Port, "80");
    strcpy(item.User, "admin");
    strcpy(item.Password, "admin");
    item.FileInterval = 180;/* 3 mins */
}

#pragma pack(pop)

#endif /* _CONF_H_ */
<commit_msg>update version<commit_after>

#ifndef _CONF_H_
#define _CONF_H_

#include "utility.hpp"

#define VE_VERSION "r1.0.1-20150103"
#define VE_INFO "vdceye Manager r1.0.1 2015"

#ifdef WIN32
#define VE_NVR_CLIENT
#else
#define VE_NVR
#endif

/* NVR Client feature */
#ifdef VE_NVR_CLIENT
#define VE_RECORDER_MGR_CLIENT_SUPPORT
#endif

/* NVR feature */
#ifdef VE_NVR
#define VE_RECORDER_MGR_SERVER_SUPPORT
#endif

#define CONF_NAME_MAX 128
/* support Camera num */
#define CONF_MAP_MAX 4096
#define CONF_USER_PASSWORD_MAX 1024
#define CONF_PATH_MAX 1024
/* 0xFF FFFF to 0xFFFF FFFF is for status for the map */
#define CONF_MAP_INVALID_MIN 0xFFFFFF
#define CONF_KEY_STR_MAX 16

/* Support VMS(site, recorder) num */
#define CONF_VMS_NUM_MAX 128
#define CONF_VIEW_NUM_MAX 128
/* IP camera Group max num */
#define CONF_VGROUP_NUM_MAX 128

#define VSC_CONF_KEY "ConfVSCSystem"
#define VSC_CONF_LIC_KEY "ConfVSCLicense"
#define VSC_CONF_CHANNEL_KEY "ConfVSCDevice"
#define VSC_CONF_VIPC_KEY "ConfVSCVIPC"
#define VSC_CONF_VMS_KEY "ConfVSCVms"
#define VSC_CONF_VIEW_KEY "ConfVSCView"
#define VSC_CONF_VGROUP_KEY "ConfVSCVGroup"
#define VSC_CONF_HDFS_RECORD_KEY "ConfVSCHdfsRec"
#define VSC_CONF_PARAM_MAX 1024
#define VSC_CONF_PARAM_S_MAX 128
/* Max camera in one view */
#define VSC_CONF_VIEW_CH_MAX 256
/* Max camera in one Group */
#define VSC_CONF_VGROUP_CH_MAX 256

typedef enum
{
    VSC_DEVICE_CAM = 1,
    VSC_DEVICE_RECORDER,

    VSC_DEVICE_LAST
} VSCDeviceType;

/* Device Type */
typedef enum
{
    VSC_SUB_DEVICE_USB_CAM = 1,
    VSC_SUB_DEVICE_FILE,
    VSC_SUB_DEVICE_RTSP,
    VSC_SUB_DEVICE_ONVIF,
    VSC_SUB_DEVICE_ONVIF_RECODER,

    VSC_SUB_DEVICE_LAST
} VSCDeviceSubType;

typedef enum
{
    VSC_VMS_RECORDER = 1,
    VSC_VMS_SITE,
    VSC_VMS_VIRTUL_IPC,

    VSC_VMS_LAST
} VSCVmsType;

typedef enum
{
    VSC_SUB_VMS_PG = 1,
    VSC_SUB_VMS_ZB,
    VSC_SUB_VIPC_FILE,
    VSC_SUB_VIPC_LIVE,

    VSC_SUB_VMS_LAST
} VSCVmsSubType;

/* Control command */
typedef enum
{
    LAYOUT_MODE_1 = 1,
    LAYOUT_MODE_2X2,
    LAYOUT_MODE_3X3,
    LAYOUT_MODE_4X4,
    LAYOUT_MODE_6,
    LAYOUT_MODE_8,
    LAYOUT_MODE_12p1,
    LAYOUT_MODE_5x5,
    LAYOUT_MODE_6x6,
    LAYOUT_MODE_8x8,
    LAYOUT_MODE_ONE,
    LAYOUT_MODE_LAST
} VideoWallLayoutMode;

#pragma pack(push,  1 )
typedef struct __VSCConfSystemKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfSystemKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_KEY);
    }
}VSCConfSystemKey;

typedef struct __VSCConfLicenseKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfLicenseKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_LIC_KEY);
    }
}VSCConfLicenseKey;

typedef struct __VSCConfDeviceKey {
    u32 nId;
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfDeviceKey(u32 id)
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_CHANNEL_KEY);
        nId = id;
    }
}VSCConfDeviceKey;

typedef struct __VSCConfVIPCKey {
    u32 nId;
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfVIPCKey(u32 id)
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VIPC_KEY);
        nId = id;
    }
}VSCConfVIPCKey;

typedef struct __VSCConfVmsKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfVmsKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VMS_KEY);
    }
}VSCConfVmsKey;

typedef struct __VSCConfViewKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfViewKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VIEW_KEY);
    }
}VSCConfViewKey;

/* Camera Group key */
typedef struct __VSCConfGroupKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfGroupKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_VGROUP_KEY);
    }
}VSCConfVGroupKey;

/* HDFS Reocrd key */
typedef struct __VSCConfHdfsRecordKey {
    s8 Key[CONF_KEY_STR_MAX];
    __VSCConfHdfsRecordKey()
    {
        memset(Key, 0, CONF_KEY_STR_MAX);
        strcpy(Key, VSC_CONF_HDFS_RECORD_KEY);
    }
}VSCConfHdfsRecordKey;

typedef struct __VSCConfData__ {
    u32 DeviceMap[CONF_MAP_MAX];
    u32 Language;
    u32 DeviceNum;
    u32 VIPCMap[CONF_MAP_MAX];
    u32 VIPCNum;
}VSCConfData__;

typedef struct __VSCConfData {
    union {
        VSCConfData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCConfData;

typedef struct __VSCDeviceData__ {
	u32 nId;
	VSCDeviceType nType;
	VSCDeviceSubType nSubType;

	s8 Name[CONF_NAME_MAX];
	s8 Param[VSC_CONF_PARAM_MAX];

	s8 IP[VSC_CONF_PARAM_MAX];
	s8 Port[VSC_CONF_PARAM_MAX];
	s8 User[VSC_CONF_PARAM_MAX];
	s8 Password[VSC_CONF_PARAM_MAX];

	/* Camera Param */
	s8 RtspLocation[VSC_CONF_PARAM_MAX];
	s8 FileLocation[VSC_CONF_PARAM_MAX];
	s8 OnvifAddress[VSC_CONF_PARAM_MAX];
	s8 CameraIndex[VSC_CONF_PARAM_MAX];/* This is For USB Camera */

	u32 UseProfileToken;/* 1 stand for use, 0 stand for do not use */
	s8 OnvifProfileToken[VSC_CONF_PARAM_MAX];

	/* Recording */
	u32 Recording;/* 1 stand for recording, 0 stand for do record */
	u32 GroupId;
	u32 HdfsRecording;/* 1 stand for recording, 0 stand for do record */
}VSCDeviceData__;

typedef struct __VSCConfHdfsRecordData__ {
	s8 NameNode[VSC_CONF_PARAM_MAX];
	s8 Port[VSC_CONF_PARAM_MAX];
	s8 User[VSC_CONF_PARAM_MAX];
	s8 Password[VSC_CONF_PARAM_MAX];
	int FileInterval;/* In Seconds */
}VSCConfHdfsRecordData__;

typedef struct __VSCVmsDataItem__ {
	u32 nId;
	VSCVmsType nType;
	VSCVmsSubType nSubType;

	s8 Name[CONF_NAME_MAX];
	s8 Param[VSC_CONF_PARAM_MAX];

	s8 IP[VSC_CONF_PARAM_MAX];
	s8 Port[VSC_CONF_PARAM_MAX];
	s8 User[VSC_CONF_PARAM_MAX];
	s8 Password[VSC_CONF_PARAM_MAX];

	s8 OnvifAddress[VSC_CONF_PARAM_MAX];
	u32 GroupId;
	u32 Used;/* 1 stand for used, 0 stand for not used */
}VSCVmsDataItem;

typedef struct __VSCViewDataItem__ {
	u32 nId;
	s8 Name[CONF_NAME_MAX];
	/* Map for this view */
	u32 Map[VSC_CONF_VIEW_CH_MAX];
	VideoWallLayoutMode Mode;
	u32 Used;/* 1 stand for used, 0 stand for not used */
}VSCViewDataItem;

/* IP Camera Group */
typedef struct __VSCVGroupDataItem__ {
	u32 nId;
	s8 Name[CONF_NAME_MAX];
	/* Map for this group */
	u32 Map[VSC_CONF_VGROUP_CH_MAX];
	u32 Used;/* 1 stand for used, 0 stand for not used */
}VSCVGroupDataItem;

typedef struct __VSCVIPCDataItem__ {
	u32 nId;
	VSCVmsType nType;
	VSCVmsSubType nSubType;

	s8 Name[CONF_NAME_MAX];
	s8 Param[VSC_CONF_PARAM_S_MAX];
	s32 nStreamId;

	s8 IP[VSC_CONF_PARAM_S_MAX];
	s8 Port[VSC_CONF_PARAM_S_MAX];
	s8 User[VSC_CONF_PARAM_S_MAX];
	s8 Password[VSC_CONF_PARAM_S_MAX];

	s8 OnvifAddress[VSC_CONF_PARAM_S_MAX];
}VSCVIPCDataItem__;

typedef struct __VSCVmsData__ {
	VSCVmsDataItem vms[CONF_VMS_NUM_MAX];
}VSCVmsData__;

typedef struct __VSCViewData__ {
	VSCViewDataItem view[CONF_VIEW_NUM_MAX];
}VSCViewData__;

typedef struct __VSCVGroupData__ {
	VSCVGroupDataItem group[CONF_VGROUP_NUM_MAX];
}VSCVGroupData__;

typedef struct __VSCDeviceData {
    union {
        VSCDeviceData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCDeviceData;

typedef struct __VSCVmsData {
    union {
        VSCVmsData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCVmsData;

typedef struct __VSCViewData {
    union {
        VSCViewData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCViewData;

typedef struct __VSCVGroupData {
    union {
        VSCVGroupData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCVGroupData;

typedef struct __VSCVIPCData {
    union {
        VSCVIPCDataItem__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCVIPCData;

typedef struct __VSCHdfsRecordData {
    union {
        VSCConfHdfsRecordData__ conf;
        u8 whole[1024 * 128];
    } data;
}VSCHdfsRecordData;

inline void VSCVmsDataItemDefault(VSCVmsDataItem &item)
{
    sprintf(item.Name, "Recorder");

    strcpy(item.IP, "192.168.0.1");
    strcpy(item.Port, "80");
    strcpy(item.User, "admin");
    strcpy(item.Password, "admin");
    strcpy(item.Param, "none");
    item.Used = 0;
    item.nId = 0;
    item.GroupId = 0;
}

inline void VSCViewDataItemDefault(VSCViewDataItem &item)
{
    memset(&item, 0, sizeof(VSCViewDataItem));
    sprintf(item.Name, "View");
    item.Mode = LAYOUT_MODE_3X3;
}

inline void VSCVGroupDataItemDefault(VSCVGroupDataItem &item)
{
    memset(&item, 0, sizeof(VSCVGroupDataItem));
    sprintf(item.Name, "Group");
}

inline void VSCVIPCDataItemDefault(VSCVIPCDataItem__ &item)
{
    sprintf(item.Name, "Virutal IPC");

    strcpy(item.IP, "192.168.0.1");
    strcpy(item.Port, "8000");
    strcpy(item.User, "admin");
    strcpy(item.Password, "admin");
    item.nStreamId = 1;
}

inline void VSCHdfsRecordDataItemDefault(VSCConfHdfsRecordData__ &item)
{
    strcpy(item.NameNode, "localhost");//default for hdd
    strcpy(item.Port, "9010");//0 for hdd
    strcpy(item.User, "admin");
    strcpy(item.Password, "admin");
    item.FileInterval = 3;/* 3 mins */
}

#pragma pack(pop)

#endif /* _CONF_H_ */
<|endoftext|>