Exemple #1
0
////////////////////////////////////////////////////////////////////////////////
// Saves the file strFilePath after getting it from the ars server
CFieldValuePair::DumpAttachment(CARSConnection &arsConnect, CString Form, 
								CEntryId EntryId, ARInternalId arsFieldId,
								CString strFilePath)
{
	ARNameType arsFormName; // working variable
	AREntryIdList arsEntryId; // working variable
	ARLocStruct arsLocStruct; // working variable
	ARStatusList arsStatusList; // working variable

	// Build ARNameType formName
	strcpy( (char*)arsFormName, LPCSTR(Form.Left(sizeof(ARNameType))) ); // copy form name, truncating if necessary
	if(Form.GetLength() > sizeof(ARNameType))
	{
		// Output truncation to log file
		CString strLog("CFieldValuePair::DumpAttachment()");
		strLog += "\tForm name truncated due because size exceeded limits.  Original name: ";
		strLog += Form;
		strLog += INDENT;
		strLog += "Truncated name: ";
		strLog += (char*)arsFormName;
//		Log(strLog);
	}
	// Build AREntryIdList entryId. Will be entry id to get blob for
	if(!FillEntryId(EntryId, &arsEntryId))
	{
		// output to error log here
		CString strLog;
		strLog = "\tAttachment \"";
		strLog += strFilePath;
		strLog += "\" not saved because FillEntryId() failed.\t";
		strLog += "CFieldValuePair::DumpAttachment()";
		Log(strLog);
		ThrowARSException(LPCSTR(strLog), "CFieldValuePair::DumpAttachment()");
	}

	// Build ARLocStruct. Will hold the filename to save the attachment to.
	if(!FillARLocStruct(strFilePath, arsLocStruct))
	{
		// output to error log here
		CString strLog;
		strLog = "\tAttachment \"";
		strLog += strFilePath;
		strLog += "\" not saved because FillARLocStruct() failed.\t";
		strLog += "CFieldValuePair::DumpAttachment()";
		Log(strLog);
		ThrowARSException(LPCSTR(strLog), "CFieldValuePair::DumpAttachment()");
	}

	// Call ARGetEntryBLOB to dump the attachment
	if(ARGetEntryBLOB(&arsConnect.LoginInfo, arsFormName, &arsEntryId,
					  arsFieldId, &arsLocStruct, &arsStatusList) > AR_RETURN_OK)
	{
		ThrowARSException(arsStatusList, "CFieldValuePair::DumpAttachment");
	}

	// Free up heap memory
	FreeAREntryIdList(&arsEntryId, FALSE);
	FreeARLocStruct(&arsLocStruct, FALSE);
}
Exemple #2
0
FunctionPrint::FunctionPrint(const std::string& functionName)
    : m_functionName(functionName)
{
    std::string strLog("{");
    strLog.append(m_functionName);
    strLog.append("} --- ENTRY");
    Log_Run_Debug(PRODUCT_NAME,strLog.c_str());
}
void CDataFeedingEditCtrl::TraceDisconnection() {
    CTime currentTime = CTime::GetCurrentTime();
    CString cstrCurrentTime = currentTime.Format(_T("%Y-%m-%d  %H:%M:%S"));
    tstring strCurrentTime(cstrCurrentTime);
    tstring strLog(_T("Server was disconnected. Readvise Data Feeding"));
    tstring strTrace = strCurrentTime + _T(" : ") + strLog + _T("\r\n");

    int length;
    length = this->GetWindowTextLength();
    this->SetSel(length, length);
    this->ReplaceSel(strTrace.c_str());
}
Exemple #4
0
FunctionPrint::~FunctionPrint()
{
    try
    {
        std::string strLog("{");
        strLog.append(m_functionName);
        strLog.append("} --- LEAVE");
        Log_Run_Debug(PRODUCT_NAME,strLog.c_str());
    }
    catch (...)
    {

    }
}
 Action::result JSONParseLog::takeData(const char* const startBuf, const char* const endBuf, uint64_t totalDataSize) {
     
     std::copy(startBuf, endBuf, std::back_inserter(buffer_));
     std::string strLog(startBuf, endBuf);
     log(strLog);
     picojson::value v;
     std::string     err;
     picojson::parse(v, buffer_.data(), buffer_.data()+buffer_.size(), &err);
     
     if ( !err.empty() ) {
         //Log error
         
     } else if ( !v.is<picojson::object>() ) {
         //Log error
     } else {
         std::string indent("");
         JSONParseAndFill(v.get<picojson::object>(), indent);
     }
     return Action::ALL_DATA_RCVD;
  }
Exemple #6
0
cl_int cl_runner::execute(const char *filename)
{
    if (filename == NULL || m_clContext == NULL)
        return -1;

    if (!m_bInitCL)
        init_cl();

    // Error code
    cl_int err_num = CL_SUCCESS;

    char *source_content = NULL;
    size_t src_length = 0;
    bool source_need_free = false;

#if 1
    std::ifstream ifs;
    source_need_free = true;
    err_num = clLoadProgramSource(filename, (const char **)&source_content, (size_t *)&src_length);
    if (err_num != CL_SUCCESS || src_length == 0 || source_content == NULL) {
        DOL_TRACE1("cl_runner: Error load program source. ErrCode = %d \n", err_num);
        return err_num;
    }
#else
    std::ifstream ifs(filename, std::ios_base::binary);
    if (!ifs.good()) {
        DOL_TRACE("cl_runner: Error load program source, open source file failed.\n");
        return -1;
    }

    // get file length
    ifs.seekg(0, std::ios_base::end);
    size_t length = ifs.tellg();
    ifs.seekg(0, std::ios_base::beg);

    // read program source
    std::vector<char> data(length + 1);
    ifs.read(&data[0], length);
    data[length] = 0;

    // create and build program
    source_content = &data[0];
    src_length = length;
#endif

    // Create the program
    err_num = CL_SUCCESS;
    m_clProgram = clCreateProgramWithSource(m_clContext, 1, (const char **)&source_content, &src_length, &err_num);  // 加载文件内容
    if (source_need_free) {
        if (source_content != NULL) {
            free(source_content);
            source_content = NULL;
        }
    }
    ifs.close();
    DOL_ASSERT(err_num == CL_SUCCESS);
    if (err_num != CL_SUCCESS || m_clProgram == NULL) {
        DOL_TRACE1("cl_runner: Error create program with source. ErrCode = %d \n", err_num);
        return err_num;
    }

    // Build the program
    err_num = clBuildProgram(m_clProgram, 1, &m_clDeviceId, NULL, NULL, NULL);   // 编译cl程序
    DOL_ASSERT(err_num == CL_SUCCESS);
    if (err_num != CL_SUCCESS) {
        DOL_TRACE1("cl_runner: Error build program. ErrCode = %d \n", err_num);
        return err_num;
    }

    // Show the log
    char *build_log;
    size_t log_size;

    // First call to know the proper size
    err_num = clGetProgramBuildInfo(m_clProgram, m_clDeviceId, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
    if (err_num != CL_SUCCESS) {
        DOL_TRACE1("cl_runner: Error get program build info step 1. ErrCode = %d \n", err_num);
        return err_num;
    }

    build_log = new char[log_size + 1]; // 编译CL的出错记录
    if (build_log == NULL)
        return (cl_int)-1;

    // Second call to get the log
    err_num = clGetProgramBuildInfo(m_clProgram, m_clDeviceId, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
    if (err_num != CL_SUCCESS) {
        if (build_log) {
            delete build_log;
            build_log = NULL;
        }
        DOL_TRACE1("cl_runner: Error get program build info step 2. ErrCode = %d \n", err_num);
        return err_num;
    }

    build_log[log_size] = '\0';
    std::string strLog(build_log);
    strLog += "\n";
    DOL_TRACE(strLog.c_str());      // 因为cl程序是在运行时编译的,在运行过程中如果出错,显示编译CL文件的错误,以便查找问题
    if (build_log) {
        delete build_log;
        build_log = NULL;
    }

    // set seed for rand()
    ::srand(FIXED_SRAND_SEED);

    const unsigned int DATA_SIZE = 1048576;
    std::vector<CL_FLOAT_T> a(DATA_SIZE), b(DATA_SIZE), ret(DATA_SIZE);
    for (unsigned int i = 0; i < DATA_SIZE; ++i) {
        a[i]    = std::rand() / (CL_FLOAT_T)RAND_MAX;
        b[i]    = std::rand() / (CL_FLOAT_T)RAND_MAX;
        ret[i]  = 0.0;
    }

    // Allocate the buffer memory objects
    cl_mem cl_a   = clCreateBuffer(m_clContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(CL_FLOAT_T) * DATA_SIZE, (void *)&a[0], NULL);
    cl_mem cl_b   = clCreateBuffer(m_clContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(CL_FLOAT_T) * DATA_SIZE, (void *)&b[0], NULL);
    cl_mem cl_ret = clCreateBuffer(m_clContext, CL_MEM_READ_WRITE,                       sizeof(CL_FLOAT_T) * DATA_SIZE, (void *)NULL, NULL);
    cl_mem cl_num = clCreateBuffer(m_clContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_uint),                (void *)&DATA_SIZE, NULL);

    // 创建Kernel对应的函数

    // Extracting the kernel
#if defined(USE_CL_DOUBLE) && (USE_CL_DOUBLE != 0)
    m_clKernel = clCreateKernel(m_clProgram, "vector_add_double", &err_num);    // 这个引号中的字符串要对应cl文件中的kernel函数
#else
    m_clKernel = clCreateKernel(m_clProgram, "vector_add_float", &err_num);     // 这个引号中的字符串要对应cl文件中的kernel函数
#endif
    DOL_ASSERT(err_num == CL_SUCCESS);
    if (err_num != CL_SUCCESS) {
        DOL_TRACE1("cl_runner: Error create kernel. ErrCode = %d \n", err_num);
        return err_num;
    }

    if (m_clKernel != NULL) {
        // Set the args values
        err_num  = clSetKernelArg(m_clKernel, 0, sizeof(cl_mem), &cl_a);
        err_num |= clSetKernelArg(m_clKernel, 1, sizeof(cl_mem), &cl_b);
        err_num |= clSetKernelArg(m_clKernel, 2, sizeof(cl_mem), &cl_ret);
        //err_num |= clSetKernelArg(m_clKernel, 3, sizeof(cl_mem), &cl_num);
        err_num |= clSetKernelArg(m_clKernel, 3, sizeof(cl_uint), &DATA_SIZE);
        if (err_num != CL_SUCCESS)
            return err_num;

        // Set work-item dimensions
        size_t globalWorkSize[2];
        size_t localWorkSize[2] = { 0 };
        globalWorkSize[0] = DATA_SIZE;
        globalWorkSize[1] = DATA_SIZE;

        sw_kernel.start();

        // Execute kernel
        err_num = clEnqueueNDRangeKernel(m_clCmdQueue, m_clKernel, 1, NULL, globalWorkSize, NULL, 0, NULL, NULL);

        sw_kernel.stop();
        if (err_num != CL_SUCCESS) {
            if (err_num == CL_INVALID_KERNEL_ARGS)
                DOL_TRACE("Invalid kernel args \n");
            else
                DOL_TRACE1("cl_runner: Error enqueue NDRange kernel. ErrCode = %d \n", err_num);
            //return err_num;
        }

        // Read output array
        if (err_num == CL_SUCCESS) {
            sw_kernel_readBuffer.start();
            err_num = clEnqueueReadBuffer(m_clCmdQueue, cl_ret, CL_TRUE, 0, sizeof(CL_FLOAT_T) * DATA_SIZE, &ret[0], 0, NULL, NULL);
            sw_kernel_readBuffer.stop();
            if (err_num != CL_SUCCESS) {
                DOL_TRACE1("cl_runner: Error enqueue read buffer. ErrCode = %d \n", err_num);
                //return err_num;
            }

            if (err_num == CL_SUCCESS) {
                bool correct = true;
                CL_FLOAT_T diff;
                for (unsigned int i = 0; i < DATA_SIZE; ++i) {
                    diff = a[i] + b[i] - ret[i];
                    if (fabs(diff) > 0.0001) {
                        correct = false;
                        break;
                    }
                }

                if (correct)
                    std::cout << "cl_runner: Data is correct" << endl;
                else
                    std::cout << "cl_runner: Data is incorrect" << endl;
            }
            else {
                std::cerr << "cl_runner: Can't run kernel or read back data" << endl;
            }
        }
    }

    if (cl_a)
        clReleaseMemObject(cl_a);
    if (cl_b)
        clReleaseMemObject(cl_b);
    if (cl_ret)
        clReleaseMemObject(cl_ret);
    if (cl_num)
        clReleaseMemObject(cl_num);

    if (m_clKernel) {
        clReleaseKernel(m_clKernel);
        m_clKernel = NULL;
    }

    if (m_clProgram) {
        clReleaseProgram(m_clProgram);
        m_clProgram = NULL;
    }

    return err_num;
}
Exemple #7
0
// Time 字符串中不能有空格
HRESULT KppUserLog::WriteSingleLog(
	/* [in] */const std::wstring& wstLogString
	)
{
	std::wstring strLog(L"");
	HRESULT	hrRet = E_FAIL;
	SYSTEMTIME	sysTime = {0};
    std::wstring strTmep(L"\n");

	if(!m_bWrite)
	{
		return E_FAIL;
	}

	if (!m_bInitFlag)
	{
		return E_FAIL;
	}

	_LockWork();

	FILE* pfile = NULL;

	if (::PathFileExists(m_strPathName.c_str()))
	{
		pfile = ::_wfopen(m_strPathName.c_str(), L"at,ccs=UTF-8");
	}
	else
	{
		pfile = ::_wfopen(m_strPathName.c_str(), L"wt,ccs=UTF-8");
	}
	
	if (!pfile)
	{
		hrRet = E_FAIL;
		goto _Exit;
	}

	GetLocalTime( &sysTime );

    ParseTime(strLog, &sysTime);

	strLog += wstLogString;
	strLog += strTmep;

	size_t fwsize = ::fwrite((BYTE *)strLog.c_str(), sizeof(BYTE), ::wcslen(strLog.c_str())*2, pfile);

	hrRet = S_OK;

_Exit:

	if (pfile)
	{
		::fclose(pfile);
		pfile = NULL;
	}

	_UnlockWork();

	return hrRet;
}