2022-04-10 11:29:06 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2022-04-10 11:07:42 +02:00
|
|
|
#include <stdlib.h>
|
2022-04-10 11:29:06 +02:00
|
|
|
#include <string.h>
|
2022-04-10 11:07:42 +02:00
|
|
|
|
|
|
|
#include "edid.h"
|
|
|
|
#include "info.h"
|
2022-08-02 12:18:19 +02:00
|
|
|
#include "log.h"
|
2022-04-10 11:07:42 +02:00
|
|
|
|
|
|
|
struct di_info *
|
|
|
|
di_info_parse_edid(const void *data, size_t size)
|
|
|
|
{
|
|
|
|
struct di_edid *edid;
|
|
|
|
struct di_info *info;
|
2022-08-02 12:18:19 +02:00
|
|
|
char *failure_msg = NULL;
|
|
|
|
size_t failure_msg_size;
|
|
|
|
FILE *failure_msg_file;
|
2022-04-10 11:07:42 +02:00
|
|
|
|
2022-08-02 12:18:19 +02:00
|
|
|
failure_msg_file = open_memstream(&failure_msg,
|
|
|
|
&failure_msg_size);
|
|
|
|
if (!failure_msg_file)
|
2022-04-10 11:07:42 +02:00
|
|
|
return NULL;
|
|
|
|
|
2022-08-02 12:18:19 +02:00
|
|
|
edid = _di_edid_parse(data, size, failure_msg_file);
|
|
|
|
if (!edid)
|
|
|
|
goto err_failure_msg_file;
|
|
|
|
|
2022-04-10 11:07:42 +02:00
|
|
|
info = calloc(1, sizeof(*info));
|
2022-08-02 12:18:19 +02:00
|
|
|
if (!info)
|
|
|
|
goto err_edid;
|
2022-04-10 11:07:42 +02:00
|
|
|
|
|
|
|
info->edid = edid;
|
|
|
|
|
2022-08-02 12:18:19 +02:00
|
|
|
if (fflush(failure_msg_file) != 0)
|
|
|
|
goto err_info;
|
|
|
|
fclose(failure_msg_file);
|
|
|
|
if (failure_msg && failure_msg[0] != '\0')
|
|
|
|
info->failure_msg = failure_msg;
|
|
|
|
else
|
|
|
|
free(failure_msg);
|
|
|
|
|
2022-04-10 11:07:42 +02:00
|
|
|
return info;
|
2022-08-02 12:18:19 +02:00
|
|
|
|
|
|
|
err_info:
|
|
|
|
free(info);
|
|
|
|
err_edid:
|
|
|
|
_di_edid_destroy(edid);
|
|
|
|
err_failure_msg_file:
|
|
|
|
fclose(failure_msg_file);
|
|
|
|
free(failure_msg);
|
|
|
|
return NULL;
|
2022-04-10 11:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
di_info_destroy(struct di_info *info)
|
|
|
|
{
|
2022-06-09 14:45:47 +02:00
|
|
|
_di_edid_destroy(info->edid);
|
2022-08-02 12:18:19 +02:00
|
|
|
free(info->failure_msg);
|
2022-04-10 11:07:42 +02:00
|
|
|
free(info);
|
|
|
|
}
|
2022-05-03 12:04:11 +02:00
|
|
|
|
|
|
|
const struct di_edid *
|
|
|
|
di_info_get_edid(const struct di_info *info)
|
|
|
|
{
|
|
|
|
return info->edid;
|
|
|
|
}
|
2022-04-10 11:29:06 +02:00
|
|
|
|
2022-06-22 15:29:53 +02:00
|
|
|
const char *
|
|
|
|
di_info_get_failure_msg(const struct di_info *info)
|
|
|
|
{
|
2022-08-02 12:18:19 +02:00
|
|
|
return info->failure_msg;
|
2022-06-22 15:29:53 +02:00
|
|
|
}
|