Esempio n. 1
0
errInfo newWork(const std::wstring &name, const std::wstring &info, work **ret)
{
	dataBuf buf;
	CURL *handle = curl_easy_init();
	std::string postField = "field=work&operation=add&name=" + encode(name) + "&info=" + encode(toSingleLine(info));
	std::unique_ptr<char[]> errBuf = std::make_unique<char[]>(2048);
	CURLcode success;
	curl_easy_setopt(handle, CURLOPT_URL, scriptURL);
	curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf.get());
	curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postField.c_str());
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buf);
	success = curl_easy_perform(handle);
	if (success != CURLcode::CURLE_OK)
	{
		curl_easy_cleanup(handle);
		std::string err(errBuf.get());
		return errInfo("E:network:" + err);
	}
	curl_easy_cleanup(handle);
	
	size_t newID;
	if (str2num(buf, newID) != 0)
		return errInfo(std::string("E:Server side error:") + buf);
	*ret = new work(newID, name, info);
	workList.emplace(newID, *ret);

	return errInfo();
}
Esempio n. 2
0
errInfo work::editInfo(const std::wstring &newInfo)
{
	info = newInfo;

	dataBuf buf;
	CURL *handle = curl_easy_init();
	std::string postField = "field=work&operation=edit&id=" + std::to_string(wID) + "&item=info&value=" + encode(toSingleLine(newInfo));
	std::unique_ptr<char[]> errBuf = std::make_unique<char[]>(2048);
	CURLcode success;
	curl_easy_setopt(handle, CURLOPT_URL, scriptURL);
	curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf.get());
	curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postField.c_str());
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buf);
	success = curl_easy_perform(handle);
	if (success != CURLcode::CURLE_OK)
	{
		curl_easy_cleanup(handle);
		std::string err(errBuf.get());
		return errInfo("E:network:" + err);
	}
	curl_easy_cleanup(handle);
	
	if (!buf.empty())
		return errInfo(std::string("E:Server side error:") + buf);

	return errInfo();
}
Esempio n. 3
0
errInfo work::writeMemList()
{
	std::string newMemberStr;
	for (size_t uID : members)
	{
		newMemberStr.append(std::to_string(uID));
		newMemberStr.push_back(';');
	}

	dataBuf buf;
	CURL *handle = curl_easy_init();
	std::string postField = "field=work&operation=edit&id=" + std::to_string(wID) + "&item=member&value=" + encode(newMemberStr);
	std::unique_ptr<char[]> errBuf = std::make_unique<char[]>(2048);
	CURLcode success;
	curl_easy_setopt(handle, CURLOPT_URL, scriptURL);
	curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf.get());
	curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postField.c_str());
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buf);
	success = curl_easy_perform(handle);
	if (success != CURLcode::CURLE_OK)
	{
		curl_easy_cleanup(handle);
		std::string err(errBuf.get());
		return errInfo("E:network:" + err);
	}
	curl_easy_cleanup(handle);
	
	if (!buf.empty())
		return errInfo(std::string("E:Server side error:") + buf);

	return errInfo();
}
Esempio n. 4
0
errInfo delWork(size_t wID)
{
	workList.erase(wID);

	dataBuf buf;
	CURL *handle = curl_easy_init();
	std::string postField = "field=work&operation=del&id=" + std::to_string(wID);
	std::unique_ptr<char[]> errBuf = std::make_unique<char[]>(2048);
	CURLcode success;
	curl_easy_setopt(handle, CURLOPT_URL, scriptURL);
	curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf.get());
	curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postField.c_str());
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buf);
	success = curl_easy_perform(handle);
	if (success != CURLcode::CURLE_OK)
	{
		curl_easy_cleanup(handle);
		std::string err(errBuf.get());
		return errInfo("E:network:" + err);
	}
	curl_easy_cleanup(handle);
	
	if (!buf.empty())
		return errInfo(std::string("E:Server side error:") + buf);

	return errInfo();
}
// ----------------------------------------------------------------------------
// CBCTestSkinsContainer::Draw
// Fills the window's rectangle.
// ----------------------------------------------------------------------------
//
void CBCTestSkinsContainer::Draw( const TRect& aRect ) const
    {    
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KAknAtListGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    
	if( !iDrawFlag ) 
		{
		return;	
		}
    
    // AknsDrawUtils::Background
    TBool boolflag = ETrue;   
    _LIT( KMsg, "Great");
    TBuf<16> info( KMsg );   
    
    _LIT( KErr, "Error");
    TBuf<16> errInfo( KErr );   
    
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
    if( skin != NULL )    
	    {
		CEikonEnv::Static()->InfoMsg( KMsg );				    	
	    }
    
    boolflag = AknsDrawUtils::Background( skin, cc, gc, aRect );    
    if (boolflag) 
		{
		CEikonEnv::Static()->InfoMsg( info );			
		}
	else
		{
		CEikonEnv::Static()->InfoMsg( errInfo );			
		}
			
    // AknsDrawUtils::BackgroundBetweenRects
    TRect innerRect( 5, 5, 100, 100);    
    boolflag = AknsDrawUtils::BackgroundBetweenRects( skin, cc, gc, aRect, innerRect);
    if (boolflag) 
		{
		CEikonEnv::Static()->InfoMsg( info );			
		}
	else
		{
		CEikonEnv::Static()->InfoMsg( errInfo );			
		}    
	
	boolflag = AknsDrawUtils::DrawFramePart(skin, gc, aRect, KAknsIIDQsnFrSetOptCornerTl, 
	    EAknsFrameIndexCenter );  
    }
