| 3083 | */ |
| 3084 | |
| 3085 | static int |
| 3086 | JSONStream_Output(struct iperf_test * test, const char * event_name, cJSON * obj) |
| 3087 | { |
| 3088 | cJSON *event = cJSON_CreateObject(); |
| 3089 | if (!event) |
| 3090 | return -1; |
| 3091 | cJSON_AddStringToObject(event, "event", event_name); |
| 3092 | cJSON_AddItemReferenceToObject(event, "data", obj); |
| 3093 | char *str = cJSON_PrintUnformatted(event); |
| 3094 | if (str == NULL) |
| 3095 | return -1; |
| 3096 | if (test->json_callback != NULL) { |
| 3097 | (test->json_callback)(test, str); |
| 3098 | } else { |
| 3099 | if (pthread_mutex_lock(&(test->print_mutex)) != 0) { |
| 3100 | perror("iperf_json_finish: pthread_mutex_lock"); |
| 3101 | } |
| 3102 | fprintf(test->outfile, "%s\n", str); |
| 3103 | if (pthread_mutex_unlock(&(test->print_mutex)) != 0) { |
| 3104 | perror("iperf_json_finish: pthread_mutex_unlock"); |
| 3105 | } |
| 3106 | } |
| 3107 | iflush(test); |
| 3108 | cJSON_free(str); |
| 3109 | cJSON_Delete(event); |
| 3110 | return 0; |
| 3111 | } |
| 3112 | |
| 3113 | /*************************************************************/ |
| 3114 | /** |
no test coverage detected
searching dependent graphs…