forked from roc-streaming/roc-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
299 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* Logging configuration example. | ||
* | ||
* This example demonstrates how to configure logging. | ||
* | ||
* Building: | ||
* cc misc_logging.c -lroc | ||
* | ||
* Running: | ||
* ./a.out | ||
* | ||
* License: | ||
* public domain | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <roc/context.h> | ||
#include <roc/log.h> | ||
|
||
#define oops() \ | ||
do { \ | ||
fprintf(stderr, "oops: failure on %s:%d\n", __FILE__, __LINE__); \ | ||
fprintf(stderr, "exiting!\n"); \ | ||
exit(1); \ | ||
} while (0) | ||
|
||
static void my_log_handler(const roc_log_message* message, void* argument) { | ||
const char* lvl = NULL; | ||
|
||
switch (message->level) { | ||
case ROC_LOG_ERROR: | ||
lvl = "ERROR"; | ||
break; | ||
|
||
case ROC_LOG_INFO: | ||
lvl = "INFO"; | ||
break; | ||
|
||
case ROC_LOG_NOTE: | ||
lvl = "NOTE"; | ||
break; | ||
|
||
case ROC_LOG_DEBUG: | ||
lvl = "DEBUG"; | ||
break; | ||
|
||
case ROC_LOG_TRACE: | ||
lvl = "TRACE"; | ||
break; | ||
|
||
default: | ||
lvl = "UNKNOWN"; | ||
break; | ||
} | ||
|
||
printf("level=%s module=%s time=%lld pid=%llu tid=%llu text=%s\n", lvl, | ||
message->module, message->time, message->pid, message->tid, message->text); | ||
} | ||
|
||
int main() { | ||
/* Allow all log message starting from DEBUG level and higher. | ||
*/ | ||
roc_log_set_level(ROC_LOG_DEBUG); | ||
|
||
/* Set custom handler for log messages. | ||
*/ | ||
roc_log_set_handler(my_log_handler, NULL); | ||
|
||
/* Do something to trigger some logging. | ||
*/ | ||
roc_context_config context_config; | ||
memset(&context_config, 0, sizeof(context_config)); | ||
roc_context* context = NULL; | ||
if (roc_context_open(&context_config, &context) != 0) { | ||
oops(); | ||
} | ||
if (roc_context_close(context) != 0) { | ||
oops(); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* Logging configuration example. | ||
* | ||
* This example demonstrates how to check library version. | ||
* | ||
* Building: | ||
* cc misc_version.c -lroc | ||
* | ||
* Running: | ||
* ./a.out | ||
* | ||
* License: | ||
* public domain | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include <roc/version.h> | ||
|
||
int main() { | ||
/* Inspect compile-time library version, defined in header file. | ||
*/ | ||
printf("compile-time version: %u.%u.%u, version code: %u\n", ROC_VERSION_MAJOR, | ||
ROC_VERSION_MINOR, ROC_VERSION_PATCH, ROC_VERSION); | ||
|
||
#if ROC_VERSION >= ROC_VERSION_CODE(0, 3, 0) | ||
printf("compile-time version is >= 0.3.0\n"); | ||
#else | ||
printf("compile-time version is < 0.3.0\n"); | ||
#endif | ||
|
||
/* Inspect run-time library version, returned by a function. | ||
*/ | ||
roc_version version; | ||
roc_version_load(&version); | ||
|
||
printf("run-time version: %u.%u.%u, version code: %u\n", version.major, version.minor, | ||
version.patch, version.code); | ||
|
||
if (version.code >= ROC_VERSION_CODE(0, 3, 0)) { | ||
printf("run-time version is >= 0.3.0\n"); | ||
} else { | ||
printf("run-time version is < 0.3.0\n"); | ||
} | ||
|
||
/* Compare compile-time and run-time version. | ||
* They may differ when using a shared library. | ||
*/ | ||
if (version.code == ROC_VERSION) { | ||
printf("compile-time and run-time versions match\n"); | ||
} else { | ||
printf("compile-time and run-time versions differ\n"); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.