| 1460 | } |
| 1461 | |
| 1462 | cs_error_t sam_hc_callback_register (sam_hc_callback_t cb) |
| 1463 | { |
| 1464 | cs_error_t error = CS_OK; |
| 1465 | pthread_attr_t thread_attr; |
| 1466 | int pipe_error; |
| 1467 | int pipe_fd[2]; |
| 1468 | |
| 1469 | if (sam_internal_data.internal_status != SAM_INTERNAL_STATUS_REGISTERED) { |
| 1470 | return (CS_ERR_BAD_HANDLE); |
| 1471 | } |
| 1472 | |
| 1473 | if (sam_internal_data.time_interval == 0) { |
| 1474 | return (CS_ERR_INVALID_PARAM); |
| 1475 | } |
| 1476 | |
| 1477 | if (sam_internal_data.cb_registered) { |
| 1478 | sam_internal_data.hc_callback = cb; |
| 1479 | |
| 1480 | return (CS_OK); |
| 1481 | } |
| 1482 | |
| 1483 | /* |
| 1484 | * We know, this is first registration |
| 1485 | */ |
| 1486 | |
| 1487 | if (cb == NULL) { |
| 1488 | return (CS_ERR_INVALID_PARAM); |
| 1489 | } |
| 1490 | |
| 1491 | pipe_error = pipe (pipe_fd); |
| 1492 | |
| 1493 | if (pipe_error != 0) { |
| 1494 | /* |
| 1495 | * Pipe creation error |
| 1496 | */ |
| 1497 | error = CS_ERR_LIBRARY; |
| 1498 | goto error_exit; |
| 1499 | } |
| 1500 | |
| 1501 | sam_internal_data.cb_rpipe_fd = pipe_fd[0]; |
| 1502 | sam_internal_data.cb_wpipe_fd = pipe_fd[1]; |
| 1503 | |
| 1504 | /* |
| 1505 | * Create thread attributes |
| 1506 | */ |
| 1507 | error = pthread_attr_init (&thread_attr); |
| 1508 | if (error != 0) { |
| 1509 | error = CS_ERR_LIBRARY; |
| 1510 | goto error_close_fd_exit; |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED); |
| 1515 | pthread_attr_setstacksize (&thread_attr, 32768); |
| 1516 | |
| 1517 | /* |
| 1518 | * Create thread |
| 1519 | */ |
no outgoing calls