hyperion.ng/src/hyperion-remote/JsonConnection.h

210 lines
5.6 KiB
C
Raw Normal View History

#pragma once
// stl includes
#include <string>
// Qt includes
#include <QColor>
#include <QImage>
#include <QTcpSocket>
2013-08-17 11:54:16 +02:00
#include <QMap>
// jsoncpp includes
#include <json/json.h>
// hyperion-remote includes
#include "ColorTransformValues.h"
#include "ColorCorrectionValues.h"
#include "ColorAdjustmentValues.h"
2013-09-09 04:54:13 +02:00
///
/// Connection class to setup an connection to the hyperion server and execute commands
2013-09-09 04:54:13 +02:00
///
2013-08-17 11:54:16 +02:00
class JsonConnection
{
public:
2013-09-09 04:54:13 +02:00
///
/// Constructor
///
2013-08-31 14:36:54 +02:00
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444)
/// @param printJson Boolean indicating if the sent and received json is written to stdout
2013-09-09 04:54:13 +02:00
///
2013-08-17 11:54:16 +02:00
JsonConnection(const std::string & address, bool printJson);
2013-08-31 14:36:54 +02:00
2013-09-09 04:54:13 +02:00
///
/// Destructor
///
2013-08-17 11:54:16 +02:00
~JsonConnection();
2013-09-09 04:54:13 +02:00
///
/// Set all leds to the specified color
///
2013-08-31 14:36:54 +02:00
/// @param color The color
/// @param priority The priority
/// @param duration The duration in milliseconds
2013-09-09 04:54:13 +02:00
///
void setColor(std::vector<QColor> color, int priority, int duration);
2013-09-09 04:54:13 +02:00
///
/// Set the leds according to the given image (assume the image is stretched to the display size)
///
2013-08-31 14:36:54 +02:00
/// @param image The image
/// @param priority The priority
/// @param duration The duration in milliseconds
2013-09-09 04:54:13 +02:00
///
2013-08-17 11:54:16 +02:00
void setImage(QImage image, int priority, int duration);
///
/// Start the given effect
///
/// @param effect The name of the effect
/// @param effectArgs The arguments to use instead of the default ones
/// @param priority The priority
/// @param duration The duration in milliseconds
///
void setEffect(const std::string & effectName, const std::string &effectArgs, int priority, int duration);
2013-09-09 04:54:13 +02:00
///
/// Retrieve a list of all occupied priority channels
///
2013-08-31 14:36:54 +02:00
/// @return String with the server info
2013-09-09 04:54:13 +02:00
///
2013-08-17 11:54:16 +02:00
QString getServerInfo();
2013-09-09 04:54:13 +02:00
///
/// Clear the given priority channel
///
2013-08-31 14:36:54 +02:00
/// @param priority The priority
2013-09-09 04:54:13 +02:00
///
2013-08-17 11:54:16 +02:00
void clear(int priority);
2013-09-09 04:54:13 +02:00
///
/// Clear all priority channels
///
2013-08-17 11:54:16 +02:00
void clearAll();
///
/// Enable/Disable components during runtime
///
/// @param component The component [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]
/// @param state The state of the component [true | false]
///
void setComponentState(const std::string & component, const bool state);
///
/// Set current active priority channel and deactivate auto source switching
///
/// @param priority The priority
///
void setSource(int priority);
///
/// Enables auto source, if disabled prio by manual selecting input source
///
void setSourceAutoSelect();
///
/// Print the current loaded Hyperion configuration file
///
QString getConfig(std::string type);
///
/// Write JSON Value(s) to the actual loaded configuration file
///
/// @param jsonString The JSON String(s) to write
/// @param create Specifies whether the nonexistent json string to be created
///
void setConfig(const std::string & jsonString, bool create, bool overwrite);
2013-09-09 04:54:13 +02:00
///
/// Set the color transform of the leds
///
2013-08-31 14:36:54 +02:00
/// @note Note that providing a NULL will leave the settings on the server unchanged
2013-09-09 04:54:13 +02:00
///
/// @param transformId The identifier of the transform to set
2013-08-31 14:36:54 +02:00
/// @param saturation The HSV saturation gain
/// @param value The HSV value gain
/// @param saturationL The HSL saturation gain
/// @param luminance The HSL luminance gain
/// @param luminanceMin The HSL luminance minimum
2013-08-31 14:36:54 +02:00
/// @param threshold The threshold
2013-09-09 22:35:28 +02:00
/// @param gamma The gamma value
2013-08-31 14:36:54 +02:00
/// @param blacklevel The blacklevel
/// @param whitelevel The whitelevel
2013-09-09 04:54:13 +02:00
///
void setTransform(
std::string * transformId,
double * saturation,
double * value,
double * saturationL,
double * luminance,
double * luminanceMin,
ColorTransformValues * threshold,
ColorTransformValues * gamma,
ColorTransformValues * blacklevel,
ColorTransformValues * whitelevel);
///
/// Set the color correction of the leds
///
/// @note Note that providing a NULL will leave the settings on the server unchanged
///
/// @param correctionId The identifier of the correction to set
/// @param correction The correction values
void setCorrection(
std::string * correctionId,
ColorCorrectionValues * correction);
///
/// Set the color temperature of the leds
///
/// @note Note that providing a NULL will leave the settings on the server unchanged
///
/// @param temperatureId The identifier of the correction to set
/// @param temperature The temperature correction values
void setTemperature(
std::string * temperatureId,
ColorCorrectionValues * temperature);
///
/// Set the color adjustment of the leds
///
/// @note Note that providing a NULL will leave the settings on the server unchanged
///
/// @param adjustmentId The identifier of the correction to set
/// @param redAdjustment The red channel adjustment values
/// @param greenAdjustment The green channel adjustment values
/// @param blueAdjustment The blue channel adjustment values
void setAdjustment(
std::string * adjustmentId,
ColorAdjustmentValues * redAdjustment,
ColorAdjustmentValues * greenAdjustment,
ColorAdjustmentValues * blueAdjustment);
private:
2013-09-09 04:54:13 +02:00
///
/// Send a json command message and receive its reply
///
2013-08-31 14:36:54 +02:00
/// @param message The message to send
2013-09-09 04:54:13 +02:00
///
2013-08-31 14:36:54 +02:00
/// @return The returned reply
2013-09-09 04:54:13 +02:00
///
Json::Value sendMessage(const Json::Value & message);
2013-09-09 04:54:13 +02:00
///
/// Parse a reply message
///
2013-08-31 14:36:54 +02:00
/// @param reply The received reply
2013-09-09 04:54:13 +02:00
///
2013-08-31 14:36:54 +02:00
/// @return true if the reply indicates success
2013-09-09 04:54:13 +02:00
///
2013-08-13 22:35:50 +02:00
bool parseReply(const Json::Value & reply);
private:
2013-09-09 04:54:13 +02:00
/// Flag for printing all send and received json-messages to the standard out
bool _printJson;
2013-09-09 04:54:13 +02:00
/// The TCP-Socket with the connection to the server
QTcpSocket _socket;
};