Beispiel #1
0
bool Controller::loadJob(char* path, char * job)
{
    bool rtn = false;
    int status;    
    
    LOG_DEBUG("Refreshing file list");
    status = mpRefreshFileList(MP_EXT_ID_JBI);
    if (this->MP_OK != status)
    {
    	LOG_WARN("Failed to refresh file list: %d, ignoring failure", status);
    }
    LOG_DEBUG("File count before file load: %d", mpGetFileCount());
    
    LOG_DEBUG("Attempting to load file, path: %s, job: %s", path, job);
    status = mpLoadFile (MP_DRV_ID_DRAM, path, job );
    if (this->MP_OK == status)
    {
        LOG_INFO("Loaded job file %s", job);
        rtn = true;
    }
    else
    {
        LOG_ERROR("Failed to load job file: %s, path: %s, returned error code: %d",
                    job, path, status);
        rtn = false;
    }
    
    LOG_DEBUG("Refreshing file list");
    status = mpRefreshFileList(MP_EXT_ID_JBI);
    if (this->MP_OK != status)
    {
    	LOG_WARN("Failed to refresh file list: %d, ignoring failure", status);
    }
    LOG_DEBUG("File count after file load: %d", mpGetFileCount());
    
    return rtn;

}
Beispiel #2
0
int handleExFileFunctionRequest(int acceptHandle, char *inBuffer, char *outBuffer, int type, int msgSize) {
    int32_t ret = -1;
    int32_t index = -1;
    int32_t ramDriveId = -1;
    int32_t fileNameOffset = -1;
    int32_t fd = -1;

    int sendRet = 0;
    int namelen = 0;
    short extensionId = -1;
    MP_FILE_NAME_SEND_DATA fileNameSendData;
    MP_GET_JOBLIST_RSP_DATA jobListData;

    switch (type) {

        case EX_FILE_CTRL_GET_FILE_COUNT:
            if (msgSize != 10) {
                fprintf(stderr, "tcpSvr: invalid msgSize for mpGetFileCount = %d != 10\n", msgSize);
                return -1;
            }
            extensionId = getInt16(inBuffer, 12);
            if (extensionId < 1 || extensionId > 2) {
                fprintf(stderr, "tcpSvr: invalid extensionId for mpGetFileCount = %d  (must be 1 or 2)\n", extensionId);
                return -1;
            }
            lastExtensionId = -1;
            ret = mpRefreshFileList(extensionId);
            if (ret != 0) {
                setInt32(outBuffer, 0, 4);
                setInt32(outBuffer, 4, ret);
                sendRet = sendN(acceptHandle, outBuffer, 8, 0);
                if (sendRet != 8) {
                    fprintf(stderr, "tcpSvr: sendRet = %d != 8\n", sendRet);
                    return -1;
                }
                return 0;
            }
            lastExtensionId = extensionId;
            ret = mpGetFileCount();
            setInt32(outBuffer, 0, 8);
            setInt32(outBuffer, 4, 0);
            setInt32(outBuffer, 8, ret);
            sendRet = sendN(acceptHandle, outBuffer, 12, 0);
            if (sendRet != 12) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 12\n", sendRet);
                return -1;
            }
            break;

        case EX_FILE_CTRL_GET_FILE_NAME:
            extensionId = getInt16(inBuffer, 12);
            if (extensionId < 1 || extensionId > 2) {
                fprintf(stderr, "tcpSvr: invalid extensionId for mpGetFileName = %d  (must be 1 or 2)\n", extensionId);
                return -1;
            }
            if (extensionId != lastExtensionId) {
                lastExtensionId = -1;
                ret = mpRefreshFileList(extensionId);
                if (ret != 0) {
                    setInt32(outBuffer, 0, 4);
                    setInt32(outBuffer, 4, ret);
                    lastExtensionId = -1;
                    sendRet = sendN(acceptHandle, outBuffer, 8, 0);
                    if (sendRet != 8) {
                        fprintf(stderr, "tcpSvr: sendRet = %d != 8\n", sendRet);
                        return -1;
                    }
                    return 0;
                }
            }
            index = getInt32(inBuffer, 14);
            ret = mpGetFileName(index, outBuffer + 12);
            namelen = strlen(outBuffer + 12);
            setInt32(outBuffer, 0, 8 + namelen + 1);
            setInt32(outBuffer, 4, 0);
            setInt32(outBuffer, 8, ret);
            sendRet = sendN(acceptHandle, outBuffer, 12 + namelen + 1, 0);
            if (sendRet != 12 + namelen + 1) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 12+namelen+1\n", sendRet);
                return -1;
            }
            break;

        case EX_FILE_CTRL_LOAD_FILE:
            ramDriveId = getInt32(inBuffer, 12);
            if (ramDriveId < 1 || ramDriveId > 2) {
                fprintf(stderr, "tcpSvr: invalid ramDriveId for mpLoadFile = %d  (must be 1 or 2)\n", ramDriveId);
                return -1;
            }
            fileNameOffset = getInt32(inBuffer, 16);
            if (fileNameOffset < 20 || fileNameOffset > (BUFF_MAX - 21)) {
                fprintf(stderr, "tcpSvr: invalid fileNameOffset for mpLoadFile = %d  \n", fileNameOffset);
                return -1;
            }
            ret = mpLoadFile(ramDriveId, inBuffer + 20, inBuffer + fileNameOffset);
            setInt32(outBuffer, 0, 4);
            setInt32(outBuffer, 4, ret);
            sendRet = sendN(acceptHandle, outBuffer, 8, 0);
            if (sendRet != 8) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 8\n", sendRet);
                return -1;
            }
            break;

        case EX_FILE_CTRL_SAVE_FILE:
            ramDriveId = getInt32(inBuffer, 12);
            if (ramDriveId < 1 || ramDriveId > 2) {
                fprintf(stderr, "tcpSvr: invalid ramDriveId for mpSaveFile = %d  (must be 1 or 2)\n", ramDriveId);
                return -1;
            }
            fileNameOffset = getInt32(inBuffer, 16);
            if (fileNameOffset < 20 || fileNameOffset > (BUFF_MAX - 21)) {
                fprintf(stderr, "tcpSvr: invalid fileNameOffset for mpSaveFile = %d  \n", fileNameOffset);
                return -1;
            }
            ret = mpSaveFile(ramDriveId, inBuffer + 20, inBuffer + fileNameOffset);
            setInt32(outBuffer, 0, 4);
            setInt32(outBuffer, 4, ret);
            sendRet = sendN(acceptHandle, outBuffer, 8, 0);
            if (sendRet != 8) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 8\n", sendRet);
                return -1;
            }
            break;

        case EX_FILE_CTRL_FD_READ_FILE:
            fd = getInt32(inBuffer, 12);
            if(fd == -99) {
                fd = acceptHandle;
            }
            if (fd < 1 ) {
                fprintf(stderr, "tcpSvr: invalid fd for mpFdReadFile = %d\n", ramDriveId);
                return -1;
            }
            memset(&fileNameSendData,0,sizeof(fileNameSendData));
            strcpy(fileNameSendData.cFileName,inBuffer+16);
            ret = mpFdReadFile(fd, &fileNameSendData);
            setInt32(outBuffer, 0, 4);
            setInt32(outBuffer, 4, ret);
            sendRet = sendN(acceptHandle, outBuffer, 8, 0);
            if (sendRet != 8) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 8\n", sendRet);
                return -1;
            }
            break;
            
        case EX_FILE_CTRL_FD_WRITE_FILE:
            fd = getInt32(inBuffer, 12);
            if(fd == -99) {
                fd = acceptHandle;
            }
            if (fd < 1 ) {
                fprintf(stderr, "tcpSvr: invalid fd for mpFdWriteFile = %d\n", ramDriveId);
                return -1;
            }
            memset(&fileNameSendData,0,sizeof(fileNameSendData));
            strcpy(fileNameSendData.cFileName,inBuffer+16);
            ret = mpFdWriteFile(fd, &fileNameSendData);
            setInt32(outBuffer, 0, 4);
            setInt32(outBuffer, 4, ret);
            sendRet = sendN(acceptHandle, outBuffer, 8, 0);
            if (sendRet != 8) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 8\n", sendRet);
                return -1;
            }
            break;
            
        case EX_FILE_CTRL_FD_GET_JOB_LIST:
            fd = getInt32(inBuffer, 12);
            if(fd == -99) {
                fd = acceptHandle;
            }
            if (fd < 1 ) {
                fprintf(stderr, "tcpSvr: invalid fd for mpFdGetJobList = %d  (must be 1 or 2)\n", ramDriveId);
                return -1;
            }
            memset(&jobListData,0,sizeof(jobListData));
            ret = mpFdGetJobList(fd, &jobListData);
            setInt32(outBuffer, 0, 10);
            setInt32(outBuffer, 4, ret);
            setInt16(outBuffer,8,jobListData.err_no);
            setInt16(outBuffer,10,jobListData.uIsEndFlag);
            setInt16(outBuffer,12,jobListData.uListDataNum);
            sendRet = sendN(acceptHandle, outBuffer, 14, 0);
            if (sendRet != 14) {
                fprintf(stderr, "tcpSvr: sendRet = %d != 14\n", sendRet);
                return -1;
            }
            break;

        default:
            fprintf(stderr, "tcpSvr: invalid file function type = %d\n", type);
            return -1;
    }
    return 0;
}