<commit_before>#include "bulkDataCallback.h"

using namespace ACSBulkDataError;
using namespace ACSBulkDataStatus;

BulkDataCallback::BulkDataCallback()
{
    ACS_TRACE("BulkDataCallback::BulkDataCallback");

    state_m = CB_UNS;
    substate_m = CB_SUB_UNS;

    dim_m = 0;
    count_m = 0;

    //loop_m = 5;
    loop_m = 1000;
    //waitPeriod_m.set(0L, 400000L);
    waitPeriod_m.set(0L, 10L); // set to 0.01 ms to improve Receiver performance
                               // (similar to Distributor callback)

    frameCount_m = 0;

    bufParam_p = 0;

    timeout_m = false;
    working_m = false;
    error_m = false;

    errComp_p = 0;

    flowTimeout_m = 0;

    isFepAlive_m = true;
}

BulkDataCallback::~BulkDataCallback()
{
    ACS_TRACE("BulkDataCallback::~BulkDataCallback");

    if (error_m == true)
	{
	if (errComp_p != 0)
	    {
	    delete errComp_p;
	    errComp_p = 0;
	    }
	}
    error_m = false;

    if(bufParam_p)
	{
	bufParam_p->release();
	bufParam_p = 0;
	}
}

int BulkDataCallback::handle_start(void)
{

    // cout << "BulkDataCallback::handle_start - state_m: " << state_m << endl;
    //if(timeout_m == true)
    //ACS_SHORT_LOG((LM_INFO,"BulkDataCallback::handle_start - timeout_m == true !!!"));

    timeout_m = false;

    if (error_m == true)
	{
	if (errComp_p != 0)
	    {
	    delete errComp_p;
	    errComp_p = 0;
	    }
	}
    // error is cleared
    error_m = false;

    // parameter buffer is cleared (just in case)
    if(bufParam_p)
	{
	bufParam_p->release();
	bufParam_p = 0;
	}

    state_m = CB_UNS;
    substate_m = CB_SUB_UNS;

    frameCount_m = 1; // we need to wait for 1 following frame before doing anything else

    if (flowTimeout_m != 0)
	startTime_m = ACE_OS::gettimeofday();

    return 0;
}

int BulkDataCallback::handle_stop (void)
{
    //ACS_TRACE("BulkDataCallback::handle_stop");

    // cout << "CCCCCCCCCCCCCCCCC enter stop state " << state_m << " " << substate_m << endl;

    try
	{
	int locLoop;
	int res;

	locLoop = loop_m;
	while ( (frameCount_m != 0) && locLoop > 0)
	    {
	    ACE_OS::sleep(waitPeriod_m);
	    locLoop--;
	    } // we didn't receive the first frame yet

	if(state_m == CB_UNS)
	    {
	    res = cbStop();
	    return 0;
	    }

	if((state_m == CB_SEND_PARAM) || (state_m == CB_SEND_DATA))
	    {

	    if  (substate_m == CB_SUB_INIT)
		{
		substate_m = CB_SUB_UNS;
		return 0;
		}

	    if (error_m == true)
		{
		timeout_m = true;
		throw CORBA::BAD_OPERATION();
		}

	    locLoop = loop_m;
	    while((count_m != dim_m) && locLoop > 0)
		{
		ACE_OS::sleep(waitPeriod_m);
		locLoop--;
		checkFlowTimeout();

		// re-check error_m in case that is not set the first time
		if (error_m == true)
		    {
		    timeout_m = true;
		    throw CORBA::BAD_OPERATION();
		    }
		}

	    if ( locLoop == 0 )
		{
		ACS_SHORT_LOG((LM_INFO,"BulkDataCallback::handle_stop timeout ( (%ld sec + %ld usec) * %ld ) expired for flow %s - not all data received", waitPeriod_m.sec(), waitPeriod_m.usec(), loop_m, flowname_m.c_str()));

		timeout_m = true;
		//cleaning the recv buffer
		///cleanRecvBuffer();
		//cout << "BulkDataCallback::handle_stop - handle removed: " << getHandle() << endl;
		TAO_AV_CORE::instance()->reactor()->remove_handler(getHandle(),ACE_Event_Handler::READ_MASK);
		ACS_SHORT_LOG((LM_DEBUG,"BulkDataCallback::handle_stop - receiver handler removed from the ACE reactor"));
		//ACE_OS::sleep(1);  // seems necessary to give time to remove
		                   // the handler from the reactor
		throw CORBA::TIMEOUT();
		}

	    if(state_m == CB_SEND_PARAM)
		{
		//res ignored by reactor
		if (dim_m != 0)
		    res = cbStart(bufParam_p);

		if(bufParam_p)
		    {
		    bufParam_p->release();
		    bufParam_p = 0;
		    }
		checkFlowTimeout();
		}

	    state_m = CB_UNS;
	    substate_m = CB_SUB_UNS;

	    return 0;
	    }

	}
    catch(ACSErr::ACSbaseExImpl &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(ex,__FILE__,__LINE__,"BulkDataCallback::handle_stop");
	err.log();
	// add to the completion
	errComp_p = new AVCbErrorCompletion(err, __FILE__, __LINE__, "BulkDataCallback::handle_stop");
	error_m = true;

	if(bufParam_p)
	    {
	    bufParam_p->release();
	    bufParam_p = 0;
	    }

	state_m = CB_UNS;
	substate_m = CB_SUB_UNS;

	throw CORBA::BAD_OPERATION();
	//throw CORBA::TIMEOUT();
	}
    catch(CORBA::Exception &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::handle_stop");
	err.addData("CORBA::Exception", ex._info());
	err.log();

	if (errComp_p == 0)
	    {
	    errComp_p = new AVCbErrorCompletion(err, __FILE__, __LINE__, "BulkDataCallback::handle_stop");
	    error_m = true;
	    }

	if(bufParam_p)
	    {
	    bufParam_p->release();
	    bufParam_p = 0;
	    }

	state_m = CB_UNS;
	substate_m = CB_SUB_UNS;

	throw;
	//throw CORBA::TIMEOUT();
	}
    catch(...)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::handle_stop");
	err.addData("UNKNOWN Exception", "Unknown ex in BulkDataCallback::handle_stop");
	err.log();
//	error_m = true;

	if(bufParam_p)
	    {
	    bufParam_p->release();
	    bufParam_p = 0;
	    }

	state_m = CB_UNS;
	substate_m = CB_SUB_UNS;

	throw;
	//throw CORBA::TIMEOUT();
	}

    state_m = CB_UNS;
    substate_m = CB_SUB_UNS;

    return 0;
}

int BulkDataCallback::handle_destroy (void)
{
    //ACS_TRACE("BulkDataCallback::handle_destroy");

    //cout << "BulkDataCallback::handle_destroy" << endl;

    isFepAlive_m = false;

    return 0;
}

int BulkDataCallback::receive_frame (ACE_Message_Block *frame, TAO_AV_frame_info *frame_info, const ACE_Addr &)
{
    //cout << "BulkDataCallback::receive_frame - state_m: " << state_m << endl;
    working_m = true;

    if(error_m == true)
	{
	///cleanRecvBuffer();
	working_m = false;
	return 0;
	}

    //ACS_SHORT_LOG((LM_INFO,"BulkDataCallback::receive_frame for flow %s", flowname_m.c_str()));
    // cout << "BulkDataCallback::receive_frame - state_m: " << state_m << endl;

    try
	{
	CORBA::ULong val1, val2;
	int res;

	if(state_m == CB_UNS)
	    {
	    char tmp[255];
	    ACE_OS::strcpy(tmp, frame->rd_ptr());

	    std::string strDataInfo(tmp);

	    std::istringstream iss(strDataInfo);

	    iss >> val1 >> val2;

	    // cout << "CCCCCCCCCCCCCCC " << val1 << " " << val2 << endl;

	    if(val1 == 1)
		{
		state_m = CB_SEND_PARAM;
		substate_m = CB_SUB_INIT;

		if(val2 != 0)
		    bufParam_p = new ACE_Message_Block(val2);
		else
		    bufParam_p = 0;
		}
	    else if(val1 == 2)
		{
		state_m = CB_SEND_DATA;
		substate_m = CB_SUB_INIT;
		}
	    else
		{
		state_m = CB_UNS;
		substate_m = CB_SUB_UNS;
		}

	    dim_m = val2;
	    count_m = 0;

	    frameCount_m = 0;
	    working_m = false;

	    return 0;
	    }

	if(state_m == CB_SEND_PARAM)
	    {

	    if ( dim_m == 0 )
		{
		res = cbStart();

		checkFlowTimeout();
		working_m = false;
		return 0;
		}

	    bufParam_p->copy(frame->rd_ptr(),frame->length());
	    count_m += frame->length();

	    working_m = false;
	    return 0;
	    }

	if (state_m == CB_SEND_DATA)
	    {
	    res = cbReceive(frame);
	    count_m += frame->length();

	    checkFlowTimeout();
	    working_m = false;
	    return 0;
	    }

	}
    catch(ACSErr::ACSbaseExImpl &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(ex,__FILE__,__LINE__,"BulkDataCallback::receive_frame");
	err.log();
	// add to the completion
	errComp_p = new AVCbErrorCompletion(err, __FILE__, __LINE__, "BulkDataCallback::receive_frame");
	error_m = true;
	}
    catch(CORBA::Exception &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::receive_frame");
	err.addData("CORBA::Exception", ex._info());
	err.log();
	error_m = true;
	}
    catch(std::exception &stdex)
        {
    	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::receive_frame");
    	err.addData("std::exception", stdex.what());
    	err.log();
    	error_m = true;
        }
    catch(...)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::receive_frame");
	err.addData("UNKNOWN Exception", "Unknown ex in BulkDataCallback::receive_frame");
	err.log();
	error_m = true;
	}

    working_m = false;
    return 0;
}

void BulkDataCallback::setFlowname (const char * flowname_p)
{
    ACS_TRACE("BulkDataCallback::setFlowname");
    //ACS_SHORT_LOG((LM_INFO,"RRRRRRRRRRRRRRRRR BulkDataCallback::flowname for flow %s", flow_name));
    flowname_m = flowname_p;

    std::string flwName(flowname_p);
    std::string flwNumber(flwName, 4, 1);

    flowNumber_m = atol(flwNumber.c_str());
}

