Ejemplo n.º 1
0
// FreeQueryIterator
void
ServerVolume::FreeQueryIterator(QueryIterator* _iterator)
{
	ServerQueryIterator* iterator
		= dynamic_cast<ServerQueryIterator*>(_iterator);

	int32 cookie = iterator->GetRemoteCookie();
	if (cookie >= 0) {
		// prepare the close request
		CloseRequest request;
		request.volumeID = -1;
		request.cookie = cookie;

		// send the request
		ServerConnection* serverConnection
			= fConnectionProvider->GetExistingServerConnection();
		if (serverConnection && serverConnection->IsConnected()) {
			CloseReply* reply;
			status_t error = SendRequest(
				serverConnection->GetRequestConnection(), &request, &reply);
			if (error == B_OK)
				delete reply;
		}
	}

	delete iterator;
}
Ejemplo n.º 2
0
// ReadQuery
status_t
ServerVolume::ReadQuery(QueryIterator* _iterator, struct dirent* buffer,
	size_t bufferSize, int32 count, int32* countRead)
{
	// get connection
	ServerConnection* serverConnection
		= fConnectionProvider->GetExistingServerConnection();
	if (!serverConnection)
		return ERROR_NOT_CONNECTED;
	RequestConnection* connection = serverConnection->GetRequestConnection();

	ServerQueryIterator* iterator
		= dynamic_cast<ServerQueryIterator*>(_iterator);

	*countRead = 0;

	for (;;) {
		// if the iterator hasn't cached any more share volume IDs, we need to
		// ask the server for the next entry
		if (!iterator->HasNextShareVolumeID()) {
			// prepare the request
			ReadQueryRequest request;
			request.cookie = iterator->GetRemoteCookie();
			request.count = 1;

			// send the request
			ReadQueryReply* reply;
			status_t error = SendRequest(connection, &request, &reply);
			if (error != B_OK)
				RETURN_ERROR(error);
			ObjectDeleter<Request> replyDeleter(reply);
			if (reply->error != B_OK)
				RETURN_ERROR(reply->error);

			// check, if anything has been read at all
			if (reply->count == 0) {
				*countRead = 0;
				return B_OK;
			}

			// update the iterator
			error = iterator->SetEntry(reply->clientVolumeIDs.GetElements(),
				reply->clientVolumeIDs.CountElements(), reply->dirInfo,
				reply->entryInfo);
			if (error != B_OK)
				return error;
		}

		// get the next concerned share volume and delegate the rest of the work
		int32 volumeID = iterator->NextShareVolumeID();
		ShareVolume* shareVolume = _GetShareVolume(volumeID);
		if (!shareVolume)
			continue;
		VolumePutter volumePutter(shareVolume);

		return shareVolume->GetQueryEntry(iterator->GetEntryInfo(),
			iterator->GetDirectoryInfo(), buffer, bufferSize, countRead);
	}
}
Ejemplo n.º 3
0
// OpenQuery
status_t
ServerVolume::OpenQuery(const char* queryString, uint32 flags, port_id port,
	int32 token, QueryIterator** _iterator)
{
// TODO: Do nothing when there are no (mounted) shares.
	// get connection
	ServerConnection* serverConnection
		= fConnectionProvider->GetExistingServerConnection();
	if (!serverConnection)
		return ERROR_NOT_CONNECTED;
	RequestConnection* connection = serverConnection->GetRequestConnection();

	// create a query iterator and add it to the query manager
	ServerQueryIterator* iterator = new(std::nothrow) ServerQueryIterator(this);
	if (!iterator)
		return B_NO_MEMORY;
	QueryManager* queryManager = fVolumeManager->GetQueryManager();
	status_t error = queryManager->AddIterator(iterator);
	if (error != B_OK) {
		delete iterator;
		return error;
	}
	QueryIteratorPutter iteratorPutter(queryManager, iterator);

	// prepare the request
	OpenQueryRequest request;
	request.queryString.SetTo(queryString);
	request.flags = flags;
	request.port = port;
	request.token = token;

	// send the request
	OpenQueryReply* reply;
	error = SendRequest(connection, &request, &reply);
	if (error != B_OK)
		RETURN_ERROR(error);
	ObjectDeleter<Request> replyDeleter(reply);
	if (reply->error != B_OK)
		RETURN_ERROR(reply->error);

	// set the result
	iterator->SetRemoteCookie(reply->cookie);
	*_iterator = iterator;
	iteratorPutter.Detach();
	return B_OK;
}