2019-07-20 15:22:51 +02:00
|
|
|
/*
|
|
|
|
* Part of ncdc - a discord client for the console
|
|
|
|
* Copyright (C) 2019 Florian Stinglmayr <fstinglmayr@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-25 16:18:15 +02:00
|
|
|
#ifndef DC_LOOP_H
|
|
|
|
#define DC_LOOP_H
|
|
|
|
|
|
|
|
#include <dc/api.h>
|
2019-07-08 23:29:08 +02:00
|
|
|
#include <dc/gateway.h>
|
2019-06-25 16:18:15 +02:00
|
|
|
|
|
|
|
#include <event.h>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
struct dc_loop_;
|
|
|
|
typedef struct dc_loop_ *dc_loop_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple CURLM <--> libevent2 loop and handler if you don't want
|
|
|
|
* to bother rolling your own.
|
|
|
|
*/
|
|
|
|
dc_loop_t dc_loop_new(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If you already have either the CURL multi handle, or the event
|
|
|
|
* base handle, use this function. Either can be NULL. If both are
|
|
|
|
* NULL both are allocated for you.
|
|
|
|
*/
|
|
|
|
dc_loop_t dc_loop_new_full(struct event_base *base, CURLM *multi);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the CURL multi handle in use by this loop.
|
|
|
|
*/
|
|
|
|
CURLM *dc_loop_curl(dc_loop_t l);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the event base used by this loop.
|
|
|
|
*/
|
|
|
|
struct event_base *dc_loop_event_base(dc_loop_t l);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an API handle that this loop should feed.
|
|
|
|
*/
|
|
|
|
void dc_loop_add_api(dc_loop_t loop, dc_api_t api);
|
|
|
|
|
2019-07-10 14:30:37 +02:00
|
|
|
/**
|
|
|
|
* Remove the given API handle from the loop.
|
|
|
|
*/
|
|
|
|
void dc_loop_remove_api(dc_loop_t loop, dc_api_t api);
|
|
|
|
|
2019-07-08 23:29:08 +02:00
|
|
|
/**
|
|
|
|
* Add a gateway to be handled with the rest.
|
|
|
|
*/
|
|
|
|
void dc_loop_add_gateway(dc_loop_t loop, dc_gateway_t gw);
|
|
|
|
|
2019-07-10 14:30:37 +02:00
|
|
|
/**
|
|
|
|
* Remove the given gateway from the loop.
|
|
|
|
*/
|
|
|
|
void dc_loop_remove_gateway(dc_loop_t loop, dc_gateway_t gw);
|
|
|
|
|
2019-06-25 16:18:15 +02:00
|
|
|
/**
|
|
|
|
* Loop once, and process one message in the queues of the event
|
|
|
|
* base, and one message from the queue of the CURL multi events.
|
|
|
|
*/
|
|
|
|
bool dc_loop_once(dc_loop_t l);
|
|
|
|
|
2019-07-03 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Abort the whole event looping shenanigans
|
|
|
|
*/
|
|
|
|
void dc_loop_abort(dc_loop_t l);
|
|
|
|
|
2019-06-25 16:18:15 +02:00
|
|
|
#endif
|