* append a log data receiver, return 0 if success. */
| 214 | * append a log data receiver, return 0 if success. |
| 215 | */ |
| 216 | XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receive_callback rev, int *out_index) |
| 217 | { |
| 218 | int i; |
| 219 | |
| 220 | if (ctx == NULL){ |
| 221 | return -1; |
| 222 | } |
| 223 | if (rev == NULL){ |
| 224 | strcpy(ctx->_error, "param @rev is null"); |
| 225 | return -1; |
| 226 | } |
| 227 | |
| 228 | pthread_mutex_lock(&ctx->_mutext); |
| 229 | |
| 230 | for (i = 0; i < RECEIVER_MAX_COUNT; i++){ |
| 231 | if (ctx->_receivers[i]._fn == NULL) |
| 232 | break; |
| 233 | } |
| 234 | |
| 235 | if (i == RECEIVER_MAX_COUNT){ |
| 236 | strcpy(ctx->_error, "receiver count is full"); |
| 237 | pthread_mutex_unlock(&ctx->_mutext); |
| 238 | return -1; |
| 239 | } |
| 240 | |
| 241 | ctx->_receivers[i]._type = RECEIVER_TYPE_CALLBACK; |
| 242 | ctx->_receivers[i]._rev = rev; |
| 243 | ctx->_receivers[i]._fn = print_to_user_callback; |
| 244 | ctx->_receivers[i]._enable = 1; |
| 245 | ctx->_count++; |
| 246 | |
| 247 | if (out_index) |
| 248 | *out_index = i; |
| 249 | |
| 250 | pthread_mutex_unlock(&ctx->_mutext); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * append a log data receiver, return 0 if success. |