Newer
Older
/*
* Open Pixel Control server for Fadecandy
*
* Copyright (c) 2013 Micah Elizabeth Scott
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "rapidjson/document.h"
#include "usbdevice.h"
#include "libusbev.h"
#include <libusb.h>
#include <ev.h>
#include <netinet/in.h>
#include <netdb.h>
public:
typedef rapidjson::Value Value;
FCServer(rapidjson::Document &config);
const char *errorText() const { return mError.str().c_str(); }
bool hasError() const { return !mError.str().empty(); }
void start(struct ev_loop *loop);
private:
std::ostringstream mError;
const Value& mListen;
const Value& mColor;
const Value& mDevices;
struct addrinfo *mListenAddr;
OPCSink mOPCSink;
libusb_context *mUSB;
LibUSBEventBridge mUSBEvent;
std::vector<USBDevice*> mUSBDevices;
static void cbMessage(OPCSink::Message &msg, void *context);
static int cbHotplug(libusb_context *ctx, libusb_device *device, libusb_hotplug_event event, void *user_data);
void startUSB(struct ev_loop *loop);
void usbDeviceArrived(libusb_device *device);
void usbDeviceLeft(libusb_device *device);