Compare commits

...

3 Commits

Author SHA1 Message Date
nekobit f004d06316 Sum code
FossilOrigin-Name: a3f9c49fe762fcce33b4f03f825c9b65dd6db6f3a3edbc5bfc27190cd530027b
2023-03-06 19:45:46 +00:00
nekobit 1a52d1f23b Some test gui wip
FossilOrigin-Name: 666e04bd3b6805836ebf944c00876e6e82cda32f262022ff63722b53631265b6
2023-03-06 04:02:30 +00:00
nekobit 05af07a450 Get fds function
FossilOrigin-Name: f2e861ab0b82431686099ea537def9b3344d390b3c7445643b9b09986e48be32
2023-03-06 03:14:01 +00:00
6 changed files with 203 additions and 16 deletions

View File

@ -28,8 +28,8 @@ mstdnt_global_curl_cleanup(void);
/**
* Initializes a mstdnt struct
*
* @param data Pointer to struct to fill in
* @return Value of curl_easy_init(); either Zero or non-zero
* \param data Pointer to struct to fill in
* \return Value of curl_easy_init(); either Zero or non-zero
*/
int
mstdnt_init(mastodont_t* data);
@ -37,7 +37,7 @@ mstdnt_init(mastodont_t* data);
/**
* Cleans up the mstdnt struct
*
* @param data Pointer to the mstdnt data
* \param data Pointer to the mstdnt data
*/
void
mstdnt_cleanup(mastodont_t* data);
@ -47,7 +47,7 @@ mstdnt_cleanup(mastodont_t* data);
*
* This contains information such as JSON information and errors.
*
* @param storage The storage block to cleanup
* \param storage The storage block to cleanup
*/
void
mstdnt_storage_cleanup(struct mstdnt_storage *storage);

View File

@ -67,22 +67,43 @@ int mstdnt_fetch_curl_async(mastodont_t* mstdnt,
char* request_t_custom);
/**
* @brief Blocks until a transfer is complete.
* \brief Blocks until a transfer is complete.
*
* You can also check curl's socket
* You can also check curl's socket, but mastodont offers ways to do that
* in case of change
*
* @param mstdnt Mastodont struct
* @param opt Option, MSTDNT_AWAIT_ALL means it will keep going until
* \param mstdnt Mastodont struct
* \param opt Option, MSTDNT_AWAIT_ALL means it will keep going until
* there are no more transfers. MSTDNT_AWAIT_ONCE will run
* @param extra_fds Set of file descriptors to poll alongside
* \param extra_fds Set of file descriptors to poll alongside
* the mastodont data.
* @param nfds Length of extra_fds
* @return 1 on error
* \param nfds Length of extra_fds
* \return 1 on error
*/
int mstdnt_await(mastodont_t* mstdnt,
enum mstdnt_fetch_await opt,
struct mstdnt_fd extra_fds[],
size_t nfds);
/**
* Returns a array of file descriptors to network sockets (if any)
*
* These file descriptors only notify when ready to read.
*
* \remark If you need the write-ready sockets available, poke at CURLM*
directly
* \remark Usually required if you want to interface Mastodont with
* application event loops (i.e. GTK, QT, EFL)
*
* \param set Reference ptr to set
* \param nfds Number of file descriptors to check for reading.
* \return 0 on success, 1 on error
*/
int
mstdnt_get_fds(mastodont_t* mstdnt,
fd_set* set,
int* nfds);
void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data);

View File

