| 1368 | */ |
| 1369 | |
| 1370 | static void |
| 1371 | cupsd_send_notification( |
| 1372 | cupsd_subscription_t *sub, /* I - Subscription object */ |
| 1373 | cupsd_event_t *event) /* I - Event to send */ |
| 1374 | { |
| 1375 | ipp_state_t state; /* IPP event state */ |
| 1376 | |
| 1377 | |
| 1378 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
| 1379 | "cupsd_send_notification(sub=%p(%d), event=%p(%s))", |
| 1380 | sub, sub->id, event, cupsdEventName(event->event)); |
| 1381 | |
| 1382 | /* |
| 1383 | * Allocate the events array as needed... |
| 1384 | */ |
| 1385 | |
| 1386 | _cupsRWLockWrite(&sub->lock); |
| 1387 | |
| 1388 | if (!sub->events) |
| 1389 | { |
| 1390 | sub->events = cupsArrayNew3((cups_array_func_t)NULL, NULL, |
| 1391 | (cups_ahash_func_t)NULL, 0, |
| 1392 | (cups_acopy_func_t)NULL, |
| 1393 | (cups_afree_func_t)cupsd_delete_event); |
| 1394 | |
| 1395 | if (!sub->events) |
| 1396 | { |
| 1397 | cupsdLogMessage(CUPSD_LOG_CRIT, |
| 1398 | "Unable to allocate memory for subscription #%d!", |
| 1399 | sub->id); |
| 1400 | goto done; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | /* |
| 1405 | * Purge an old event as needed... |
| 1406 | */ |
| 1407 | |
| 1408 | if (cupsArrayCount(sub->events) >= MaxEvents) |
| 1409 | { |
| 1410 | /* |
| 1411 | * Purge the oldest event in the cache... |
| 1412 | */ |
| 1413 | |
| 1414 | cupsArrayRemove(sub->events, cupsArrayFirst(sub->events)); |
| 1415 | |
| 1416 | sub->first_event_id ++; |
| 1417 | } |
| 1418 | |
| 1419 | /* |
| 1420 | * Add the event to the subscription. Since the events array is |
| 1421 | * always MaxEvents in length, and since we will have already |
| 1422 | * removed an event from the subscription cache if we hit the |
| 1423 | * event cache limit, we don't need to check for overflow here... |
| 1424 | */ |
| 1425 | |
| 1426 | cupsArrayAdd(sub->events, event); |
| 1427 |
no test coverage detected