/*!
 *
 * Copyright (c) 2015-2018, 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: 21/03/2015
 *
 */

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

#include "ubus-cpp/ubus-object.h"

/*------------------------------- GLOBALS ----------------------------------*/

/*--------------------------------- DEFINES ---------------------------------*/

/*!  ----------------------------------------------------------------------------
 *  @fn UBusObject
 *
 *  @brief Construct a new UBusObject, the object type and methods is 
 * provided statically using the type Derived
 * 
 * @param anObjType object type, be careful it should not be a temporary !!! 
 * @param AnObjName : the name of the object 
 * @param anObjID : TO BE DEFINED
 * @param anObjPath : TO BE DEFINED
 * 
 * @important : the parameter anObjType should not be a temporary !!!
 */
UBusObject::UBusObject(ubus_object_type &anObjType, const char *AnObjName, int anObjID,
					   const char *anObjPath)
{
	name = AnObjName ? strdup(AnObjName) : 0;
	id = anObjID;
	path = anObjPath ? strdup(anObjPath) : 0;

	type = &anObjType;
	methods = anObjType.methods;
	n_methods = anObjType.n_methods;

	// nullify last fields
	subscribe_cb = 0;
	has_subscribers = false;
}

/*!  ----------------------------------------------------------------------------
 *  @fn ~UBusObject
 *
 *  @brief Destructor of the UBusObject
 */
UBusObject::~UBusObject(void)
{
	free((char *)name);
	free((char *)path);
}
