#include "pa_api.h"
#include "nwd_log.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <scl/memory.h>

#if !defined (VERSION_SUFFIX)
/* Are we compiling under soong? Try to include generated file. */
#include "proca_version_suffix.h"
#endif

#if defined(VERSION_NAME) && defined(VERSION_SUFFIX)
#define VERSION_STRING (VERSION_NAME VERSION_SUFFIX)
#else
#error "Please, define VERSION_NAME and VERSION_SUFFIX"
#endif

static const char kVersionString[] __attribute__((used)) = VERSION_STRING;

PaResult PaHandlerCreate(PaHandler *handler) {
  if (NULL == handler) {
    LOG_E("Invalid arguments.\n");
    return PA_INVALID_ARGUMENTS;
  }

  TEES_LogSetLevel(TEES_LOG_LEVEL_DEBUG);
  LOG_I("Version: %s", kVersionString);

  handler->pid = getpid();
  handler->flags = getpid();
  handler->data = (uintptr_t)NULL;

  return PA_SUCCESS;
}

void PaHandlerDestroy(PaHandler *handler) {
  if (NULL == handler) {
    return;
  }

  scl_clean(handler, SCL_SIZEOF(*handler));
}
