/*
 * Copyright 2018 Foundation for Research and Technology - Hellas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0 [1] [1]
 *
 * Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 *  implied.
 * See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 * Links:
 *  ------
 * [1] http://www.apache.org/licenses/LICENSE-2.0 [1]
*/


#ifndef VINE_ACCEL_HEADER
#define VINE_ACCEL_HEADER
#include <vine_talk.h>

typedef struct vine_accel_s vine_accel_s;

#include "core/vine_vaccel.h"

#ifdef __cplusplus
extern "C" {
#endif /* ifdef __cplusplus */

struct vine_accel_s {
	vine_object_s      obj;
	utils_spinlock     lock;
	utils_list_s       vaccels;
	vine_accel_type_e  type;
	vine_accel_loc_s   location;
	vine_accel_stats_s stats;
	vine_accel_state_e state;
	size_t             revision;
	/* To add more as needed */
};

/**
 * Initialize a vine_accel descriptor in the provided \c mem with the provided
 * arguements.
 * @return An initialized vine_accel instance on success, or NULL on failure.
 */
vine_accel_s* vine_accel_init(vine_pipe_s * pipe, const char *name,
                              vine_accel_type_e type);

const char* vine_accel_get_name(vine_accel_s *accel);

vine_accel_state_e vine_accel_get_stat(vine_accel_s *accel,vine_accel_stats_s * stat);

/**
 * Increase 'revision' of accelerator.
 */
void vine_accel_inc_revision(vine_accel_s * accel);

/**
 * Get 'revision' of accelerator.
 */
size_t vine_accel_get_revision(vine_accel_s * accel);

/**
 * Add (register) a virtual accell \c vaccel to physical accelerator \c accel.
 *
 * @param accel A physsical accelerator
 * @param vaccel A virtual accelerator to be linked with \c accel
 */
void vine_accel_add_vaccel(vine_accel_s * accel,vine_vaccel_s * vaccel);

/**
 * Delete (unregister) a virtual accell \c vaccel from physical accelerator \c accel.
 *
 * @param accel A physsical accelerator
 * @param vaccel A virtual accelerator to be unlinked from \c accel
 */
void vine_accel_del_vaccel(vine_accel_s * accel,vine_vaccel_s * vaccel);

#ifdef __cplusplus
}
#endif /* ifdef __cplusplus */

#endif /* ifndef VINE_ACCEL_HEADER */
