/*
 * Close the queue
 *
 * Returns:
 * * true : On Success
 * * false: On Failure
 *
 *   comp_code and reason_code are also updated.
 *   reason will return a text description of the reason_code
 *
 * Throws:
 * * WMQ::WMQException if comp_code == MQCC_FAILED
 * * Except if :exception_on_error => false was supplied as a parameter
 *   to QueueManager.new
 */
VALUE Queue_close(VALUE self)
{
    PQUEUE pq;
    Data_Get_Struct(self, QUEUE, pq);

    /* Check if queue is open */
    if (!pq->hcon)
    {
        if(pq->trace_level) printf ("WMQ::Queue#close() Queue not open\n");
        return Qtrue;
    }

    if(pq->trace_level) printf ("WMQ::Queue#close() Queue Handle:%ld, Queue Manager Handle:%ld\n", pq->hobj, pq->hcon);

    pq->MQCLOSE(pq->hcon, &pq->hobj, pq->close_options, &pq->comp_code, &pq->reason_code);

    pq->hcon = 0; /* Every time the queue is opened, the qmgr handle must be fetched again! */
    pq->hobj = 0;

    if(pq->trace_level) printf("WMQ::Queue#close() MQCLOSE ended with reason:%s\n", wmq_reason(pq->reason_code));

    if (pq->comp_code == MQCC_FAILED)
    {
        if (pq->exception_on_error)
        {
            VALUE name = Queue_name(self);

            rb_raise(wmq_exception,
                     "WMQ::Queue#close(). Error closing Queue:%s, reason:%s",
                     RSTRING(name)->ptr,
                     wmq_reason(pq->reason_code));
        }
        return Qfalse;
    }

    return Qtrue;
}