Doxygen: Add missing @retval tag
[libjaylink.git] / libjaylink / core.c
blob9189905d170f8e22070f5bb296a294385a93ab3a
1 /*
2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2015 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdlib.h>
21 #include <libusb.h>
23 #include "libjaylink.h"
24 #include "libjaylink-internal.h"
26 /**
27 * @file
29 * Core library functions.
32 /**
33 * Initialize libjaylink.
35 * This function must be called before any other libjaylink function is called.
37 * @param[out] ctx Newly allocated libjaylink context on success, and undefined
38 * on failure.
40 * @retval JAYLINK_OK Success.
41 * @retval JAYLINK_ERR_ARG Invalid arguments.
42 * @retval JAYLINK_ERR_MALLOC Memory allocation error.
43 * @retval JAYLINK_ERR Other error conditions.
45 JAYLINK_API int jaylink_init(struct jaylink_context **ctx)
47 int ret;
48 struct jaylink_context *context;
50 if (!ctx)
51 return JAYLINK_ERR_ARG;
53 context = malloc(sizeof(struct jaylink_context));
55 if (!context)
56 return JAYLINK_ERR_MALLOC;
58 if (libusb_init(&context->usb_ctx) < 0) {
59 free(context);
60 return JAYLINK_ERR;
63 context->devs = NULL;
65 /* Show error and warning messages by default. */
66 context->log_level = JAYLINK_LOG_LEVEL_WARNING;
68 context->log_callback = &log_vprintf;
69 context->log_callback_data = NULL;
71 ret = jaylink_log_set_domain(context, JAYLINK_LOG_DOMAIN_DEFAULT);
73 if (ret != JAYLINK_OK) {
74 free(context);
75 return ret;
78 *ctx = context;
80 return JAYLINK_OK;
83 /**
84 * Shutdown libjaylink.
86 * @param[in,out] ctx libjaylink context.
88 JAYLINK_API void jaylink_exit(struct jaylink_context *ctx)
90 if (!ctx)
91 return;
93 list_free(ctx->devs);
94 libusb_exit(ctx->usb_ctx);
95 free(ctx);