void BulkDataCallback::setReceiverName(ACE_CString recvName)
{
    recvName_m = recvName;
}

void BulkDataCallback::setSleepTime(ACE_Time_Value locWaitPeriod)
{
    ACS_TRACE("BulkDataCallback::setSleepTime");

    waitPeriod_m = locWaitPeriod;
}

void BulkDataCallback::setSafeTimeout(CORBA::ULong locLoop)
{
    ACS_TRACE("BulkDataCallback::setSafeTimeout");

    loop_m = locLoop;
}

CORBA::Boolean BulkDataCallback::isTimeout()
{
    ACS_TRACE("BulkDataCallback::isTimeout");

    return timeout_m;
}

CORBA::Boolean BulkDataCallback::isWorking()
{
    ACS_TRACE("BulkDataCallback::isWorking");

    return working_m;
}

CORBA::Boolean BulkDataCallback::isError()
{
//    ACS_TRACE("BulkDataCallback::isError");

    return error_m;
}

CompletionImpl *BulkDataCallback::getErrorCompletion()
{
    ACS_TRACE("BulkDataCallback::getErrorCompletion");

    // error is cleared; completion cannot be retrieved two times
    error_m = false;

    return errComp_p;
}

void BulkDataCallback::cleanRecvBuffer()
{
    ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *svch = dynamic_cast<ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *>(handler_);

    char buf[BUFSIZ];
    int bufSize = sizeof(buf);
    int nn = 1;
    while(nn > 0)
	{
	nn = svch->peer().recv(buf,bufSize);
	}

//    svch->peer().close();
}

void BulkDataCallback::setFlowTimeout(CORBA::ULong timeout)
{
    flowTimeout_m = timeout;
}

void BulkDataCallback::checkFlowTimeout()
{
    if(flowTimeout_m == 0)
	return;

    ACE_Time_Value elapsedTime = ACE_OS::gettimeofday() - startTime_m;
    double dtime = (elapsedTime.sec() * 1000.) + ( elapsedTime.usec() / 1000. );
    if(dtime > flowTimeout_m)
	{
	///cleanRecvBuffer();
	timeout_m = true;
	AVCbFlowTimeoutExImpl err = AVCbFlowTimeoutExImpl(__FILE__,__LINE__,"BulkDataCallback::checkFlowTimeout");
	throw err;
	}
}

void BulkDataCallback::closePeer()
{
    ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *svch =
	dynamic_cast<ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *>(handler_);

    if (svch != 0)
	{
	svch->peer().close();
	}
}

ACE_HANDLE BulkDataCallback::getHandle()
{
    ACS_TRACE("BulkDataCallback::getHandle");

    ACE_Event_Handler *event_handler = handler_->event_handler();

    ACE_HANDLE handle = event_handler->get_handle();

    return handle;
}
<commit_msg>timeout message canged from INFO to ERROR<commit_after>#include "bulkDataCallback.h"

using namespace ACSBulkDataError;
using namespace ACSBulkDataStatus;

BulkDataCallback::BulkDataCallback()
{
    ACS_TRACE("BulkDataCallback::BulkDataCallback");

    state_m = CB_UNS;
    substate_m = CB_SUB_UNS;

    dim_m = 0;
    count_m = 0;

    //loop_m = 5;
    loop_m = 1000;
    //waitPeriod_m.set(0L, 400000L);
    waitPeriod_m.set(0L, 10L); // set to 0.01 ms to improve Receiver performance
                               // (similar to Distributor callback)

    frameCount_m = 0;

    bufParam_p = 0;

    timeout_m = false;
    working_m = false;
    error_m = false;

    errComp_p = 0;

    flowTimeout_m = 0;

    isFepAlive_m = true;
}

BulkDataCallback::~BulkDataCallback()
{
    ACS_TRACE("BulkDataCallback::~BulkDataCallback");

    if (error_m == true)
	{
	if (errComp_p != 0)
	    {
	    delete errComp_p;
	    errComp_p = 0;
	    }
	}
    error_m = false;

    if(bufParam_p)
	{
	bufParam_p->release();
	bufParam_p = 0;
	}
}

int BulkDataCallback::handle_start(void)
{

    // cout << "BulkDataCallback::handle_start - state_m: " << state_m << endl;
    //if(timeout_m == true)
    //ACS_SHORT_LOG((LM_INFO,"BulkDataCallback::handle_start - timeout_m == true !!!"));

    timeout_m = false;

    if (error_m == true)
	{
	if (errComp_p != 0)
	    {
	    delete errComp_p;
	    errComp_p = 0;
	    }
	}
    // error is cleared
    error_m = false;

    // parameter buffer is cleared (just in case)
    if(bufParam_p)
	{
	bufParam_p->release();
	bufParam_p = 0;
	}

    state_m = CB_UNS;
    substate_m = CB_SUB_UNS;

    frameCount_m = 1; // we need to wait for 1 following frame before doing anything else

    if (flowTimeout_m != 0)
	startTime_m = ACE_OS::gettimeofday();

    return 0;
}

int BulkDataCallback::handle_stop (void)
{
    //ACS_TRACE("BulkDataCallback::handle_stop");

    // cout << "CCCCCCCCCCCCCCCCC enter stop state " << state_m << " " << substate_m << endl;

    try
	{
	int locLoop;
	int res;

	locLoop = loop_m;
	while ( (frameCount_m != 0) && locLoop > 0)
	    {
	    ACE_OS::sleep(waitPeriod_m);
	    locLoop--;
	    } // we didn't receive the first frame yet

	if(state_m == CB_UNS)
	    {
	    res = cbStop();
	    return 0;
	    }

	if((state_m == CB_SEND_PARAM) || (state_m == CB_SEND_DATA))
	    {

	    if  (substate_m == CB_SUB_INIT)
		{
		substate_m = CB_SUB_UNS;
		return 0;
		}

	    if (error_m == true)
		{
		timeout_m = true;
		throw CORBA::BAD_OPERATION();
		}

	    locLoop = loop_m;
	    while((count_m != dim_m) && locLoop > 0)
		{
		ACE_OS::sleep(waitPeriod_m);
		locLoop--;
		checkFlowTimeout();

		// re-check error_m in case that is not set the first time
		if (error_m == true)
		    {
		    timeout_m = true;
		    throw CORBA::BAD_OPERATION();
		    }
		}

	    if ( locLoop == 0 )
		{
		ACS_SHORT_LOG((LM_ERROR,"BulkDataCallback::handle_stop timeout ( (%ld sec + %ld usec) * %ld ) expired for flow %s - not all data received", waitPeriod_m.sec(), waitPeriod_m.usec(), loop_m, flowname_m.c_str()));

		timeout_m = true;
		//cleaning the recv buffer
		///cleanRecvBuffer();
		//cout << "BulkDataCallback::handle_stop - handle removed: " << getHandle() << endl;
		TAO_AV_CORE::instance()->reactor()->remove_handler(getHandle(),ACE_Event_Handler::READ_MASK);
		ACS_SHORT_LOG((LM_DEBUG,"BulkDataCallback::handle_stop - receiver handler removed from the ACE reactor"));
		//ACE_OS::sleep(1);  // seems necessary to give time to remove
		                   // the handler from the reactor
		throw CORBA::TIMEOUT();
		}

	    if(state_m == CB_SEND_PARAM)
		{
		//res ignored by reactor
		if (dim_m != 0)
		    res = cbStart(bufParam_p);

		if(bufParam_p)
		    {
		    bufParam_p->release();
		    bufParam_p = 0;
		    }
		checkFlowTimeout();
		}

	    state_m = CB_UNS;
	    substate_m = CB_SUB_UNS;

	    return 0;
	    }

	}
    catch(ACSErr::ACSbaseExImpl &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(ex,__FILE__,__LINE__,"BulkDataCallback::handle_stop");
	err.log();
	// add to the completion
	errComp_p = new AVCbErrorCompletion(err, __FILE__, __LINE__, "BulkDataCallback::handle_stop");
	error_m = true;

	if(bufParam_p)
	    {
	    bufParam_p->release();
	    bufParam_p = 0;
	    }

	state_m = CB_UNS;
	substate_m = CB_SUB_UNS;

	throw CORBA::BAD_OPERATION();
	//throw CORBA::TIMEOUT();
	}
    catch(CORBA::Exception &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::handle_stop");
	err.addData("CORBA::Exception", ex._info());
	err.log();

	if (errComp_p == 0)
	    {
	    errComp_p = new AVCbErrorCompletion(err, __FILE__, __LINE__, "BulkDataCallback::handle_stop");
	    error_m = true;
	    }

	if(bufParam_p)
	    {
	    bufParam_p->release();
	    bufParam_p = 0;
	    }

	state_m = CB_UNS;
	substate_m = CB_SUB_UNS;

	throw;
	//throw CORBA::TIMEOUT();
	}
    catch(...)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::handle_stop");
	err.addData("UNKNOWN Exception", "Unknown ex in BulkDataCallback::handle_stop");
	err.log();
//	error_m = true;

	if(bufParam_p)
	    {
	    bufParam_p->release();
	    bufParam_p = 0;
	    }

	state_m = CB_UNS;
	substate_m = CB_SUB_UNS;

	throw;
	//throw CORBA::TIMEOUT();
	}

    state_m = CB_UNS;
    substate_m = CB_SUB_UNS;

    return 0;
}

int BulkDataCallback::handle_destroy (void)
{
    //ACS_TRACE("BulkDataCallback::handle_destroy");

    //cout << "BulkDataCallback::handle_destroy" << endl;

    isFepAlive_m = false;

    return 0;
}

int BulkDataCallback::receive_frame (ACE_Message_Block *frame, TAO_AV_frame_info *frame_info, const ACE_Addr &)
{
    //cout << "BulkDataCallback::receive_frame - state_m: " << state_m << endl;
    working_m = true;

    if(error_m == true)
	{
	///cleanRecvBuffer();
	working_m = false;
	return 0;
	}

    //ACS_SHORT_LOG((LM_INFO,"BulkDataCallback::receive_frame for flow %s", flowname_m.c_str()));
    // cout << "BulkDataCallback::receive_frame - state_m: " << state_m << endl;

    try
	{
	CORBA::ULong val1, val2;
	int res;

	if(state_m == CB_UNS)
	    {
	    char tmp[255];
	    ACE_OS::strcpy(tmp, frame->rd_ptr());

	    std::string strDataInfo(tmp);

	    std::istringstream iss(strDataInfo);

	    iss >> val1 >> val2;

	    // cout << "CCCCCCCCCCCCCCC " << val1 << " " << val2 << endl;

	    if(val1 == 1)
		{
		state_m = CB_SEND_PARAM;
		substate_m = CB_SUB_INIT;

		if(val2 != 0)
		    bufParam_p = new ACE_Message_Block(val2);
		else
		    bufParam_p = 0;
		}
	    else if(val1 == 2)
		{
		state_m = CB_SEND_DATA;
		substate_m = CB_SUB_INIT;
		}
	    else
		{
		state_m = CB_UNS;
		substate_m = CB_SUB_UNS;
		}

	    dim_m = val2;
	    count_m = 0;

	    frameCount_m = 0;
	    working_m = false;

	    return 0;
	    }

	if(state_m == CB_SEND_PARAM)
	    {

	    if ( dim_m == 0 )
		{
		res = cbStart();

		checkFlowTimeout();
		working_m = false;
		return 0;
		}

	    bufParam_p->copy(frame->rd_ptr(),frame->length());
	    count_m += frame->length();

	    working_m = false;
	    return 0;
	    }

	if (state_m == CB_SEND_DATA)
	    {
	    res = cbReceive(frame);
	    count_m += frame->length();

	    checkFlowTimeout();
	    working_m = false;
	    return 0;
	    }

	}
    catch(ACSErr::ACSbaseExImpl &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(ex,__FILE__,__LINE__,"BulkDataCallback::receive_frame");
	err.log();
	// add to the completion
	errComp_p = new AVCbErrorCompletion(err, __FILE__, __LINE__, "BulkDataCallback::receive_frame");
	error_m = true;
	}
    catch(CORBA::Exception &ex)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::receive_frame");
	err.addData("CORBA::Exception", ex._info());
	err.log();
	error_m = true;
	}
    catch(std::exception &stdex)
        {
    	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::receive_frame");
    	err.addData("std::exception", stdex.what());
    	err.log();
    	error_m = true;
        }
    catch(...)
	{
	AVCallbackErrorExImpl err = AVCallbackErrorExImpl(__FILE__,__LINE__,"BulkDataCallback::receive_frame");
	err.addData("UNKNOWN Exception", "Unknown ex in BulkDataCallback::receive_frame");
	err.log();
	error_m = true;
	}

    working_m = false;
    return 0;
}

void BulkDataCallback::setFlowname (const char * flowname_p)
{
    ACS_TRACE("BulkDataCallback::setFlowname");
    //ACS_SHORT_LOG((LM_INFO,"RRRRRRRRRRRRRRRRR BulkDataCallback::flowname for flow %s", flow_name));
    flowname_m = flowname_p;

    std::string flwName(flowname_p);
    std::string flwNumber(flwName, 4, 1);

    flowNumber_m = atol(flwNumber.c_str());
}

void BulkDataCallback::setReceiverName(ACE_CString recvName)
{
    recvName_m = recvName;
}

void BulkDataCallback::setSleepTime(ACE_Time_Value locWaitPeriod)
{
    ACS_TRACE("BulkDataCallback::setSleepTime");

    waitPeriod_m = locWaitPeriod;
}

void BulkDataCallback::setSafeTimeout(CORBA::ULong locLoop)
{
    ACS_TRACE("BulkDataCallback::setSafeTimeout");

    loop_m = locLoop;
}

CORBA::Boolean BulkDataCallback::isTimeout()
{
    ACS_TRACE("BulkDataCallback::isTimeout");

    return timeout_m;
}

CORBA::Boolean BulkDataCallback::isWorking()
{
    ACS_TRACE("BulkDataCallback::isWorking");

    return working_m;
}

CORBA::Boolean BulkDataCallback::isError()
{
//    ACS_TRACE("BulkDataCallback::isError");

    return error_m;
}

CompletionImpl *BulkDataCallback::getErrorCompletion()
{
    ACS_TRACE("BulkDataCallback::getErrorCompletion");

    // error is cleared; completion cannot be retrieved two times
    error_m = false;

    return errComp_p;
}

void BulkDataCallback::cleanRecvBuffer()
{
    ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *svch = dynamic_cast<ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *>(handler_);

    char buf[BUFSIZ];
    int bufSize = sizeof(buf);
    int nn = 1;
    while(nn > 0)
	{
	nn = svch->peer().recv(buf,bufSize);
	}

//    svch->peer().close();
}

void BulkDataCallback::setFlowTimeout(CORBA::ULong timeout)
{
    flowTimeout_m = timeout;
}

void BulkDataCallback::checkFlowTimeout()
{
    if(flowTimeout_m == 0)
	return;

    ACE_Time_Value elapsedTime = ACE_OS::gettimeofday() - startTime_m;
    double dtime = (elapsedTime.sec() * 1000.) + ( elapsedTime.usec() / 1000. );
    if(dtime > flowTimeout_m)
	{
	///cleanRecvBuffer();
	timeout_m = true;
	AVCbFlowTimeoutExImpl err = AVCbFlowTimeoutExImpl(__FILE__,__LINE__,"BulkDataCallback::checkFlowTimeout");
	throw err;
	}
}

void BulkDataCallback::closePeer()
{
    ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *svch =
	dynamic_cast<ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH> *>(handler_);

    if (svch != 0)
	{
	svch->peer().close();
	}
}

ACE_HANDLE BulkDataCallback::getHandle()
{
    ACS_TRACE("BulkDataCallback::getHandle");

    ACE_Event_Handler *event_handler = handler_->event_handler();

    ACE_HANDLE handle = event_handler->get_handle();

    return handle;
}
<|endoftext|>


<commit_before>/*****************************************************************************
 * vout_manager.cpp
 *****************************************************************************
 * Copyright (C) 2009 the VideoLAN team
 * $Id$
 *
 * Authors: Erwan Tulou <brezhoneg1 at yahoo.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "vout_manager.hpp"
#include "vlcproc.hpp"
#include "os_factory.hpp"

VoutManager *VoutManager::instance( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_voutManager == NULL )
    {
        pIntf->p_sys->p_voutManager = new VoutManager( pIntf );
    }

    return pIntf->p_sys->p_voutManager;
}

void VoutManager::destroy( intf_thread_t *pIntf )
{
    delete pIntf->p_sys->p_voutManager;
    pIntf->p_sys->p_voutManager = NULL;
}

VoutManager::VoutManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
     m_pCtrlVideoVec(), m_pCtrlVideoVecBackup(), m_SavedWndVec(),
     m_pVoutMainWindow( NULL ), m_pFscWindow( NULL )
{
    m_pVoutMainWindow = new VoutMainWindow( getIntf() );

    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
    int width = pOsFactory->getScreenWidth();
    int height = pOsFactory->getScreenHeight();

    m_pVoutMainWindow->move( 0, 0 );
    m_pVoutMainWindow->resize( width, height );

    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
    rFullscreen.addObserver( this );
}

VoutManager::~VoutManager( )
{
    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
    rFullscreen.delObserver( this );

    delete m_pVoutMainWindow;
}

void VoutManager::registerCtrlVideo( CtrlVideo* p_CtrlVideo )
{
    m_pCtrlVideoVec.push_back( p_CtrlVideo );
}

void VoutManager::registerFSC( FscWindow* p_Win )
{
    m_pFscWindow = p_Win;
}

void VoutManager::saveVoutConfig( )
{
    // Save width/height to be consistent across themes
    // and detach Video Controls
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pCtrlVideo )
        {
            // detach vout thread from VideoControl
            it->pCtrlVideo->detachVoutWindow( );

            // memorize width/height before VideoControl is destroyed
            it->width = it->pCtrlVideo->getPosition()->getWidth();
            it->height = it->pCtrlVideo->getPosition()->getHeight();
            it->pCtrlVideo = NULL;
       }
    }

    // Create a backup copy and reset original for new theme
    m_pCtrlVideoVecBackup = m_pCtrlVideoVec;
    m_pCtrlVideoVec.clear();
}

void VoutManager::restoreVoutConfig( bool b_success )
{
    if( !b_success )
    {
        // loading new theme failed, restoring previous theme
        m_pCtrlVideoVec = m_pCtrlVideoVecBackup;
    }

    // reattach vout(s) to Video Controls
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        CtrlVideo* pCtrlVideo = getBestCtrlVideo();
        if( pCtrlVideo )
        {
            pCtrlVideo->attachVoutWindow( it->pVoutWindow );
            it->pCtrlVideo = pCtrlVideo;
        }
    }
}

void VoutManager::discardVout( CtrlVideo* pCtrlVideo )
{
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pCtrlVideo == pCtrlVideo )
        {
            // detach vout thread from VideoControl
            it->pCtrlVideo->detachVoutWindow( );
            it->width = it->pCtrlVideo->getPosition()->getWidth();
            it->height = it->pCtrlVideo->getPosition()->getHeight();
            it->pCtrlVideo = NULL;
            break;
        }
    }
}

void VoutManager::requestVout( CtrlVideo* pCtrlVideo )
{
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pCtrlVideo == NULL )
        {
            pCtrlVideo->attachVoutWindow( it->pVoutWindow,
                                          it->width, it->height );
            it->pCtrlVideo = pCtrlVideo;
            break;
        }
    }
}

CtrlVideo* VoutManager::getBestCtrlVideo( )
{
    vector<CtrlVideo*>::const_iterator it;

    // first, look up a video control that is visible and unused
    for( it = m_pCtrlVideoVec.begin(); it != m_pCtrlVideoVec.end(); ++it )
    {
        if( (*it)->isUseable() && !(*it)->isUsed() )
        {
            return (*it);
        }
    }

    // as a fallback, look up any video control that is unused
    for( it = m_pCtrlVideoVec.begin(); it != m_pCtrlVideoVec.end(); ++it )
    {
        if( !(*it)->isUsed() )
        {
            return (*it);
        }
    }

    return NULL;
}

// Functions called by window provider
// ///////////////////////////////////

void VoutManager::acceptWnd( vout_window_t* pWnd, int width, int height )
{
    // Creation of a dedicated Window per vout thread
    VoutWindow* pVoutWindow = new VoutWindow( getIntf(), pWnd, width, height,
                                         (GenericWindow*) m_pVoutMainWindow );

    // try to find a video Control within the theme
    CtrlVideo* pCtrlVideo = getBestCtrlVideo();
    if( pCtrlVideo )
    {
        // A Video Control is available
        // directly attach vout thread to it
        pCtrlVideo->attachVoutWindow( pVoutWindow );
    }
    else
    {
        pVoutWindow->setCtrlVideo( NULL );
    }

    // save vout characteristics
    m_SavedWndVec.push_back( SavedWnd( pWnd, pVoutWindow, pCtrlVideo ) );

    msg_Dbg( pWnd, "New vout : Ctrl = %p, w x h = %ix%i",
                    pCtrlVideo, width, height );
}

void VoutManager::releaseWnd( vout_window_t* pWnd )
{
    // remove vout thread from savedVec
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pWnd == pWnd )
        {
            msg_Dbg( getIntf(), "vout released vout=%p, VideoCtrl=%p",
                             pWnd, it->pCtrlVideo );

            // if a video control was being used, detach from it
            if( it->pCtrlVideo )
            {
                it->pCtrlVideo->detachVoutWindow( );
            }

            // remove resources
            delete it->pVoutWindow;
            m_SavedWndVec.erase( it );
            break;
        }
    }

    // force fullscreen to false so that user regains control
    VlcProc::instance( getIntf() )->setFullscreenVar( false );
}

void VoutManager::setSizeWnd( vout_window_t *pWnd, int width, int height )
{
   msg_Dbg( pWnd, "setSize (%ix%i) received from vout thread",
                  width, height );

   vector<SavedWnd>::iterator it;
   for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
   {
       if( it->pWnd == pWnd )
       {
           VoutWindow* pVoutWindow = it->pVoutWindow;

           pVoutWindow->setOriginalWidth( width );
           pVoutWindow->setOriginalHeight( height );

           CtrlVideo* pCtrlVideo = pVoutWindow->getCtrlVideo();
           if( pCtrlVideo )
           {
               pCtrlVideo->resizeControl( width, height );
           }
           break;
       }
   }
}

void VoutManager::setFullscreenWnd( vout_window_t *pWnd, bool b_fullscreen )
{
    msg_Dbg( pWnd, "setFullscreen (%i) received from vout thread",
                   b_fullscreen );

    // reconfigure the fullscreen window (multiple screens)
    if( b_fullscreen )
    {
        vector<SavedWnd>::iterator it;
        for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
        {
            if( it->pWnd == pWnd )
            {
                VoutWindow* pVoutWindow = it->pVoutWindow;
                configureFullscreen( *pVoutWindow );
            }
            break;
        }
    }

    // set fullscreen
    VlcProc::instance( getIntf() )->setFullscreenVar( b_fullscreen );
}

void VoutManager::onUpdate( Subject<VarBool> &rVariable, void *arg )
{
    (void)arg;
    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
    if( &rVariable == &rFullscreen )
    {
        if( rFullscreen.get() )
            m_pVoutMainWindow->show();
        else
            m_pVoutMainWindow->hide();
    }
}

void VoutManager::configureFullscreen( VoutWindow& rWindow )
{
    int numScr = var_InheritInteger( getIntf(), "qt-fullscreen-screennumber" );
    int x0 = m_pVoutMainWindow->getTop();
    int y0 = m_pVoutMainWindow->getLeft();

    int x, y, w, h;
    if( numScr >= 0 )
    {
        // select screen requested by user
        OSFactory *pOsFactory = OSFactory::instance( getIntf() );
        pOsFactory->getMonitorInfo( numScr, &x, &y, &w, &h );
    }
    else
    {
        // select screen where display is already occurring
        rWindow.getMonitorInfo( &x, &y, &w, &h );
    }

    if( x != x0 || y != y0 )
    {
        // move and resize fullscreen
        m_pVoutMainWindow->move( x, y );
        m_pVoutMainWindow->resize( w, h );

        // ensure the fs controller is also moved
        if( m_pFscWindow )
        {
            m_pFscWindow->moveTo( x, y, w, h );
        }
    }
}
<commit_msg>skins2: fix wrong break (cid #1049865)<commit_after>/*****************************************************************************
 * vout_manager.cpp
 *****************************************************************************
 * Copyright (C) 2009 the VideoLAN team
 * $Id$
 *
 * Authors: Erwan Tulou <brezhoneg1 at yahoo.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "vout_manager.hpp"
#include "vlcproc.hpp"
#include "os_factory.hpp"

VoutManager *VoutManager::instance( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_voutManager == NULL )
    {
        pIntf->p_sys->p_voutManager = new VoutManager( pIntf );
    }

    return pIntf->p_sys->p_voutManager;
}

void VoutManager::destroy( intf_thread_t *pIntf )
{
    delete pIntf->p_sys->p_voutManager;
    pIntf->p_sys->p_voutManager = NULL;
}

VoutManager::VoutManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
     m_pCtrlVideoVec(), m_pCtrlVideoVecBackup(), m_SavedWndVec(),
     m_pVoutMainWindow( NULL ), m_pFscWindow( NULL )
{
    m_pVoutMainWindow = new VoutMainWindow( getIntf() );

    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
    int width = pOsFactory->getScreenWidth();
    int height = pOsFactory->getScreenHeight();

    m_pVoutMainWindow->move( 0, 0 );
    m_pVoutMainWindow->resize( width, height );

    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
    rFullscreen.addObserver( this );
}

VoutManager::~VoutManager( )
{
    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
    rFullscreen.delObserver( this );

    delete m_pVoutMainWindow;
}

void VoutManager::registerCtrlVideo( CtrlVideo* p_CtrlVideo )
{
    m_pCtrlVideoVec.push_back( p_CtrlVideo );
}

void VoutManager::registerFSC( FscWindow* p_Win )
{
    m_pFscWindow = p_Win;
}

void VoutManager::saveVoutConfig( )
{
    // Save width/height to be consistent across themes
    // and detach Video Controls
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pCtrlVideo )
        {
            // detach vout thread from VideoControl
            it->pCtrlVideo->detachVoutWindow( );

            // memorize width/height before VideoControl is destroyed
            it->width = it->pCtrlVideo->getPosition()->getWidth();
            it->height = it->pCtrlVideo->getPosition()->getHeight();
            it->pCtrlVideo = NULL;
       }
    }

    // Create a backup copy and reset original for new theme
    m_pCtrlVideoVecBackup = m_pCtrlVideoVec;
    m_pCtrlVideoVec.clear();
}

void VoutManager::restoreVoutConfig( bool b_success )
{
    if( !b_success )
    {
        // loading new theme failed, restoring previous theme
        m_pCtrlVideoVec = m_pCtrlVideoVecBackup;
    }

    // reattach vout(s) to Video Controls
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        CtrlVideo* pCtrlVideo = getBestCtrlVideo();
        if( pCtrlVideo )
        {
            pCtrlVideo->attachVoutWindow( it->pVoutWindow );
            it->pCtrlVideo = pCtrlVideo;
        }
    }
}

void VoutManager::discardVout( CtrlVideo* pCtrlVideo )
{
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pCtrlVideo == pCtrlVideo )
        {
            // detach vout thread from VideoControl
            it->pCtrlVideo->detachVoutWindow( );
            it->width = it->pCtrlVideo->getPosition()->getWidth();
            it->height = it->pCtrlVideo->getPosition()->getHeight();
            it->pCtrlVideo = NULL;
            break;
        }
    }
}

void VoutManager::requestVout( CtrlVideo* pCtrlVideo )
{
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pCtrlVideo == NULL )
        {
            pCtrlVideo->attachVoutWindow( it->pVoutWindow,
                                          it->width, it->height );
            it->pCtrlVideo = pCtrlVideo;
            break;
        }
    }
}

CtrlVideo* VoutManager::getBestCtrlVideo( )
{
    vector<CtrlVideo*>::const_iterator it;

    // first, look up a video control that is visible and unused
    for( it = m_pCtrlVideoVec.begin(); it != m_pCtrlVideoVec.end(); ++it )
    {
        if( (*it)->isUseable() && !(*it)->isUsed() )
        {
            return (*it);
        }
    }

    // as a fallback, look up any video control that is unused
    for( it = m_pCtrlVideoVec.begin(); it != m_pCtrlVideoVec.end(); ++it )
    {
        if( !(*it)->isUsed() )
        {
            return (*it);
        }
    }

    return NULL;
}

// Functions called by window provider
// ///////////////////////////////////

void VoutManager::acceptWnd( vout_window_t* pWnd, int width, int height )
{
    // Creation of a dedicated Window per vout thread
    VoutWindow* pVoutWindow = new VoutWindow( getIntf(), pWnd, width, height,
                                         (GenericWindow*) m_pVoutMainWindow );

    // try to find a video Control within the theme
    CtrlVideo* pCtrlVideo = getBestCtrlVideo();
    if( pCtrlVideo )
    {
        // A Video Control is available
        // directly attach vout thread to it
        pCtrlVideo->attachVoutWindow( pVoutWindow );
    }
    else
    {
        pVoutWindow->setCtrlVideo( NULL );
    }

    // save vout characteristics
    m_SavedWndVec.push_back( SavedWnd( pWnd, pVoutWindow, pCtrlVideo ) );

    msg_Dbg( pWnd, "New vout : Ctrl = %p, w x h = %ix%i",
                    pCtrlVideo, width, height );
}

void VoutManager::releaseWnd( vout_window_t* pWnd )
{
    // remove vout thread from savedVec
    vector<SavedWnd>::iterator it;
    for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
    {
        if( it->pWnd == pWnd )
        {
            msg_Dbg( getIntf(), "vout released vout=%p, VideoCtrl=%p",
                             pWnd, it->pCtrlVideo );

            // if a video control was being used, detach from it
            if( it->pCtrlVideo )
            {
                it->pCtrlVideo->detachVoutWindow( );
            }

            // remove resources
            delete it->pVoutWindow;
            m_SavedWndVec.erase( it );
            break;
        }
    }

    // force fullscreen to false so that user regains control
    VlcProc::instance( getIntf() )->setFullscreenVar( false );
}

void VoutManager::setSizeWnd( vout_window_t *pWnd, int width, int height )
{
   msg_Dbg( pWnd, "setSize (%ix%i) received from vout thread",
                  width, height );

   vector<SavedWnd>::iterator it;
   for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
   {
       if( it->pWnd == pWnd )
       {
           VoutWindow* pVoutWindow = it->pVoutWindow;

           pVoutWindow->setOriginalWidth( width );
           pVoutWindow->setOriginalHeight( height );

           CtrlVideo* pCtrlVideo = pVoutWindow->getCtrlVideo();
           if( pCtrlVideo )
           {
               pCtrlVideo->resizeControl( width, height );
           }
           break;
       }
   }
}

void VoutManager::setFullscreenWnd( vout_window_t *pWnd, bool b_fullscreen )
{
    msg_Dbg( pWnd, "setFullscreen (%i) received from vout thread",
                   b_fullscreen );

    // reconfigure the fullscreen window (multiple screens)
    if( b_fullscreen )
    {
        vector<SavedWnd>::iterator it;
        for( it = m_SavedWndVec.begin(); it != m_SavedWndVec.end(); ++it )
        {
            if( it->pWnd == pWnd )
            {
                VoutWindow* pVoutWindow = it->pVoutWindow;
                configureFullscreen( *pVoutWindow );
                break;
            }
        }
    }

    // set fullscreen
    VlcProc::instance( getIntf() )->setFullscreenVar( b_fullscreen );
}

void VoutManager::onUpdate( Subject<VarBool> &rVariable, void *arg )
{
    (void)arg;
    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
    if( &rVariable == &rFullscreen )
    {
        if( rFullscreen.get() )
            m_pVoutMainWindow->show();
        else
            m_pVoutMainWindow->hide();
    }
}

void VoutManager::configureFullscreen( VoutWindow& rWindow )
{
    int numScr = var_InheritInteger( getIntf(), "qt-fullscreen-screennumber" );
    int x0 = m_pVoutMainWindow->getTop();
    int y0 = m_pVoutMainWindow->getLeft();

    int x, y, w, h;
    if( numScr >= 0 )
    {
        // select screen requested by user
        OSFactory *pOsFactory = OSFactory::instance( getIntf() );
        pOsFactory->getMonitorInfo( numScr, &x, &y, &w, &h );
    }
    else
    {
        // select screen where display is already occurring
        rWindow.getMonitorInfo( &x, &y, &w, &h );
    }

    if( x != x0 || y != y0 )
    {
        // move and resize fullscreen
        m_pVoutMainWindow->move( x, y );
        m_pVoutMainWindow->resize( w, h );

        // ensure the fs controller is also moved
        if( m_pFscWindow )
        {
            m_pFscWindow->moveTo( x, y, w, h );
        }
    }
}
<|endoftext|>


<commit_before>/*****************************************************************************
 * win32_loop.cpp
 *****************************************************************************
 * Copyright (C) 2003 VideoLAN
 * $Id: win32_loop.cpp,v 1.2 2004/02/27 13:24:12 gbazin Exp $
 *
 * Authors: Cyril Deguet     <asmax@via.ecp.fr>
 *          Olivier Teulire <ipkiss@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#ifdef WIN32_SKINS

#include "win32_factory.hpp"
#include "win32_loop.hpp"
#include "../src/generic_window.hpp"
#include "../events/evt_key.hpp"
#include "../events/evt_leave.hpp"
#include "../events/evt_motion.hpp"
#include "../events/evt_mouse.hpp"
#include "../events/evt_refresh.hpp"
#include "../events/evt_scroll.hpp"
#include "vlc_keys.h"

// XXX: Cygwin (at least) doesn't define these macros. Too bad...
#ifndef GET_X_LPARAM
    #define GET_X_LPARAM(a) ((int16_t)(a))
    #define GET_Y_LPARAM(a) ((int16_t)((a)>>16))
#endif

Win32Loop::Win32Loop( intf_thread_t *pIntf ): OSLoop( pIntf )
{
    // Initialize the map
    virtKeyToVlcKey[VK_F1] = KEY_F1;
    virtKeyToVlcKey[VK_F2] = KEY_F2;
    virtKeyToVlcKey[VK_F3] = KEY_F3;
    virtKeyToVlcKey[VK_F4] = KEY_F4;
    virtKeyToVlcKey[VK_F5] = KEY_F5;
    virtKeyToVlcKey[VK_F6] = KEY_F6;
    virtKeyToVlcKey[VK_F7] = KEY_F7;
    virtKeyToVlcKey[VK_F8] = KEY_F8;
    virtKeyToVlcKey[VK_F9] = KEY_F9;
    virtKeyToVlcKey[VK_F10] = KEY_F10;
    virtKeyToVlcKey[VK_F11] = KEY_F11;
    virtKeyToVlcKey[VK_F12] = KEY_F12;
    virtKeyToVlcKey[VK_RETURN] = KEY_ENTER;
    virtKeyToVlcKey[VK_SPACE] = KEY_SPACE;
    virtKeyToVlcKey[VK_ESCAPE] = KEY_ESC;
    virtKeyToVlcKey[VK_LEFT] = KEY_LEFT;
    virtKeyToVlcKey[VK_RIGHT] = KEY_RIGHT;
    virtKeyToVlcKey[VK_UP] = KEY_UP;
    virtKeyToVlcKey[VK_DOWN] = KEY_DOWN;
    virtKeyToVlcKey[VK_HOME] = KEY_HOME;
    virtKeyToVlcKey[VK_END] = KEY_END;
    virtKeyToVlcKey[VK_PRIOR] = KEY_PAGEUP;
    virtKeyToVlcKey[VK_NEXT] = KEY_PAGEDOWN;
}

Win32Loop::~Win32Loop()
{
}

OSLoop *Win32Loop::instance( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_osLoop == NULL )
    {
        OSLoop *pOsLoop = new Win32Loop( pIntf );
        pIntf->p_sys->p_osLoop = pOsLoop;
    }
    return pIntf->p_sys->p_osLoop;
}

void Win32Loop::destroy( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_osLoop )
    {
        delete pIntf->p_sys->p_osLoop;
        pIntf->p_sys->p_osLoop = NULL;
    }
}

void Win32Loop::run()
{
    MSG msg;

    // Compute windows message list
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        Win32Factory *pFactory =
            (Win32Factory*)Win32Factory::instance( getIntf() );
        GenericWindow *pWin = pFactory->m_windowMap[msg.hwnd];
        if( pWin == NULL )
        {
            // We are probably getting a message for a tooltip (which has no
            // associated GenericWindow), for a timer, or for the parent window
            DispatchMessage( &msg );
            continue;
        }

        GenericWindow &win = *pWin;
        switch( msg.message )
        {
            case WM_PAINT:
            {
                PAINTSTRUCT Infos;
                BeginPaint( msg.hwnd, &Infos );
                EvtRefresh evt( getIntf(), 0, 0, Infos.rcPaint.right,
                                Infos.rcPaint.bottom );
                EndPaint( msg.hwnd, &Infos );
                win.processEvent( evt );
                break;
            }
            case WM_MOUSEMOVE:
            {
                // Needed to generate WM_MOUSELEAVE events
                TRACKMOUSEEVENT TrackEvent;
                TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );
                TrackEvent.dwFlags     = TME_LEAVE;
                TrackEvent.hwndTrack   = msg.hwnd;
                TrackEvent.dwHoverTime = 1;
                TrackMouseEvent( &TrackEvent );

                // Compute the absolute position of the mouse
                int x = GET_X_LPARAM( msg.lParam ) + win.getLeft();
                int y = GET_Y_LPARAM( msg.lParam ) + win.getTop();
                EvtMotion evt( getIntf(), x, y );
                win.processEvent( evt );
                break;
            }
            case WM_MOUSELEAVE:
            {
                EvtLeave evt( getIntf() );
                win.processEvent( evt );
                break;
            }
            case WM_MOUSEWHEEL:
            {
                int x = GET_X_LPARAM( msg.lParam ) - win.getLeft();
                int y = GET_Y_LPARAM( msg.lParam ) - win.getTop();
                int mod = getMod( msg.wParam );
                if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
                {
                    EvtScroll evt( getIntf(), x, y, EvtScroll::kUp, mod );
                    win.processEvent( evt );
                }
                else
                {
                    EvtScroll evt( getIntf(), x, y, EvtScroll::kDown, mod );
                    win.processEvent( evt );
                }
                break;
            }
            case WM_LBUTTONDOWN:
            {
                SetCapture( msg.hwnd );
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
                              EvtMouse::kDown, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_RBUTTONDOWN:
            {
                SetCapture( msg.hwnd );
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
                              EvtMouse::kDown, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_LBUTTONUP:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
                              EvtMouse::kUp, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_RBUTTONUP:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
                              EvtMouse::kUp, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_LBUTTONDBLCLK:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
                              EvtMouse::kDblClick, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_RBUTTONDBLCLK:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
                              EvtMouse::kDblClick, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_KEYDOWN:
            case WM_SYSKEYDOWN:
            case WM_KEYUP:
            case WM_SYSKEYUP:
            {
                // The key events are first processed here and not translated
                // into WM_CHAR events because we need to know the status of
                // the modifier keys.

                // Get VLC key code from the virtual key code
                int key = virtKeyToVlcKey[msg.wParam];
                if( !key )
                {
                    // This appears to be a "normal" (ascii) key
                    key = tolower( MapVirtualKey( msg.wParam, 2 ) );
                }

                if( key )
                {
                    // Get the modifier
                    int mod = 0;
                    if( GetKeyState( VK_CONTROL ) & 0x8000 )
                    {
                        mod |= EvtInput::kModCtrl;
                    }
                    if( GetKeyState( VK_SHIFT ) & 0x8000 )
                    {
                        mod |= EvtInput::kModShift;
                    }
                    if( GetKeyState( VK_MENU ) & 0x8000 )
                    {
                        mod |= EvtInput::kModAlt;
                    }

                    // Get the state
                    EvtKey::ActionType_t state;
                    if( msg.message == WM_KEYDOWN ||
                        msg.message == WM_SYSKEYDOWN )
                    {
                        state = EvtKey::kDown;
                    }
                    else
                    {
                        state = EvtKey::kUp;
                    }

                    EvtKey evt( getIntf(), key, state, mod );
                    win.processEvent( evt );
                }
                break;
            }
            default:
                TranslateMessage( &msg );
                DispatchMessage( &msg );
        }
    }
}

int Win32Loop::getMod( WPARAM wParam ) const
{
    int mod = EvtInput::kModNone;
    if( wParam & MK_CONTROL )
        mod |= EvtInput::kModCtrl;
    if( wParam & MK_SHIFT )
        mod |= EvtInput::kModShift;

    return mod;
}

void Win32Loop::exit()
{
    PostQuitMessage(0);
}

#endif
<commit_msg> * skins2/win32/win32_loop.cpp: Refresh the needed rectangle only.    This doesn't fix totally the refresh problems on the skinned vout,    but it improves the situation a lot.<commit_after>/*****************************************************************************
 * win32_loop.cpp
 *****************************************************************************
 * Copyright (C) 2003 VideoLAN
 * $Id$
 *
 * Authors: Cyril Deguet     <asmax@via.ecp.fr>
 *          Olivier Teulire <ipkiss@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#ifdef WIN32_SKINS

#include "win32_factory.hpp"
#include "win32_loop.hpp"
#include "../src/generic_window.hpp"
#include "../events/evt_key.hpp"
#include "../events/evt_leave.hpp"
#include "../events/evt_motion.hpp"
#include "../events/evt_mouse.hpp"
#include "../events/evt_refresh.hpp"
#include "../events/evt_scroll.hpp"
#include "vlc_keys.h"

// XXX: Cygwin (at least) doesn't define these macros. Too bad...
#ifndef GET_X_LPARAM
    #define GET_X_LPARAM(a) ((int16_t)(a))
    #define GET_Y_LPARAM(a) ((int16_t)((a)>>16))
#endif

Win32Loop::Win32Loop( intf_thread_t *pIntf ): OSLoop( pIntf )
{
    // Initialize the map
    virtKeyToVlcKey[VK_F1] = KEY_F1;
    virtKeyToVlcKey[VK_F2] = KEY_F2;
    virtKeyToVlcKey[VK_F3] = KEY_F3;
    virtKeyToVlcKey[VK_F4] = KEY_F4;
    virtKeyToVlcKey[VK_F5] = KEY_F5;
    virtKeyToVlcKey[VK_F6] = KEY_F6;
    virtKeyToVlcKey[VK_F7] = KEY_F7;
    virtKeyToVlcKey[VK_F8] = KEY_F8;
    virtKeyToVlcKey[VK_F9] = KEY_F9;
    virtKeyToVlcKey[VK_F10] = KEY_F10;
    virtKeyToVlcKey[VK_F11] = KEY_F11;
    virtKeyToVlcKey[VK_F12] = KEY_F12;
    virtKeyToVlcKey[VK_RETURN] = KEY_ENTER;
    virtKeyToVlcKey[VK_SPACE] = KEY_SPACE;
    virtKeyToVlcKey[VK_ESCAPE] = KEY_ESC;
    virtKeyToVlcKey[VK_LEFT] = KEY_LEFT;
    virtKeyToVlcKey[VK_RIGHT] = KEY_RIGHT;
    virtKeyToVlcKey[VK_UP] = KEY_UP;
    virtKeyToVlcKey[VK_DOWN] = KEY_DOWN;
    virtKeyToVlcKey[VK_HOME] = KEY_HOME;
    virtKeyToVlcKey[VK_END] = KEY_END;
    virtKeyToVlcKey[VK_PRIOR] = KEY_PAGEUP;
    virtKeyToVlcKey[VK_NEXT] = KEY_PAGEDOWN;
}

Win32Loop::~Win32Loop()
{
}

OSLoop *Win32Loop::instance( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_osLoop == NULL )
    {
        OSLoop *pOsLoop = new Win32Loop( pIntf );
        pIntf->p_sys->p_osLoop = pOsLoop;
    }
    return pIntf->p_sys->p_osLoop;
}

void Win32Loop::destroy( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_osLoop )
    {
        delete pIntf->p_sys->p_osLoop;
        pIntf->p_sys->p_osLoop = NULL;
    }
}

void Win32Loop::run()
{
    MSG msg;

    // Compute windows message list
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        Win32Factory *pFactory =
            (Win32Factory*)Win32Factory::instance( getIntf() );
        GenericWindow *pWin = pFactory->m_windowMap[msg.hwnd];
        if( pWin == NULL )
        {
            // We are probably getting a message for a tooltip (which has no
            // associated GenericWindow), for a timer, or for the parent window
            DispatchMessage( &msg );
            continue;
        }

        GenericWindow &win = *pWin;
        switch( msg.message )
        {
            case WM_PAINT:
            {
                PAINTSTRUCT Infos;
                BeginPaint( msg.hwnd, &Infos );
                EvtRefresh evt( getIntf(),
                                Infos.rcPaint.left,
                                Infos.rcPaint.top,
                                Infos.rcPaint.right - Infos.rcPaint.left + 1,
                                Infos.rcPaint.bottom - Infos.rcPaint.top + 1 );
                EndPaint( msg.hwnd, &Infos );
                win.processEvent( evt );
                break;
            }
            case WM_MOUSEMOVE:
            {
                // Needed to generate WM_MOUSELEAVE events
                TRACKMOUSEEVENT TrackEvent;
                TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );
                TrackEvent.dwFlags     = TME_LEAVE;
                TrackEvent.hwndTrack   = msg.hwnd;
                TrackEvent.dwHoverTime = 1;
                TrackMouseEvent( &TrackEvent );

                // Compute the absolute position of the mouse
                int x = GET_X_LPARAM( msg.lParam ) + win.getLeft();
                int y = GET_Y_LPARAM( msg.lParam ) + win.getTop();
                EvtMotion evt( getIntf(), x, y );
                win.processEvent( evt );
                break;
            }
            case WM_MOUSELEAVE:
            {
                EvtLeave evt( getIntf() );
                win.processEvent( evt );
                break;
            }
            case WM_MOUSEWHEEL:
            {
                int x = GET_X_LPARAM( msg.lParam ) - win.getLeft();
                int y = GET_Y_LPARAM( msg.lParam ) - win.getTop();
                int mod = getMod( msg.wParam );
                if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
                {
                    EvtScroll evt( getIntf(), x, y, EvtScroll::kUp, mod );
                    win.processEvent( evt );
                }
                else
                {
                    EvtScroll evt( getIntf(), x, y, EvtScroll::kDown, mod );
                    win.processEvent( evt );
                }
                break;
            }
            case WM_LBUTTONDOWN:
            {
                SetCapture( msg.hwnd );
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
                              EvtMouse::kDown, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_RBUTTONDOWN:
            {
                SetCapture( msg.hwnd );
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
                              EvtMouse::kDown, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_LBUTTONUP:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
                              EvtMouse::kUp, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_RBUTTONUP:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
                              EvtMouse::kUp, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_LBUTTONDBLCLK:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
                              EvtMouse::kDblClick, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_RBUTTONDBLCLK:
            {
                ReleaseCapture();
                EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
                              GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
                              EvtMouse::kDblClick, getMod( msg.wParam ) );
                win.processEvent( evt );
                break;
            }
            case WM_KEYDOWN:
            case WM_SYSKEYDOWN:
            case WM_KEYUP:
            case WM_SYSKEYUP:
            {
                // The key events are first processed here and not translated
                // into WM_CHAR events because we need to know the status of
                // the modifier keys.

                // Get VLC key code from the virtual key code
                int key = virtKeyToVlcKey[msg.wParam];
                if( !key )
                {
                    // This appears to be a "normal" (ascii) key
                    key = tolower( MapVirtualKey( msg.wParam, 2 ) );
                }

                if( key )
                {
                    // Get the modifier
                    int mod = 0;
                    if( GetKeyState( VK_CONTROL ) & 0x8000 )
                    {
                        mod |= EvtInput::kModCtrl;
                    }
                    if( GetKeyState( VK_SHIFT ) & 0x8000 )
                    {
                        mod |= EvtInput::kModShift;
                    }
                    if( GetKeyState( VK_MENU ) & 0x8000 )
                    {
                        mod |= EvtInput::kModAlt;
                    }

                    // Get the state
                    EvtKey::ActionType_t state;
                    if( msg.message == WM_KEYDOWN ||
                        msg.message == WM_SYSKEYDOWN )
                    {
                        state = EvtKey::kDown;
                    }
                    else
                    {
                        state = EvtKey::kUp;
                    }

                    EvtKey evt( getIntf(), key, state, mod );
                    win.processEvent( evt );
                }
                break;
            }
            default:
                TranslateMessage( &msg );
                DispatchMessage( &msg );
        }
    }
}

int Win32Loop::getMod( WPARAM wParam ) const
{
    int mod = EvtInput::kModNone;
    if( wParam & MK_CONTROL )
        mod |= EvtInput::kModCtrl;
    if( wParam & MK_SHIFT )
        mod |= EvtInput::kModShift;

    return mod;
}

void Win32Loop::exit()
{
    PostQuitMessage(0);
}

#endif
<|endoftext|>


<commit_before>/*
 * Copyright 2015 - 2016 gtalent2@gmail.com
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#include <stdio.h>
#include <stdlib.h>
#include <ox/std/strops.hpp>
#include <ox/fs/filesystem.hpp>

using namespace ox::fs;

const char *usage = "usage:\n"
"\toxfs format [16,32,64] <size> <path>"
"\toxfs write <FS file> <inode> <insertion file>";

char *loadFileBuff(const char *path, ::size_t *sizeOut = nullptr) {
	FILE *file = fopen(path, "rw");
	fseek(file, 0, SEEK_END);
	const auto size = ftell(file);
	auto buff = (char*) malloc(size);
	fread(buff, size, 1, file);
	fclose(file);
	if (sizeOut) {
		*sizeOut = size;
	}
	return buff;
}

int format(int argc, char **args) {
	printf("Creating file system...\n");
	auto err = 1;
	if (argc >= 5) {
		auto type = ox::std::atoi(args[2]);
		auto size = ox::std::atoi(args[3]);
		auto path = args[4];
		auto buff = (ox::std::uint8_t*) malloc(size);

		printf("Size: %d bytes\n", size);
		printf("Type: %d\n", type);

		// format
		switch (type) {
			case 16:
				FileStore16::format(buff, size, ox::fs::OxFS16);
				break;
			case 32:
				FileStore32::format(buff, size, ox::fs::OxFS32);
				break;
			case 64:
				FileStore64::format(buff, size, ox::fs::OxFS64);
				break;
		}

		FILE *file = fopen(path, "w");
		if (file) {
			fwrite(buff, size, 1, file);
			err = fclose(file);
			if (err) {
				printf("Could not write to file: %s.\n", path);
			}
		} else {
			printf("Could not open file: %s.\n", path);
		}

		if (err == 0) {
			printf("Created file system %s\n", path);
		}
	}

	return err;
}

int write(int argc, char **args) {
	auto err = 0;
	if (argc >= 5) {
		auto fsPath = args[2];
		auto inode = ox::std::atoi(args[3]);
		auto srcPath = args[4];
		::size_t srcSize;

		FILE *fsFile = fopen(fsPath, "rw");
		fseek(fsFile, 0, SEEK_END);

		const auto fsSize = ftell(fsFile);
		auto fs = (char*) malloc(fsSize);
		fread(fs, fsSize, 1, fsFile);

		auto srcBuff = loadFileBuff(srcPath, &srcSize);

		auto type = *((ox::std::uint32_t*) fs);
		switch (type) {
			case ox::fs::OxFS16:
				((FileStore16*) fs)->write(inode, srcBuff, srcSize);
				break;
			case ox::fs::OxFS32:
				((FileStore32*) fs)->write(inode, srcBuff, srcSize);
				break;
			case ox::fs::OxFS64:
				((FileStore64*) fs)->write(inode, srcBuff, srcSize);
				break;
		}

		fwrite(fs, fsSize, 1, fsFile);
		err = fclose(fsFile);
	}
	return err;
}

int main(int argc, char **args) {
	auto err = 0;
	if (argc > 1) {
		auto cmd = args[1];
		if (::strcmp(cmd, "format") == 0) {
			err = format(argc, args);
		} else if (::strcmp(cmd, "write") == 0) {
			err = write(argc, args);
		} else if (::strcmp(cmd, "help") == 0) {
			printf("%s\n", usage);
		} else {
			printf("Command '%s' not recognized.\n", cmd);
			err = 1;
		}
	} else {
		printf("%s\n", usage);
	}
	return err;
}
<commit_msg>Add missing new line to oxfstool usage<commit_after>/*
 * Copyright 2015 - 2016 gtalent2@gmail.com
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#include <stdio.h>
#include <stdlib.h>
#include <ox/std/strops.hpp>
#include <ox/fs/filesystem.hpp>

using namespace ox::fs;

const char *usage = "usage:\n"
"\toxfs format [16,32,64] <size> <path>\n"
"\toxfs write <FS file> <inode> <insertion file>";

char *loadFileBuff(const char *path, ::size_t *sizeOut = nullptr) {
	FILE *file = fopen(path, "rw");
	fseek(file, 0, SEEK_END);
	const auto size = ftell(file);
	auto buff = (char*) malloc(size);
	fread(buff, size, 1, file);
	fclose(file);
	if (sizeOut) {
		*sizeOut = size;
	}
	return buff;
}

int format(int argc, char **args) {
	printf("Creating file system...\n");
	auto err = 1;
	if (argc >= 5) {
		auto type = ox::std::atoi(args[2]);
		auto size = ox::std::atoi(args[3]);
		auto path = args[4];
		auto buff = (ox::std::uint8_t*) malloc(size);

		printf("Size: %d bytes\n", size);
		printf("Type: %d\n", type);

		// format
		switch (type) {
			case 16:
				FileStore16::format(buff, size, ox::fs::OxFS16);
				break;
			case 32:
				FileStore32::format(buff, size, ox::fs::OxFS32);
				break;
			case 64:
				FileStore64::format(buff, size, ox::fs::OxFS64);
				break;
		}

		FILE *file = fopen(path, "w");
		if (file) {
			fwrite(buff, size, 1, file);
			err = fclose(file);
			if (err) {
				printf("Could not write to file: %s.\n", path);
			}
		} else {
			printf("Could not open file: %s.\n", path);
		}

		if (err == 0) {
			printf("Created file system %s\n", path);
		}
	}

	return err;
}

int write(int argc, char **args) {
	auto err = 0;
	if (argc >= 5) {
		auto fsPath = args[2];
		auto inode = ox::std::atoi(args[3]);
		auto srcPath = args[4];
		::size_t srcSize;

		FILE *fsFile = fopen(fsPath, "rw");
		fseek(fsFile, 0, SEEK_END);

		const auto fsSize = ftell(fsFile);
		auto fs = (char*) malloc(fsSize);
		fread(fs, fsSize, 1, fsFile);

		auto srcBuff = loadFileBuff(srcPath, &srcSize);

		auto type = *((ox::std::uint32_t*) fs);
		switch (type) {
			case ox::fs::OxFS16:
				((FileStore16*) fs)->write(inode, srcBuff, srcSize);
				break;
			case ox::fs::OxFS32:
				((FileStore32*) fs)->write(inode, srcBuff, srcSize);
				break;
			case ox::fs::OxFS64:
				((FileStore64*) fs)->write(inode, srcBuff, srcSize);
				break;
		}

		fwrite(fs, fsSize, 1, fsFile);
		err = fclose(fsFile);
	}
	return err;
}

int main(int argc, char **args) {
	auto err = 0;
	if (argc > 1) {
		auto cmd = args[1];
		if (::strcmp(cmd, "format") == 0) {
			err = format(argc, args);
		} else if (::strcmp(cmd, "write") == 0) {
			err = write(argc, args);
		} else if (::strcmp(cmd, "help") == 0) {
			printf("%s\n", usage);
		} else {
			printf("Command '%s' not recognized.\n", cmd);
			err = 1;
		}
	} else {
		printf("%s\n", usage);
	}
	return err;
}
<|endoftext|>


<commit_before>/*
 * Copyright 2015 - 2016 gtalent2@gmail.com
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#include <stdio.h>
#include <stdlib.h>
#include <ox/std/strops.hpp>
#include <ox/fs/filesystem.hpp>

using namespace ox::fs;

const char *usage = "usage:\n"
"\toxfs format [16,32,64] <size> <path>\n"
"\toxfs read <FS file> <inode>\n"
"\toxfs write <FS file> <inode> <insertion file>";

char *loadFileBuff(const char *path, ::size_t *sizeOut = nullptr) {
	FILE *file = fopen(path, "rb");
	if (file) {
		fseek(file, 0, SEEK_END);
		const auto size = ftell(file);
		rewind(file);
		auto buff = (char*) malloc(size);
		fread(buff, size, 1, file);
		fclose(file);
		if (sizeOut) {
			*sizeOut = size;
		}
		return buff;
	} else {
		return nullptr;
	}
}

int format(int argc, char **args) {
	printf("Creating file system...\n");
	auto err = 1;
	if (argc >= 5) {
		auto type = ox::std::atoi(args[2]);
		auto size = ox::std::atoi(args[3]);
		auto path = args[4];
		auto buff = (ox::std::uint8_t*) malloc(size);

		printf("Size: %d bytes\n", size);
		printf("Type: %d\n", type);

		// format
		switch (type) {
			case 16:
				FileStore16::format(buff, size, ox::fs::OxFS_16);
				break;
			case 32:
				FileStore32::format(buff, size, ox::fs::OxFS_32);
				break;
			case 64:
				FileStore64::format(buff, size, ox::fs::OxFS_64);
				break;
		}
		createFileSystem(buff);

		auto file = fopen(path, "wb");
		if (file) {
			fwrite(buff, size, 1, file);
			err = fclose(file);
			if (err) {
				printf("Could not write to file: %s.\n", path);
			}
		} else {
			printf("Could not open file: %s.\n", path);
		}

		if (err == 0) {
			printf("Created file system %s\n", path);
		}
	}

	return err;
}

int read(int argc, char **args) {
	auto err = 1;
	if (argc >= 4) {
		auto fsPath = args[2];
		auto inode = ox::std::atoi(args[3]);
		::size_t fsSize;
		ox::std::uint64_t fileSize;

		auto fsBuff = loadFileBuff(fsPath, &fsSize);

		if (fsBuff) {
			auto fs = createFileSystem(fsBuff);

			auto output = fs->read(inode, &fileSize);

			if (output) {
				fwrite(output, fileSize, 1, stdout);
				err = 0;
			}

			delete fs;
			delete fsBuff;
		} else {
			fprintf(stderr, "Could not open file: %s\n", fsPath);
		}
	}
	return err;
}

int write(int argc, char **args) {
	auto err = 0;
	if (argc >= 5) {
		auto fsPath = args[2];
		auto inode = ox::std::atoi(args[3]);
		auto srcPath = args[4];
		::size_t srcSize;

		auto fsFile = fopen(fsPath, "rb");
		if (fsFile) {
			fseek(fsFile, 0, SEEK_END);

			const auto fsSize = (::size_t) ftell(fsFile);
			rewind(fsFile);
			auto fsBuff = (char*) malloc(fsSize);
			fread(fsBuff, fsSize, 1, fsFile);
			fclose(fsFile);

			auto srcBuff = loadFileBuff(srcPath, &srcSize);
			if (srcBuff) {
				auto fs = createFileSystem(fsBuff);
				if (fs) {
					err |= fs->write(inode, srcBuff, srcSize);
				} else {
					fprintf(stderr, "Invalid file system.\n");
				}

				if (err) {
					fprintf(stderr, "Could not write to file system.\n");
				} else {
					fsFile = fopen(fsPath, "wb");

					if (fsFile) {
						err = fwrite(fsBuff, fsSize, 1, fsFile) != 1;
						err |= fclose(fsFile);
						if (err) {
							fprintf(stderr, "Could not write to file system file.\n");
						}
					} else {
						err = 1;
					}
				}
			} else {
				err = 1;
				fprintf(stderr, "Could not load source file.\n");
			}

			free(fsBuff);
			free(srcBuff);
		} else {
			fprintf(stderr, "Could not open file system\n");
		}
	}
	return err;
}

int main(int argc, char **args) {
	auto err = 0;
	if (argc > 1) {
		auto cmd = args[1];
		if (::strcmp(cmd, "format") == 0) {
			err = format(argc, args);
		} else if (::strcmp(cmd, "read") == 0) {
			err = read(argc, args);
		} else if (::strcmp(cmd, "write") == 0) {
			err = write(argc, args);
		} else if (::strcmp(cmd, "help") == 0) {
			printf("%s\n", usage);
		} else {
			printf("Command '%s' not recognized.\n", cmd);
			err = 1;
		}
	} else {
		printf("%s\n", usage);
	}
	return err;
}
<commit_msg>Add include that is needed for Linux builds<commit_after>/*
 * Copyright 2015 - 2016 gtalent2@gmail.com
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ox/std/strops.hpp>
#include <ox/fs/filesystem.hpp>

using namespace ox::fs;

const char *usage = "usage:\n"
"\toxfs format [16,32,64] <size> <path>\n"
"\toxfs read <FS file> <inode>\n"
"\toxfs write <FS file> <inode> <insertion file>";

char *loadFileBuff(const char *path, ::size_t *sizeOut = nullptr) {
	FILE *file = fopen(path, "rb");
	if (file) {
		fseek(file, 0, SEEK_END);
		const auto size = ftell(file);
		rewind(file);
		auto buff = (char*) malloc(size);
		fread(buff, size, 1, file);
		fclose(file);
		if (sizeOut) {
			*sizeOut = size;
		}
		return buff;
	} else {
		return nullptr;
	}
}

int format(int argc, char **args) {
	printf("Creating file system...\n");
	auto err = 1;
	if (argc >= 5) {
		auto type = ox::std::atoi(args[2]);
		auto size = ox::std::atoi(args[3]);
		auto path = args[4];
		auto buff = (ox::std::uint8_t*) malloc(size);

		printf("Size: %d bytes\n", size);
		printf("Type: %d\n", type);

		// format
		switch (type) {
			case 16:
				FileStore16::format(buff, size, ox::fs::OxFS_16);
				break;
			case 32:
				FileStore32::format(buff, size, ox::fs::OxFS_32);
				break;
			case 64:
				FileStore64::format(buff, size, ox::fs::OxFS_64);
				break;
		}
		createFileSystem(buff);

		auto file = fopen(path, "wb");
		if (file) {
			fwrite(buff, size, 1, file);
			err = fclose(file);
			if (err) {
				printf("Could not write to file: %s.\n", path);
			}
		} else {
			printf("Could not open file: %s.\n", path);
		}

		if (err == 0) {
			printf("Created file system %s\n", path);
		}
	}

	return err;
}

int read(int argc, char **args) {
	auto err = 1;
	if (argc >= 4) {
		auto fsPath = args[2];
		auto inode = ox::std::atoi(args[3]);
		::size_t fsSize;
		ox::std::uint64_t fileSize;

		auto fsBuff = loadFileBuff(fsPath, &fsSize);

		if (fsBuff) {
			auto fs = createFileSystem(fsBuff);

			auto output = fs->read(inode, &fileSize);

			if (output) {
				fwrite(output, fileSize, 1, stdout);
				err = 0;
			}

			delete fs;
			delete fsBuff;
		} else {
			fprintf(stderr, "Could not open file: %s\n", fsPath);
		}
	}
	return err;
}

int write(int argc, char **args) {
	auto err = 0;
	if (argc >= 5) {
		auto fsPath = args[2];
		auto inode = ox::std::atoi(args[3]);
		auto srcPath = args[4];
		::size_t srcSize;

		auto fsFile = fopen(fsPath, "rb");
		if (fsFile) {
			fseek(fsFile, 0, SEEK_END);

			const auto fsSize = (::size_t) ftell(fsFile);
			rewind(fsFile);
			auto fsBuff = (char*) malloc(fsSize);
			fread(fsBuff, fsSize, 1, fsFile);
			fclose(fsFile);

			auto srcBuff = loadFileBuff(srcPath, &srcSize);
			if (srcBuff) {
				auto fs = createFileSystem(fsBuff);
				if (fs) {
					err |= fs->write(inode, srcBuff, srcSize);
				} else {
					fprintf(stderr, "Invalid file system.\n");
				}

				if (err) {
					fprintf(stderr, "Could not write to file system.\n");
				} else {
					fsFile = fopen(fsPath, "wb");

					if (fsFile) {
						err = fwrite(fsBuff, fsSize, 1, fsFile) != 1;
						err |= fclose(fsFile);
						if (err) {
							fprintf(stderr, "Could not write to file system file.\n");
						}
					} else {
						err = 1;
					}
				}
			} else {
				err = 1;
				fprintf(stderr, "Could not load source file.\n");
			}

			free(fsBuff);
			free(srcBuff);
		} else {
			fprintf(stderr, "Could not open file system\n");
		}
	}
	return err;
}

int main(int argc, char **args) {
	auto err = 0;
	if (argc > 1) {
		auto cmd = args[1];
		if (::strcmp(cmd, "format") == 0) {
			err = format(argc, args);
		} else if (::strcmp(cmd, "read") == 0) {
			err = read(argc, args);
		} else if (::strcmp(cmd, "write") == 0) {
			err = write(argc, args);
		} else if (::strcmp(cmd, "help") == 0) {
			printf("%s\n", usage);
		} else {
			printf("Command '%s' not recognized.\n", cmd);
			err = 1;
		}
	} else {
		printf("%s\n", usage);
	}
	return err;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: sdattr.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2004-07-06 12:24:14 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

#include "sdattr.hxx"

using namespace ::com::sun::star;

/*************************************************************************
|*
|*  DiaEffectItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaEffectItem, SfxEnumItem );

DiaEffectItem::DiaEffectItem( presentation::FadeEffect eFE ) :
    SfxEnumItem( ATTR_DIA_EFFECT, eFE )
{
}

DiaEffectItem::DiaEffectItem( SvStream& rIn ) :
    SfxEnumItem( ATTR_DIA_EFFECT, rIn )
{
}

SfxPoolItem* DiaEffectItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaEffectItem( *this );
}

SfxPoolItem* DiaEffectItem::Create( SvStream& rIn, USHORT nVer ) const
{
    return new DiaEffectItem( rIn );
}

/*************************************************************************
|*
|*  DiaSpeedItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaSpeedItem, SfxEnumItem );

DiaSpeedItem::DiaSpeedItem( FadeSpeed eFS ) :
    SfxEnumItem( ATTR_DIA_SPEED, eFS )
{
}

DiaSpeedItem::DiaSpeedItem( SvStream& rIn ) :
    SfxEnumItem( ATTR_DIA_SPEED, rIn )
{
}

SfxPoolItem* DiaSpeedItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaSpeedItem( *this );
}

SfxPoolItem* DiaSpeedItem::Create( SvStream& rIn, USHORT nVer ) const
{
    return new DiaSpeedItem( rIn );
}

/*************************************************************************
|*
|*  DiaAutoItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaAutoItem, SfxEnumItem );

DiaAutoItem::DiaAutoItem( PresChange eChange ) :
    SfxEnumItem( ATTR_DIA_AUTO, eChange )
{
}

DiaAutoItem::DiaAutoItem( SvStream& rIn ) :
    SfxEnumItem( ATTR_DIA_AUTO, rIn )
{
}

SfxPoolItem* DiaAutoItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaAutoItem( *this );
}

SfxPoolItem* DiaAutoItem::Create( SvStream& rIn, USHORT nVer ) const
{
    return new DiaAutoItem( rIn );
}

/*************************************************************************
|*
|*  DiaTimeItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaTimeItem, SfxUInt32Item );

DiaTimeItem::DiaTimeItem( UINT32 nValue ) :
        SfxUInt32Item( ATTR_DIA_TIME, nValue )
{
}

SfxPoolItem* DiaTimeItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaTimeItem( *this );
}

int DiaTimeItem::operator==( const SfxPoolItem& rItem ) const
{
    return( ( (DiaTimeItem&) rItem ).GetValue() == GetValue() );
}

<commit_msg>INTEGRATION: CWS ooo19126 (1.3.458); FILE MERGED 2005/09/05 13:20:20 rt 1.3.458.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sdattr.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 03:13:09 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#pragma hdrstop

#include "sdattr.hxx"

using namespace ::com::sun::star;

/*************************************************************************
|*
|*  DiaEffectItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaEffectItem, SfxEnumItem );

DiaEffectItem::DiaEffectItem( presentation::FadeEffect eFE ) :
    SfxEnumItem( ATTR_DIA_EFFECT, eFE )
{
}

DiaEffectItem::DiaEffectItem( SvStream& rIn ) :
    SfxEnumItem( ATTR_DIA_EFFECT, rIn )
{
}

SfxPoolItem* DiaEffectItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaEffectItem( *this );
}

SfxPoolItem* DiaEffectItem::Create( SvStream& rIn, USHORT nVer ) const
{
    return new DiaEffectItem( rIn );
}

/*************************************************************************
|*
|*  DiaSpeedItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaSpeedItem, SfxEnumItem );

DiaSpeedItem::DiaSpeedItem( FadeSpeed eFS ) :
    SfxEnumItem( ATTR_DIA_SPEED, eFS )
{
}

DiaSpeedItem::DiaSpeedItem( SvStream& rIn ) :
    SfxEnumItem( ATTR_DIA_SPEED, rIn )
{
}

SfxPoolItem* DiaSpeedItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaSpeedItem( *this );
}

SfxPoolItem* DiaSpeedItem::Create( SvStream& rIn, USHORT nVer ) const
{
    return new DiaSpeedItem( rIn );
}

/*************************************************************************
|*
|*  DiaAutoItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaAutoItem, SfxEnumItem );

DiaAutoItem::DiaAutoItem( PresChange eChange ) :
    SfxEnumItem( ATTR_DIA_AUTO, eChange )
{
}

DiaAutoItem::DiaAutoItem( SvStream& rIn ) :
    SfxEnumItem( ATTR_DIA_AUTO, rIn )
{
}

SfxPoolItem* DiaAutoItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaAutoItem( *this );
}

SfxPoolItem* DiaAutoItem::Create( SvStream& rIn, USHORT nVer ) const
{
    return new DiaAutoItem( rIn );
}

/*************************************************************************
|*
|*  DiaTimeItem
|*
*************************************************************************/
TYPEINIT1_AUTOFACTORY( DiaTimeItem, SfxUInt32Item );

DiaTimeItem::DiaTimeItem( UINT32 nValue ) :
        SfxUInt32Item( ATTR_DIA_TIME, nValue )
{
}

SfxPoolItem* DiaTimeItem::Clone( SfxItemPool* pPool ) const
{
    return new DiaTimeItem( *this );
}

int DiaTimeItem::operator==( const SfxPoolItem& rItem ) const
{
    return( ( (DiaTimeItem&) rItem ).GetValue() == GetValue() );
}

<|endoftext|>