2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2016 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/>.
33 #include "libjaylink.h"
34 #include "libjaylink-internal.h"
39 * @section sec_intro Introduction
41 * This document describes the API of libjaylink.
43 * libjaylink is a shared library written in C to access SEGGER J-Link and
46 * @section sec_error Error handling
48 * The libjaylink functions which can fail use the return value to indicate an
49 * error. The functions typically return an error code of #jaylink_error.
50 * For each function, all possible error codes and their detailed descriptions
51 * are documented. As the possible error codes returned by a function may
52 * change it is recommended to also always cover unexpected values when
53 * checking for error codes to be compatible with later versions of libjaylink.
55 * There are a few exceptions where a function directly returns the result
56 * instead of an error code because it is more convenient from an API
57 * perspective and because there is only a single reason for failure which is
58 * clearly distinguishable from the result.
60 * @section sec_license Copyright and license
62 * libjaylink is licensed under the terms of the GNU General Public
63 * License (GPL), version 2 or later.
65 * @section sec_website Website
67 * <a href="http://git.zapb.de/libjaylink.git">git.zapb.de/libjaylink.git</a>
73 * Core library functions.
77 * Initialize libjaylink.
79 * This function must be called before any other libjaylink function is called.
81 * @param[out] ctx Newly allocated libjaylink context on success, and undefined
84 * @retval JAYLINK_OK Success.
85 * @retval JAYLINK_ERR_ARG Invalid arguments.
86 * @retval JAYLINK_ERR_MALLOC Memory allocation error.
87 * @retval JAYLINK_ERR Other error conditions.
91 JAYLINK_API
int jaylink_init(struct jaylink_context
**ctx
)
94 struct jaylink_context
*context
;
100 return JAYLINK_ERR_ARG
;
102 context
= malloc(sizeof(struct jaylink_context
));
105 return JAYLINK_ERR_MALLOC
;
108 if (libusb_init(&context
->usb_ctx
) != LIBUSB_SUCCESS
) {
115 ret
= WSAStartup(MAKEWORD(2, 2), &wsa_data
);
119 libusb_exit(context
->usb_ctx
);
125 if (LOBYTE(wsa_data
.wVersion
) != 2 || HIBYTE(wsa_data
.wVersion
) != 2) {
127 libusb_exit(context
->usb_ctx
);
134 context
->devs
= NULL
;
135 context
->discovered_devs
= NULL
;
137 /* Show error and warning messages by default. */
138 context
->log_level
= JAYLINK_LOG_LEVEL_WARNING
;
140 context
->log_callback
= &log_vprintf
;
141 context
->log_callback_data
= NULL
;
143 ret
= jaylink_log_set_domain(context
, JAYLINK_LOG_DOMAIN_DEFAULT
);
145 if (ret
!= JAYLINK_OK
) {
147 libusb_exit(context
->usb_ctx
);
162 * Shutdown libjaylink.
164 * @param[in,out] ctx libjaylink context.
166 * @retval JAYLINK_OK Success.
167 * @retval JAYLINK_ERR_ARG Invalid arguments.
171 JAYLINK_API
int jaylink_exit(struct jaylink_context
*ctx
)
176 return JAYLINK_ERR_ARG
;
178 item
= ctx
->discovered_devs
;
181 jaylink_unref_device((struct jaylink_device
*)item
->data
);
185 list_free(ctx
->discovered_devs
);
186 list_free(ctx
->devs
);
189 libusb_exit(ctx
->usb_ctx
);
200 * Check for a capability of libjaylink.
202 * @param[in] cap Capability to check for.
204 * @retval true Capability is supported.
205 * @retval false Capability is not supported or invalid argument.
209 JAYLINK_API
bool jaylink_library_has_cap(enum jaylink_capability cap
)
213 case JAYLINK_CAP_HIF_USB
: