void DOMFileSystem::getFile(ScriptExecutionContext& context, FileSystemFileEntry& fileEntry, GetFileCallback&& completionCallback)
{
    auto virtualPath = fileEntry.virtualPath();
    auto fullPath = evaluatePath(virtualPath);
    m_workQueue->dispatch([context = makeRef(context), fullPath = crossThreadCopy(fullPath), virtualPath = crossThreadCopy(virtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
        auto validatedVirtualPath = validatePathIsExpectedType(fullPath, WTFMove(virtualPath), FileMetadata::Type::File);
        callOnMainThread([context = WTFMove(context), fullPath = crossThreadCopy(fullPath), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
            if (validatedVirtualPath.hasException())
                completionCallback(validatedVirtualPath.releaseException());
            else
                completionCallback(File::create(fullPath));
        });
    });
}
void DOMFileSystem::getParent(ScriptExecutionContext& context, FileSystemEntry& entry, GetParentCallback&& completionCallback)
{
    ASSERT(&entry.filesystem() == this);

    auto virtualPath = resolveRelativeVirtualPath(entry.virtualPath(), "..");
    ASSERT(virtualPath[0] == '/');
    auto fullPath = evaluatePath(virtualPath);
    m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), virtualPath = crossThreadCopy(virtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
        auto validatedVirtualPath = validatePathIsExpectedType(fullPath, WTFMove(virtualPath), FileMetadata::Type::Directory);
        callOnMainThread([this, context = WTFMove(context), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
            if (validatedVirtualPath.hasException())
                completionCallback(validatedVirtualPath.releaseException());
            else
                completionCallback(FileSystemDirectoryEntry::create(context, *this, validatedVirtualPath.releaseReturnValue()));
        });
    });
}
示例#3
0
文件: clinenoise.c 项目: CORDEA/Nim
/* This is an helper function for linenoiseEdit() and is called when the
 * user types the <tab> key in order to complete the string currently in the
 * input.
 *
 * The state of the editing is encapsulated into the pointed linenoiseState
 * structure as described in the structure definition. */
static int completeLine(struct linenoiseState *ls) {
    linenoiseCompletions lc = { 0, NULL };
    int nread, nwritten;
    char c = 0;

    completionCallback(ls->buf,&lc);
    if (lc.len == 0) {
        linenoiseBeep();
    } else {
        size_t stop = 0, i = 0;

        while(!stop) {
            /* Show completion or original buffer */
            if (i < lc.len) {
                struct linenoiseState saved = *ls;

                ls->len = ls->pos = strlen(lc.cvec[i]);
                ls->buf = lc.cvec[i];
                refreshLine(ls);
                ls->len = saved.len;
                ls->pos = saved.pos;
                ls->buf = saved.buf;
            } else {
                refreshLine(ls);
            }

            nread = read(ls->ifd,&c,1);
            if (nread <= 0) {
                freeCompletions(&lc);
                return -1;
            }

            switch(c) {
                case 9: /* tab */
                    i = (i+1) % (lc.len+1);
                    if (i == lc.len) linenoiseBeep();
                    break;
                case 27: /* escape */
                    /* Re-show original buffer */
                    if (i < lc.len) refreshLine(ls);
                    stop = 1;
                    break;
                default:
                    /* Update buffer and return */
                    if (i < lc.len) {
                        nwritten = snprintf(ls->buf,ls->buflen,"%s",lc.cvec[i]);
                        ls->len = ls->pos = nwritten;
                    }
                    stop = 1;
                    break;
            }
        }
    }

    freeCompletions(&lc);
    return c; /* Return last read character */
}
示例#4
0
static int completeLine(int fd, const char *prompt, char *buf, size_t buflen, size_t *len, size_t *pos, size_t cols) {
    linenoiseCompletions lc = { 0, NULL };
    int nwritten;
    char c = 0;

    completionCallback(buf,&lc);
    if (lc.len == 0) {
        beep();
    } else {
        size_t stop = 0, i = 0;
        size_t clen;

        while(!stop) {
            /* Show completion or original buffer */
            if (i < lc.len) {
                clen = strlen(lc.cvec[i]);
                refreshLine(fd,prompt,lc.cvec[i],clen,clen,cols);
            } else {
                refreshLine(fd,prompt,buf,*len,*pos,cols);
            }

            do {
                c = linenoiseReadChar(fd);
            } while (c == (char)-1);

            switch(c) {
                case 0:
                    freeCompletions(&lc);
                    return -1;
                case 9: /* tab */
                    i = (i+1) % (lc.len+1);
                    if (i == lc.len) beep();
                    break;
                case 27: /* escape */
                    /* Re-show original buffer */
                    if (i < lc.len) {
                        refreshLine(fd,prompt,buf,*len,*pos,cols);
                    }
                    stop = 1;
                    break;
                default:
                    /* Update buffer and return */
                    if (i < lc.len) {
                        nwritten = snprintf(buf,buflen,"%s",lc.cvec[i]);
                        *len = *pos = nwritten;
                    }
                    stop = 1;
                    break;
            }
        }
    }

    freeCompletions(&lc);
    return c; /* Return last read character */
}
示例#5
0
static int completeLine(struct current *current) {
    linenoiseCompletions lc = { 0, NULL };
    int c = 0;

    completionCallback(current->buf,&lc,completionUserdata);
    if (lc.len == 0) {
        beep();
    } else {
        size_t stop = 0, i = 0;

        while(!stop) {
            /* Show completion or original buffer */
            if (i < lc.len) {
                struct current tmp = *current;
                tmp.buf = lc.cvec[i];
                tmp.pos = tmp.len = strlen(tmp.buf);
                tmp.chars = utf8_strlen(tmp.buf, tmp.len);
                refreshLine(current->prompt, &tmp);
            } else {
                refreshLine(current->prompt, current);
            }

            c = fd_read(current);
            if (c == -1) {
                break;
            }

            switch(c) {
                case '\t': /* tab */
                    i = (i+1) % (lc.len+1);
                    if (i == lc.len) beep();
                    break;
                case 27: /* escape */
                    /* Re-show original buffer */
                    if (i < lc.len) {
                        refreshLine(current->prompt, current);
                    }
                    stop = 1;
                    break;
                default:
                    /* Update buffer and return */
                    if (i < lc.len) {
                        set_current(current,lc.cvec[i]);
                    }
                    stop = 1;
                    break;
            }
        }
    }

    freeCompletions(&lc);
    return c; /* Return last read character */
}
// This should never be called directly, the transfer manager is responsible for
// aborting the transfer from the channel.  I might want to rethink this in the
// future, though.
void LLTransferTarget::abortTransfer()
{
	// Send a message up, call the completion callback
	llinfos << "LLTransferTarget::Aborting transfer " << getID() << " from " << mChannelp->getHost() << llendl;
	gMessageSystem->newMessage("TransferAbort");
	gMessageSystem->nextBlock("TransferInfo");
	gMessageSystem->addUUID("TransferID", getID());
	gMessageSystem->addS32("ChannelType", mChannelp->getChannelType());
	gMessageSystem->sendReliable(mChannelp->getHost());

	completionCallback(LLTS_ABORT);
}
// https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getfile
// https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getdirectory
void DOMFileSystem::getEntry(ScriptExecutionContext& context, FileSystemDirectoryEntry& directory, const String& virtualPath, const FileSystemDirectoryEntry::Flags& flags, GetEntryCallback&& completionCallback)
{
    ASSERT(&directory.filesystem() == this);

    if (!isValidVirtualPath(virtualPath)) {
        callOnMainThread([completionCallback = WTFMove(completionCallback)] {
            completionCallback(Exception { TypeMismatchError, "Path is invalid"_s });
        });
        return;
    }

    if (flags.create) {
        callOnMainThread([completionCallback = WTFMove(completionCallback)] {
            completionCallback(Exception { SecurityError, "create flag cannot be true"_s });
        });
        return;
    }

    auto resolvedVirtualPath = resolveRelativeVirtualPath(directory.virtualPath(), virtualPath);
    ASSERT(resolvedVirtualPath[0] == '/');
    auto fullPath = evaluatePath(resolvedVirtualPath);
    if (fullPath == m_rootPath) {
        callOnMainThread([this, context = makeRef(context), completionCallback = WTFMove(completionCallback)]() mutable {
            completionCallback(Ref<FileSystemEntry> { root(context) });
        });
        return;
    }

    m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), resolvedVirtualPath = crossThreadCopy(resolvedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable {
        auto entryType = fileType(fullPath);
        callOnMainThread([this, context = WTFMove(context), resolvedVirtualPath = crossThreadCopy(resolvedVirtualPath), entryType, completionCallback = WTFMove(completionCallback)]() mutable {
            if (!entryType) {
                completionCallback(Exception { NotFoundError, "Cannot find entry at given path"_s });
                return;
            }
            switch (entryType.value()) {
            case FileMetadata::Type::Directory:
                completionCallback(Ref<FileSystemEntry> { FileSystemDirectoryEntry::create(context, *this, resolvedVirtualPath) });
                break;
            case FileMetadata::Type::File:
                completionCallback(Ref<FileSystemEntry> { FileSystemFileEntry::create(context, *this, resolvedVirtualPath) });
                break;
            default:
                completionCallback(Exception { NotFoundError, "Cannot find entry at given path"_s });
                break;
            }
        });
    });
}
void LLTransferSource::sendTransferStatus(LLTSCode status)
{
	gMessageSystem->newMessage("TransferInfo");
	gMessageSystem->nextBlock("TransferInfo");
	gMessageSystem->addUUID("TransferID", getID());
	gMessageSystem->addS32("TargetType", LLTTT_UNKNOWN);
	gMessageSystem->addS32("ChannelType", mChannelp->getChannelType());
	gMessageSystem->addS32("Status", status);
	gMessageSystem->addS32("Size", mSize);
	U8 tmp[MAX_PARAMS_SIZE];
	LLDataPackerBinaryBuffer dp(tmp, MAX_PARAMS_SIZE);
	packParams(dp);
	S32 len = dp.getCurrentSize();
	gMessageSystem->addBinaryData("Params", tmp, len);
	gMessageSystem->sendReliable(mChannelp->getHost());

	// Abort if there was as asset system issue.
	if (status != LLTS_OK)
	{
		completionCallback(status);
		mChannelp->deleteTransfer(this);
	}
}
示例#9
0
void AnimationHandler::update()
{
    //Update each animation
    for(auto iter = activeAnimations.begin(); iter != activeAnimations.end();)
    {
        bool didFinish = false;

        if(auto current = iter->widget.lock())
        {
            float moveAmount = iter->animationSpeed*(elapsedTime.getElapsedTime().asSeconds()/updateCount);
            switch(iter->animationType)
            {
            case Types::Glide:
            {
                if(current->getPosition().x > iter->target.x)
                {
                    current->move({-moveAmount, 0});
                }
                else if(current->getPosition().x < iter->target.x)
                {
                    current->move({moveAmount, 0});
                }
                if(current->getPosition().y > iter->target.y)
                {
                    current->move({0, -moveAmount});
                }
                else if(current->getPosition().y < iter->target.y)
                {
                    current->move({0, moveAmount});
                }
                //Check to see if it's reached its destination yet
                if(isInRange(current->getPosition().x, iter->target.x-moveAmount, iter->target.x+moveAmount) && isInRange(current->getPosition().y, iter->target.y-moveAmount, iter->target.y+moveAmount))
                {
                    //If so, set it's position to target to ensure that it's at exactly the specified place and then remove the transfer
                    current->setPosition(iter->target);
                    iter->completionCallback();
                    iter = activeAnimations.erase(iter);
                    didFinish = true;
                }
                break;
            }
            case Types::Fade:
            {
                if(iter->isFading)
                {
                    int newAlphaColor = static_cast<int>(current->getColor().a)-fadeSpeed;
                    if(newAlphaColor > 0)
                        current->setColor(sf::Color(current->getColor().r, current->getColor().g, current->getColor().b, current->getColor().a-fadeSpeed));
                    else
                    {
                        current->setColor(sf::Color(current->getColor().r, current->getColor().g, current->getColor().b, 0)); //Set to transparent to be sure
                        iter->isFading = false;
                        current->setPosition(iter->target); //Move it to the right place
                    }
                }
                else
                {
                    int newAlphaColor = static_cast<int>(current->getColor().a)+fadeSpeed;
                    if(newAlphaColor < 255)
                        current->setColor(sf::Color(current->getColor().r, current->getColor().g, current->getColor().b, current->getColor().a+fadeSpeed));
                    else
                    {
                        current->setColor(sf::Color(current->getColor().r, current->getColor().g, current->getColor().b, 255)); //255 for max RGB color
                        //Fade complete, remove the transfer
                        iter->completionCallback();
                        iter = activeAnimations.erase(iter);
                        didFinish = true;
                    }
                }
                break;
            }
            case Types::Expand:
            {
                if(current->getSize().x < iter->target.x)
                {
                    current->setSize({current->getSize().x+moveAmount, current->getSize().y});
                }
                else if(current->getSize().x > iter->target.x)
                {
                    current->setSize({current->getSize().x-moveAmount, current->getSize().y});
                }
                if(current->getSize().y < iter->target.y)
                {
                    current->setSize({current->getSize().x, current->getSize().y+moveAmount});
                }
                else if(current->getSize().y > iter->target.y)
                {
                    current->setSize({current->getSize().x, current->getSize().y-moveAmount});
                }
                //Check to see if it's reached its destination yet
                if(isInRange(current->getSize().x, iter->target.x-moveAmount, iter->target.x+moveAmount) && isInRange(current->getSize().y, iter->target.y-moveAmount, iter->target.y+moveAmount))
                {
                    //If so, set it's position to target to ensure that it's at exactly the specified place and then remove the transfer
                    current->setSize(iter->target);
                    iter->completionCallback();
                    iter = activeAnimations.erase(iter);
                    didFinish = true;
                }
                break;
            }
            default:
                sf::err() << "\nUnknown animation type in animation update... internal error D:";
            }
        }
        else //No such widget, remove it
        {
            iter = activeAnimations.erase(iter);
            didFinish = true;
        }

        if(!didFinish)
            iter++;
    }
    updateCount++;
}
static int completeLine(struct linenoiseState *ls)
{
	linenoiseCompletions lc = { 0, NULL };
	int nwritten = 0;
	char c = 0;

	completionCallback(ls->buf, &lc);

	if (lc.len == 0) {
		linenoiseBeep();

	} else {
		size_t stop = 0, i = 0;

		while (!stop) {
			/* Show completion or original buffer */
			if (i < lc.len) {
				struct linenoiseState saved = *ls;

				ls->len = ls->pos = strlen(lc.cvec[i]);
				ls->buf = lc.cvec[i];
				refreshLine(ls);
				ls->len = saved.len;
				ls->pos = saved.pos;
				ls->buf = saved.buf;

			} else {
				refreshLine(ls);
			}

			c = serial.getc();

			switch (c) {
			case TAB: /* tab */
				i = (i + 1) % (lc.len + 1);

				if (i == lc.len) linenoiseBeep();

				break;

			case ESC: /* escape */

				/* Re-show original buffer */
				if (i < lc.len) refreshLine(ls);

				stop = 1;
				break;

			default:

				/* Update buffer and return */
				if (i < lc.len) {
					for (nwritten = 0; nwritten < ls->buflen; nwritten++) {
						ls->buf[nwritten] = lc.cvec[i][nwritten];

						if (lc.cvec[i][nwritten] == '\0')
							break;
					}

					ls->len = ls->pos = nwritten;
				}

				stop = 1;
				break;
			}
		}
	}

	freeCompletions(&lc);
	return c; /* Return last read character */
}