Esempio n. 6
0
bool CalcType::checkInputCount(int count)
{
  if(mIns.size() < count)
  {
    if(1 == count)
    {
      error(FUNC, tr("'%1': No input parameter found.").arg(mType));
    }
    else
    {
      error(FUNC, tr("'%1': Too less input parameters.").arg(mType));
      errInfo(FUNC, tr("Found: %1, Expect: %2").arg(mOuts.size()).arg(count));
    }

    return false; // Error
  }

  return true; // Ok
}
Esempio n. 7
0
bool CalcType::checkOutputCount(int count)
{
  if(mOuts.size() < count)
  {
    if(1 == count)
    {
      error(FUNC, tr("'%1': No output variable found.").arg(mType));
    }
    else
    {
      error(FUNC, tr("'%1': Too less output variables.").arg(mType));
      errInfo(FUNC, tr("Found: %1, Expect: %2").arg(mOuts.size()).arg(count));
    }

    return false; // Error
  }
  else
  {
    // Register all output variable
    for(int i = 0; i < count; ++i) mUsedVariables->insert(mOuts.at(i));
  }

  return true; // Ok
}
Esempio n. 8
0
int main(int argc, char** argv)
{
//-------------------------------Analyse params---------------------------
	int ch;

	if(argc <= 1)
	{
		retval = NO_PARAM;
		goto EXIT;
	}
	else if(argv[1][0] != '-' && isNum(argv[1]))
	{
		programNum = atoi(argv[1]);
	}
	else if(argv[1][0] != '-' && !isNum(argv[1]))
	{
		retval = NO_PARAM;
		goto EXIT;
	}

	while((ch = getopt(argc, argv, "s:a:h")) != -1)
	{
		switch(ch)
		{
			case 's':
				if(isNum(optarg))
					freq = atoi(optarg);
				else
				{
					retval = PARAM_ERR;
					goto EXIT;
				}

				break;
			case 'a':
				break;
			case 'h':
				helpInfo();
				break;
			default:
				helpInfo();
		}
	}	


//----------------------------Init memory----------------------------
    progInfoBuffer = (char *)malloc(PROG_INFO_BUFFER_SIZE);
	if(progInfoBuffer == NULL)
	{
		printf("Erro occurred! Maybe lack of memory.");
		return MALLOC_ERR;
	}

//---------------------------Get dat from profile file----------------

	int tmpDatLen = 0;

	sprintf(progInfoBuffer, "[freq] %d\n", freq);	
	tmpDatLen = strlen(progInfoBuffer);

	if(freq > 0)
	{
		if((datFp = fopen("tmp.dat", "w+")) == NULL)
		{
			retval = DAT_OPEN_ERR;
			goto EXIT;
		}

		fwrite(progInfoBuffer, tmpDatLen,1, datFp);
	}
	else
	{
		if((datFp = fopen("tmp.dat", "r")) == NULL)
		{
			retval = DAT_OPEN_ERR;
			goto EXIT;
		}

		char* freqFromFile;
		int tmpFreq = 0;
		freqFromFile = (char*)malloc(tmpDatLen + 1);
		fread(freqFromFile, tmpDatLen, 1, datFp);

		if(sscanf(freqFromFile, "[freq] %d\n", &tmpFreq) > 0)
			freq = tmpFreq;

		free(freqFromFile);
	}

	if(datFp != NULL)
		fclose(datFp);

	if(freq == -1)
	{
		retval = FREQ_ERR;
		goto EXIT;
	}

	if(programNum != -1)
	{
		programWantToPlay = programNum;
		printf("Program Num: %d\n", programWantToPlay);
	}

	printf("Freq is %d\n", freq);

//---------------------Start to parse ts---------------------
	if(!parseTS(freq))
	{
		retval = FREQ_ERR;
		goto EXIT;
	}

EXIT:

	if(progInfoBuffer != NULL)
		free(progInfoBuffer);

	if(retval != 0)
		errInfo(retval);

	return retval;	
}
Esempio n. 9
0
errInfo readWorkList()
{
	dataBuf buf;
	CURL *handle = curl_easy_init();
	std::unique_ptr<char[]> errBuf = std::make_unique<char[]>(2048);
	CURLcode success;
	curl_easy_setopt(handle, CURLOPT_URL, scriptURL);
	curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf.get());
	curl_easy_setopt(handle, CURLOPT_POSTFIELDS, "field=work&operation=list");
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buf);
	success = curl_easy_perform(handle);
	if (success != CURLcode::CURLE_OK)
	{
		curl_easy_cleanup(handle);
		std::string err(errBuf.get());
		return errInfo("E:network:" + err);
	}
	curl_easy_cleanup(handle);

	for (std::pair<size_t, work*> wPtr : workList)
		delete wPtr.second;
	workList.clear();

	dataBuf::const_iterator p, pEnd = buf.cend();
	std::string::const_iterator p2, pEnd2;
	std::string data[LINE_END];
	int state = 0;
	for (p = buf.cbegin(); p != pEnd;)
	{
		switch (*p)
		{
			case '\r':
				p++;
			case '\n':
			{
				p++;

				state++;
				if (state == LINE_END)
				{
					size_t wID, uID;
					if (str2num(data[LINE_WID], wID) != 0)
						return errInfo("WID:Not a num");
					processEscChar(data[LINE_INFO]);
					work *newWork = new work(wID, decode(data[LINE_NAME]), decode(data[LINE_INFO]));

					std::string name = std::move(data[LINE_MEMBERS]);
					if (!name.empty())
					{
						if (name.back() != ';')
							name.push_back(';');
						size_t pos1 = 0, pos2 = name.find(';');
						while (pos2 != std::string::npos)
						{
							if (str2num(name.substr(pos1, pos2 - pos1), uID) != 0)
								return errInfo("UID:Not a num");
							newWork->members.insert(uID);
							pos1 = pos2 + 1;
							pos2 = name.find(';', pos1);
						}
					}

					workList.emplace(wID, newWork);

					for (int i = 0; i < LINE_END; i++)
						data[i].clear();
					state = 0;
				}
				break;
			}
			default:
				data[state].push_back(*p);
				p++;
		}
	}

	if (state != 0)
		return errInfo("Invalid work info from server");

	return errInfo();
}