@ -2,6 +2,8 @@
* Licensed under BSD 3-Clause License
*/
#include <sys/select.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
@ -114,6 +116,20 @@ int mstdnt_fetch_curl_async(mastodont_t* mstdnt,
return 0;
}
int
mstdnt_get_fds(mastodont_t* mstdnt,
fd_set* set,
int* nfds)
{
assert(mstdnt && nfds);
return curl_multi_fdset(mstdnt->curl,
set,
NULL,
NULL,
nfds) != CURLM_OK;
}
int mstdnt_await(mastodont_t* mstdnt,
enum mstdnt_fetch_await opt,
struct mstdnt_fd extra_fds[],
@ -208,7 +224,7 @@ int mstdnt_await(mastodont_t* mstdnt,
return res;
}
void mstdnt_storage_cleanup(struct mstdnt_storage* storage);
void mstdnt_storage_cleanup(struct mstdnt_storage* storage);// ?
void mstdnt_fetch_data_cleanup(struct mstdnt_fetch_data* res)
{

View File

@ -1,4 +1,5 @@
include(../cmake/mastodont-config.cmake)
add_executable(get_feed get_feed.c)
target_compile_options(get_feed PUBLIC -std=c99 -Wall)
target_link_libraries(get_feed PUBLIC
@ -7,4 +8,24 @@ target_link_libraries(get_feed PUBLIC
target_include_directories(get_feed PUBLIC
${MASTODONT_INCLUDE_DIRS}
)
# GUI demo
pkg_check_modules(EFL_ECORE efl-core)
if (EFL_ECORE_FOUND)
# EFL is clearly installed...
pkg_check_modules(EFL_ELEMENTARY elementary)
add_executable(get_feed_efl get_feed_efl.c)
target_compile_options(get_feed_efl PUBLIC -std=c99 -Wall)
target_link_libraries(get_feed_efl PUBLIC
${MASTODONT_LIBRARIES}
${EFL_ECORE_LIBRARIES}
${EFL_ELEMENTARY_LIBRARIES}
)
target_include_directories(get_feed_efl PUBLIC
${MASTODONT_INCLUDE_DIRS}
${EFL_ECORE_INCLUDE_DIRS}
${EFL_ELEMENTARY_INCLUDE_DIRS}
)
endif(EFL_ECORE_FOUND)

View File

@ -82,9 +82,9 @@ main(int argc, char** argv)
mstdnt_await(&data, 0, NULL, 0);
// Cleanup
//free(instance);
//mstdnt_cleanup(&data);
//mstdnt_global_curl_cleanup();
free(instance);
mstdnt_cleanup(&data);
mstdnt_global_curl_cleanup();
return 1;
}

129
tests/get_feed_efl.c Normal file
View File

@ -0,0 +1,129 @@
#define _POSIX_C_SOURCE 200112L
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mastodont.h>
#include <signal.h>
#define EFL_BETA_API_SUPPORT 1
#include <Efl_Ui.h>
Eo* textbox_instance;
Eo* fd;
Eo* posts;
mastodont_t mstdnt;
static void
gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
mstdnt_cleanup(&data);
mstdnt_global_curl_cleanup();
efl_exit(0);
}
int
tl_callback(mstdnt_request_cb_data* cb_data, void* args)
{
struct mstdnt_statuses* statuses = MSTDNT_CB_DATA(cb_data);
for (int i = 0; i < statuses->len; ++i)
{
struct mstdnt_status* status = statuses->statuses + i;
}
return MSTDNT_REQUEST_DONE;
}
static void
gui_fetch_posts(void* data EINA_UNUSED, const Efl_Event* event EINA_UNUSED)
{
struct mstdnt_args m_args = {
.url = NULL,
.token = NULL,
.flags = 0,
};
mstdnt_timeline_public(&mstdnt, &m_args, tl_callback, NULL, (struct mstdnt_timeline_args){.limit=20});
mstdnt_await(&data, 0, NULL, 0);
}
#if 0
static void
update_mstdnt_fds(void)
{
int nfds;
// Get
fd_set set;
mstdnt_get_fds(&mstdnt, &set, &nfds);
for (int i = 0; i < nfds; ++i)
{
fd = efl_add(EFL_LOOP_FD_CLASS,
efl_main_loop_get(),
efl_loop_fd_set(efl_added, set.fd_array[i]),
efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_READ, _eo_read_cb, &set));
}
}
#endif
static void
gui_setup(void)
{
Eo *win, *box;
win = efl_add(EFL_UI_WIN_CLASS,
efl_main_loop_get(),
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
efl_text_set(efl_added, "Hello World"),
efl_ui_win_autodel_set(efl_added, EINA_TRUE),
efl_event_callback_add(efl_added,
EFL_UI_WIN_EVENT_DELETE_REQUEST,
gui_quit_cb,
NULL));
box = efl_add(EFL_UI_BOX_CLASS,
win,
efl_content_set(win, efl_added),
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(460, 640)));
posts = efl_add(EFL_UI_LIST_CLASS,
box,
//efl_text_interactive_selection_allowed_set(efl_added, EINA_FALSE),
//efl_gfx_hint_weight_set(efl_added, 1.0, 0.9),
//efl_gfx_hint_align_set(efl_added, 0.5, 0.5),
efl_pack(box, efl_added));
textbox_instance = efl_add(EFL_UI_TEXTBOX_CLASS,
box,
efl_gfx_hint_align_set(efl_added, 0.5, 0.5),
efl_pack(box, efl_added));
efl_add(EFL_UI_BUTTON_CLASS,
box,
efl_text_set(efl_added, "Fetch posts asynchronously"),
efl_gfx_hint_weight_set(efl_added, 1.0, 0.5),
efl_pack(box, efl_added),
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
gui_fetch_posts, efl_added));
}
EAPI_MAIN void
efl_main(void *edata EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
// Initialize Mastodont library
mstdnt_global_curl_init();
if (mstdnt_init(&mstdnt) != 0)
{
fputs("Couldn't initialize Mastodont-c!", stderr);
exit(1);
}
gui_setup();
}
EFL_MAIN()