Filter results by

Older Versions

Older API versions are available as a download. To view, extract the file and open the index.html file in a web browser.

loop_test/artik_loop_test.c
/*
*
* Copyright 2017 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
*/
#include <stdio.h>
#include <artik_module.h>
#include <artik_platform.h>
#include <artik_loop.h>
static void on_timeout_callback(void *user_data)
{
artik_loop_module *loop = (artik_loop_module *) user_data;
fprintf(stdout, "TEST: %s triggered, exiting loop\n", __func__);
loop->quit();
}
artik_error test_loop_timeout(void)
{
int id = 0;
fprintf(stdout, "TEST: %s starting\n", __func__);
ret = loop->add_timeout_callback(&id, 5000, on_timeout_callback,
(void *)loop);
if (ret != S_OK)
goto exit;
loop->run();
exit:
fprintf(stdout, "TEST: %s %s\n", __func__, (ret == S_OK) ?
"succeeded" : "failed");
return ret;
}
static int count = 0;
static int on_periodic_callback(void *user_data)
{
artik_loop_module *loop = (artik_loop_module *) user_data;
count++;
if (count == 2) {
fprintf(stdout, "TEST: %s triggered, exiting loop\n", __func__);
loop->quit();
return 0;
}
return 1;
}
artik_error test_loop_periodic(void)
{
int id = 0;
fprintf(stdout, "TEST: %s starting\n", __func__);
ret = loop->add_periodic_callback(&id, 1000, on_periodic_callback,
(void *)loop);
if (ret != S_OK)
goto exit;
loop->run();
exit:
fprintf(stdout, "TEST: %s %s\n", __func__, (ret == S_OK) ?
"succeeded" : "failed");
return ret;
}
int main(void)
{
if (!artik_is_module_available(ARTIK_MODULE_LOOP)) {
fprintf(stdout,
"TEST: Loop module is not available,"\
" skipping test...\n");
return -1;
}
ret = test_loop_timeout();
if (ret != S_OK)
goto exit;
ret = test_loop_periodic();
exit:
return ((ret == S_OK) ? 0 : -1);
}
Last updated on: