// Include standard libraries and DOCA headers
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <doca_ctx.h>
#include <doca_dev.h>
#include <doca_dma.h> 
#include <doca_types.h>
#include <doca_buf.h>
#include <doca_log.h>
#include <doca_buf_inventory.h>
#include <doca_mmap.h>

#include "definitions.h"

// Register logger for this LAB 3
DOCA_LOG_REGISTER(LAB3::LOGIC);

// Define macro to exit on failure and log error
#define EXIT_ON_FAILURE(_expression_) \
{ \
	doca_error_t _status_ = _expression_; \
\
	if (_status_ != DOCA_SUCCESS) { \
		DOCA_LOG_ERR("%s failed with status %s", __func__, \
			 doca_error_get_descr(_status_)); \
		return _status_; \
	} \
}

// Define the main logic function
doca_error_t run(struct program_state *state) {
	struct doca_devinfo **dev_list;
    uint32_t nb_devs;
	int result = doca_devinfo_create_list(&dev_list, &nb_devs);

	for (int i = 0; i < nb_devs; i++) {
		result = doca_dma_cap_task_memcpy_is_supported(dev_list[i]);
		if (result != DOCA_SUCCESS) {
            continue;
        }
	    if(doca_dev_open(dev_list[i], &state->base.device) == DOCA_SUCCESS) {
			DOCA_LOG_WARN("Device opened");
            doca_devinfo_destroy_list(dev_list);   
            break;     
        }
	}
}

// Cleanup DOCA resources: inventory, mmap, device, buffer

// Define the run_lab_logic function
