/**
 * @file service.h
 *
 * @brief Service main file (header).
 *
 * Copyright 2007-2008, Freie Universitaet Berlin. All rights reserved.
 * Please refer to the COPYING file for detailed licensing information.
 *
 * @author Georg Wittenburg
 *
 * $Id: service.h 2685 2008-06-25 16:38:56Z wittenbu $
 */

#ifndef SERVICE_H
#define SERVICE_H

#include "../types.h"
#include "service_types.h"

#define SERVICE_PACKET_TYPE_CLIENT_DATA_REQUEST		0x0	///< SERVICE DATA REQUEST packet type.
#define SERVICE_PACKET_TYPE_CLIENT_DATA_UPDATE		0x1	///< SERVICE DATA UPDATE packet type.
#define SERVICE_PACKET_TYPE_CLIENT_STREAM_REQUEST	0x2	///< SERVICE STREAM REQUEST packet type.
#define SERVICE_PACKET_TYPE_SERVER_DATA_ITEM		0x3	///< SERVICE DATA ITEM packet type.
#define SERVICE_PACKET_TYPE_SERVER_STREAM_ITEM		0x4	///< SERVICE STREAM ITEM packet type.
#define SERVICE_PACKET_TYPE_SERVER_NOT_AVAILABLE	0x5	///< SERVICE NOT AVAILABLE packet type.
#define SERVICE_PACKET_TYPE_REPLICATION_REQUEST		0x6	///< SERVICE REPLICATION REQUEST packet type.
#define SERVICE_PACKET_TYPE_REPLICATION_DATA		0x7	///< SERVICE REPLICATION DATA packet type.
#define SERVICE_PACKET_TYPE_REPLICATION_ACK		0x8	///< SERVICE REPLICATION ACK packet type.
#define SERVICE_PACKET_TYPE_REPLICATION_NACK		0x9	///< SERVICE REPLICATION NACK packet type.

// Interface to main module.
void SERVICE_init();
void SERVICE_start();
void SERVICE_stop();
void SERVICE_finalize();
void SERVICE_recv(const packet_header_t* header, const void* payload);
bool SERVICE_command(int argc, const char*const* argv);

// Interface provided by this module (client).
void SERVICE_request_data(const SERVICE_id_t* service_id, uint16_t offset, size_t size);
void SERVICE_update_data(const SERVICE_id_t* service_id, uint16_t offset, size_t size, const char* data);
void SERVICE_request_stream(const SERVICE_id_t* service_id, uint16_t offset, size_t size, C_time_t interval, C_time_t duration);
// Interface provided by this module (server).
void SERVICE_create_service(const SERVICE_id_t* service_id, size_t service_data_size);
void SERVICE_shutdown_service(const SERVICE_id_t* service_id);
SERVICE_service_t* SERVICE_get_active_service(const SERVICE_id_t* service_id);
void SERVICE_replicate_service(const SERVICE_id_t* service_id, C_addr_t to, callback_function_t callback, SERVICE_replication_result_t* result);
void SERVICE_migrate_service(const SERVICE_id_t* service_id, C_addr_t to, callback_function_t callback, SERVICE_migration_result_t* result);
// Utility functions.
void SERVICE_copy_service_id(SERVICE_id_t* dest_service_id, const SERVICE_id_t* src_service_id);
bool SERVICE_same_service_id(const SERVICE_id_t* service_id_1, const SERVICE_id_t* service_id_2);

#endif	// SERVICE_H
