/*
 * Disconnect from this QueueManager instance
 *
 * 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_OK
 * * Except if :exception_on_error => false was supplied as a parameter
 *   to QueueManager.new
 */
VALUE QueueManager_disconnect(VALUE self)
{
    PQUEUE_MANAGER pqm;
    Data_Get_Struct(self, QUEUE_MANAGER, pqm);

    if(pqm->trace_level) printf ("WMQ::QueueManager#disconnect() Queue Manager Handle:%ld\n", pqm->hcon);

    if (!pqm->already_connected)
    {
        pqm->MQDISC(&pqm->hcon, &pqm->comp_code, &pqm->reason_code);

        if(pqm->trace_level) printf("WMQ::QueueManager#disconnect() MQDISC completed with reason:%s\n", wmq_reason(pqm->reason_code));

        if (pqm->comp_code != MQCC_OK)
        {
            if (pqm->exception_on_error)
            {
                VALUE name = rb_iv_get(self,"@name");
                name = StringValue(name);

                rb_raise(wmq_exception,
                         "WMQ::QueueManager#disconnect(). Error disconnecting from Queue Manager:%s, reason:%s",
                         RSTRING(name)->ptr,
                         wmq_reason(pqm->reason_code));
            }

            return Qfalse;
        }
    }
    else
    {
        pqm->comp_code = 0;
        pqm->reason_code = 0;

        if(pqm->trace_level) printf ("WMQ::QueueManager#disconnect() Not calling MQDISC, since already connected on connect\n");
    }

    pqm->hcon = 0;

    return Qtrue;
}