/*!
 * capabilities_shutters.cpp
 *
 * Copyright (c) 2015, NADAL Jean-Baptiste. All rights reserved.
 *
 * 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
 * 
 * @Author:  NADAL Jean-Baptiste
 * @Date: 24/03/2015
 *
 */

/*-------------------------------- INCLUDES ---------------------------------*/

extern "C" {
#include <libubox/blobmsg_json.h>
}

#include <jsoncpp/json.h>

#include "devices/Devices.h"

#include "capabilities_shutters.h"

namespace { 

using namespace UBus;

static ObjectType gCapabilitiesShuttersModelUbus_types(
	"shutters",
	Method("get", UBUS_CPP(CapabilitiesShuttersModel, Get)),
	Method("delete", UBUS_CPP(CapabilitiesShuttersModel, Delete)),
	Method("put", UBUS_CPP(CapabilitiesShuttersModel, Put)),
	Method("post", UBUS_CPP(CapabilitiesShuttersModel, Post)),

	Method("open", UBUS_CPP(CapabilitiesShuttersModel, Open)),
	Method("close", UBUS_CPP(CapabilitiesShuttersModel, Close)),

	Method("up", UBUS_CPP(CapabilitiesShuttersModel, Up)),
	Method("down", UBUS_CPP(CapabilitiesShuttersModel, Down)),

	Method("position", UBUS_CPP(CapabilitiesShuttersModel, Position))
);

}

/*!  ----------------------------------------------------------------------------
 *  @fn CapabilitiesShuttersModel
 *
 *  @brief Constructor of the UBus Mixer Volume.
 */
CapabilitiesShuttersModel::CapabilitiesShuttersModel (Devices *aDevice) : 
	UBusObject (gCapabilitiesShuttersModelUbus_types, "domo.capabilities.shutters"),
	mDevices (aDevice)
{
}


/*!  ----------------------------------------------------------------------------
 *  @fn ~CapabilitiesShuttersModel
 *
 *  @brief Destructor of the UBus Mixer Volume.
 */
CapabilitiesShuttersModel::~CapabilitiesShuttersModel (void)
{
	
}


/*!  ----------------------------------------------------------------------------
 *  @fn Get
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, 
							   struct blob_attr *aMsg)
{
	int theResult;
	struct blob_buf theBuf = {0};

	blob_buf_init (&theBuf, 0);
	
	blobmsg_add_json_from_string (&theBuf, mDevices->get("Shutters").c_str());
	
	theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
	
	blob_buf_free (&theBuf);
	
	return theResult;
}


/*!  ----------------------------------------------------------------------------
 *  @fn Delete
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	
	return theResult;
}


/*!  ----------------------------------------------------------------------------
 *  @fn Put
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	
	return theResult;
}


/*!  ----------------------------------------------------------------------------
 *  @fn Post
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	
	return theResult;
}


/*!  ----------------------------------------------------------------------------
 *  @fn Open
 *
 *  @brief Open the Shutter
 */
int CapabilitiesShuttersModel::Open (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	printf ("Open the Shutter\n");
	return theResult;
}


/*!  ----------------------------------------------------------------------------
 *  @fn Close
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Close (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	printf ("Close the Shutter\n");	
	return theResult;
}

/*!  ----------------------------------------------------------------------------
 *  @fn Up
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Up (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	printf ("Up the Shutter\n");
	return theResult;
}

/*!  ----------------------------------------------------------------------------
 *  @fn Down
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Down (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	printf ("Down the Shutter\n");
	return theResult;
}

/*!  ----------------------------------------------------------------------------
 *  @fn Position
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::Position (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
{
	int theResult = 0;
	printf ("Position the Shutter\n");
	return theResult;
}
