Пример #1
0
int WorkTodo::read_req( const xmlNodePtr xn )
{
	int ret = 1;
	char* tmp = (char*) xmlGetProp( xn, (const xmlChar*) "type" );
	
	if( tmp == NULL ) {
		fprintf(stderr, "Warning, no request type specified.\n");
		ret = 0;
	} else if( strcmp( tmp, "contract_details") == 0 ) {
		PacketContractDetails *pcd = PacketContractDetails::fromXml(xn);
		_contractDetailsTodo->add(pcd->getRequest());
		delete pcd;
	} else if ( strcmp( tmp, "historical_data") == 0 ) {
		PacketHistData *phd = PacketHistData::fromXml(xn);
		_histTodo->add( phd->getRequest() );
		delete phd;
	} else if ( strcmp( tmp, "place_order") == 0 ) {
		PacketPlaceOrder *ppo = PacketPlaceOrder::fromXml(xn);
		_place_order_todo->add( ppo->getRequest() );
		delete ppo;
	} else if ( strcmp( tmp, "market_data") == 0 ) {
		PacketMktData *pmd = PacketMktData::fromXml(xn);
		_market_data_todo->add( pmd->getRequest() );
		delete pmd;
		// HACK always get contractDetails too
		PacketContractDetails *pcd = PacketContractDetails::fromXml(xn);
		_contractDetailsTodo->add(pcd->getRequest());
		delete pcd;
	} else if ( strcmp( tmp, "account") == 0 ) {
		addSimpleRequest(GenericRequest::ACC_STATUS_REQUEST);
	} else if ( strcmp( tmp, "executions") == 0 ) {
		addSimpleRequest(GenericRequest::EXECUTIONS_REQUEST);
	} else if ( strcmp( tmp, "open_orders") == 0 ) {
		addSimpleRequest(GenericRequest::ORDERS_REQUEST);
	} else {
		fprintf(stderr, "Warning, unknown request type '%s' ignored.\n", tmp );
		ret = 0;
	}
	
	free(tmp);
	return ret;
}
bool
CXWindowsClipboard::insertMultipleReply(Window requestor,
				::Time time, Atom property)
{
	// get the requested targets
	Atom target;
	SInt32 format;
	CString data;
	if (!CXWindowsUtil::getWindowProperty(m_display, requestor,
								property, &data, &target, &format, False)) {
		// can't get the requested targets
		return false;
	}

	// fail if the requested targets isn't of the correct form
	if (format != 32 ||
		target != m_atomAtomPair) {
		return false;
	}

	// data is a list of atom pairs:  target, property
	const Atom* targets = reinterpret_cast<const Atom*>(data.data());
	const UInt32 numTargets = data.size() / sizeof(Atom);

	// add replies for each target
	bool changed = false;
	for (UInt32 i = 0; i < numTargets; i += 2) {
		const Atom target   = targets[i + 0];
		const Atom property = targets[i + 1];
		if (!addSimpleRequest(requestor, target, time, property)) {
			// note that we can't perform the requested conversion
			static const Atom none = None;
			data.replace(i * sizeof(Atom), sizeof(Atom),
								reinterpret_cast<const char*>(&none),
								sizeof(Atom));
			changed = true;
		}
	}

	// update the targets property if we changed it
	if (changed) {
		CXWindowsUtil::setWindowProperty(m_display, requestor,
								property, data.data(), data.size(),
								target, format);
	}

	// add reply for MULTIPLE request
	insertReply(new CReply(requestor, m_atomMultiple,
								time, property, CString(), None, 32));

	return true;
}
Пример #3
0
void
XWindowsClipboard::addRequest(Window owner, Window requestor,
				Atom target, ::Time time, Atom property)
{
	// must be for our window and we must have owned the selection
	// at the given time.
	bool success = false;
	if (owner == m_window) {
		LOG((CLOG_DEBUG1 "request for clipboard %d, target %s by 0x%08x (property=%s)", m_selection, XWindowsUtil::atomToString(m_display, target).c_str(), requestor, XWindowsUtil::atomToString(m_display, property).c_str()));
		if (wasOwnedAtTime(time)) {
			if (target == m_atomMultiple) {
				// add a multiple request.  property may not be None
				// according to ICCCM.
				if (property != None) {
					success = insertMultipleReply(requestor, time, property);
				}
			}
			else {
				addSimpleRequest(requestor, target, time, property);

				// addSimpleRequest() will have already handled failure
				success = true;
			}
		}
		else {
			LOG((CLOG_DEBUG1 "failed, not owned at time %d", time));
		}
	}

	if (!success) {
		// send failure
		LOG((CLOG_DEBUG1 "failed"));
		insertReply(new Reply(requestor, target, time));
	}

	// send notifications that are pending
	pushReplies();
}