Commit 400d5e7d2b0c848b092bccbd55591e8ccac658de
1 parent
7a9129f6
br_iterate_utemplates_file now returns the number of templates iterated
Showing
2 changed files
with
7 additions
and
4 deletions
openbr/universal_template.cpp
| @@ -74,15 +74,16 @@ static bool read_buffer(FILE *file, char *buffer, size_t bytes, bool eofAllowed) | @@ -74,15 +74,16 @@ static bool read_buffer(FILE *file, char *buffer, size_t bytes, bool eofAllowed) | ||
| 74 | return true; | 74 | return true; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | -void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel) | 77 | +int br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel) |
| 78 | { | 78 | { |
| 79 | + int count = 0; | ||
| 79 | QFutureSynchronizer<void> futures; | 80 | QFutureSynchronizer<void> futures; |
| 80 | while (true) { | 81 | while (true) { |
| 81 | br_utemplate t = (br_utemplate) malloc(sizeof(br_universal_template)); | 82 | br_utemplate t = (br_utemplate) malloc(sizeof(br_universal_template)); |
| 82 | 83 | ||
| 83 | if (!read_buffer(file, (char*) t, sizeof(br_universal_template), true)) { | 84 | if (!read_buffer(file, (char*) t, sizeof(br_universal_template), true)) { |
| 84 | free(t); | 85 | free(t); |
| 85 | - return; | 86 | + break; |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | t = (br_utemplate) realloc(t, sizeof(br_universal_template) + t->urlSize + t->fvSize); | 89 | t = (br_utemplate) realloc(t, sizeof(br_universal_template) + t->urlSize + t->fvSize); |
| @@ -90,8 +91,9 @@ void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_c | @@ -90,8 +91,9 @@ void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_c | ||
| 90 | 91 | ||
| 91 | if (parallel) futures.addFuture(QtConcurrent::run(callAndFree, callback, t, context)); | 92 | if (parallel) futures.addFuture(QtConcurrent::run(callAndFree, callback, t, context)); |
| 92 | else callAndFree(callback, t, context); | 93 | else callAndFree(callback, t, context); |
| 94 | + count++; | ||
| 93 | } | 95 | } |
| 94 | - futures.waitForFinished(); | 96 | + return count; |
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | void br_log(const char *message) | 99 | void br_log(const char *message) |
openbr/universal_template.h
| @@ -86,9 +86,10 @@ BR_EXPORT void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplat | @@ -86,9 +86,10 @@ BR_EXPORT void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplat | ||
| 86 | 86 | ||
| 87 | /*! | 87 | /*! |
| 88 | * \brief Iterate over br_universal_template in a file. | 88 | * \brief Iterate over br_universal_template in a file. |
| 89 | + * \return The number of templates iterated | ||
| 89 | * \see br_iterate_utemplates | 90 | * \see br_iterate_utemplates |
| 90 | */ | 91 | */ |
| 91 | -BR_EXPORT void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel); | 92 | +BR_EXPORT int br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel); |
| 92 | 93 | ||
| 93 | /*! | 94 | /*! |
| 94 | * \brief Write a message annotated with the current time to stderr. | 95 | * \brief Write a message annotated with the current time to stderr. |