result Enrollment::SendData() { String data = ""; ByteBuffer* pTxBuffer = null; ByteBuffer buffer; result res = E_SUCCESS; for (int i = 0; i < 4; i++) { data.Append(__pWorkList[i]->GetText()); data.Append("\n"); } if (data.IsEmpty()) { AppLog("There is no data to send"); return E_SUCCESS; } pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(data); TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer"); AppLog("Text Length %d", pTxBuffer->GetLimit()); buffer.Construct(pTxBuffer->GetLimit()); buffer.CopyFrom(*pTxBuffer); buffer.Flip(); delete pTxBuffer; res = __pSocket->SendTo(buffer, *__pUdpEndpoint); if (res != E_SUCCESS && res != E_WOULD_BLOCK) AppLog("Error sending data"); buffer.Clear(); return res; }
void RouteRequestManager::OnTransactionReadyToRead(Osp::Net::Http::HttpSession& httpSession, Osp::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen){ AppLogDebug("http ready called"); HttpResponse* resp = httpTransaction.GetResponse(); //String status = resp->GetStatusText(); //AppLog("status: %S",status); ByteBuffer* buffer = (resp->ReadBodyN()); char data[buffer->GetLimit()+1]; buffer->SetPosition(0); buffer->GetArray((byte*)data, 0, buffer->GetLimit()); data[buffer->GetLimit()] ='\0'; String test(data); AppLogDebug("%S",test.GetPointer()); AppLogDebug("\n\n"); ArrayListT<Trip*>* trips=null; IRailAPI h; if(AppData::GetInstance()->getCurrentRequest() != null){ trips = h.createTripList(buffer); } if(trips != null){ if(!addToResults) AppData::GetInstance()->getCurrentRequest()->clearTrips(); AppData::GetInstance()->getCurrentRequest()->getTrips()->AddItems(*trips); //AppLog("parsing succesfull"); Controller::GetInstance()->switchToRoutePlannerResults(); } else{ //AppLogDebug("parsing failed"); Controller::GetInstance()->showServerErrorMessage(); } //write to file /* File f; int fileIndex = getRoutePlannerRegistryIndex(); f.Construct(L"/Home/history/RP"+ Integer::ToString(fileIndex) + ".xml",L"w+",false); f.Write(*buffer); */ }
void HttpThread::OnHttpDownloadInProgress(HttpSession & /*httpSession*/, Tizen::Net::Http::HttpTransaction & httpTransaction, int64_t currentLength, int64_t totalLength) { HttpResponse * pResponse = httpTransaction.GetResponse(); if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK || pResponse->GetHttpStatusCode() == HTTP_STATUS_PARTIAL_CONTENT) { ByteBuffer * pBuffer = 0; pBuffer = pResponse->ReadBodyN(); int const chunkSize = pBuffer->GetLimit(); m_downloadedBytes += chunkSize; m_callback.OnWrite(m_begRange + m_downloadedBytes - chunkSize, pBuffer->GetPointer(), chunkSize); delete pBuffer; } else LOG(LERROR, ("OnHttpDownloadInProgress ERROR", FromTizenString(pResponse->GetStatusText()))); }
void IRailConnection::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen) { //LEZEN werkt ! ArrayListT<Connection> connections; connections.Construct(10); HttpResponse* resp = httpTransaction.GetResponse(); ByteBuffer* buf = (resp->ReadBodyN()); xmlDocPtr doc = xmlParseMemory((char*) (buf->GetPointer()), buf->GetLimit()); if (doc != null) { xmlNodePtr connection = null; xmlNodePtr pRoot = xmlDocGetRootElement(doc); for (connection = pRoot->children; connection; connection = connection->next) { xmlNodePtr child = null; Connection con; for (child = connection->children; child; child = child->next) { if (child->type == XML_ELEMENT_NODE) { String nodeName; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) child->name, nodeName); if (nodeName.CompareTo("departure") == 0) { xmlNodePtr child1 = null; for (child1 = child->children; child1; child1 = child1->next) { if (child1->type == XML_ELEMENT_NODE) { String nodeName1; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) child1->name, nodeName1); if (nodeName1.CompareTo("time") == 0) { xmlAttrPtr isoTime = child1->properties; if (isoTime != null && isoTime->type == XML_ATTRIBUTE_NODE) { String time; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) isoTime->children->content, time); con.setFromTime(time); } } else if (nodeName1.CompareTo("station") == 0) { String station; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) child1->children->content, station); con.setFromStation(station); } } } } else if (nodeName.CompareTo("arrival") == 0) { xmlNodePtr child1 = null; for (child1 = child->children; child1; child1 = child1->next) { if (child1->type == XML_ELEMENT_NODE) { String nodeName1; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) child1->name, nodeName1); if (nodeName1.CompareTo("time") == 0) { xmlAttrPtr isoTime = child1->properties; if (isoTime != null && isoTime->type == XML_ATTRIBUTE_NODE) { String time; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) isoTime->children->content, time); con.setToTime(time); } } else if (nodeName1.CompareTo("station") == 0) { String station; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) child1->children->content, station); con.setToStation(station); } } } } else if (nodeName.CompareTo("duration") == 0) { String duration_; Osp::Base::Utility::StringUtil::Utf8ToString( (char*) child->children->content, duration_); int duration; Integer::Parse(duration_, duration); con.setDuration(duration); } } } if(con != null) { connections.Add(con); } } xmlFreeDoc(doc); this->pTrainsResultsForm->setConnections(connections); } else { AppLog("parsing internet file failed"); } }
result CategoryItemForm::ReadCustomListItems() { result r = E_SUCCESS; String dirName(L"/Home/catalog/"+dir); Directory* pDir; DirEnumerator* pDirEnum; pDir = new Directory; // allocate Directory instance // Open directory r = pDir->Construct(dirName); // Read all directory entries pDirEnum = pDir->ReadN(); String contentType; int i = 0; while(pDirEnum->MoveNext() == E_SUCCESS) { DirEntry dirEntry = pDirEnum->GetCurrentDirEntry(); if(dirEntry.IsNomalFile()) { //AppLog("%S", dirEntry.GetName().GetPointer()); if(!dirEntry.GetName().Equals("category.info", false)) { String fileName(dirName+"/"+dirEntry.GetName()); String title, desc; String iTempStr, iTempStr2; File file; result r = file.Construct(fileName, L"r"); if( IsFailed(r) ) { AppLog("File::Consturct() is failed by %s", GetErrorMessage(r)); } FileAttributes fileAttrs; file.GetAttributes(fileName, fileAttrs); long long size = fileAttrs.GetFileSize(); ByteBuffer readBuffer; readBuffer.Construct((int)size + 1); r = file.Read(readBuffer); if( IsFailed(r) ) { AppLog("File::Read() is failed by %s", GetErrorMessage(r)); } char* data = new char[readBuffer.GetLimit()+1]; readBuffer.SetPosition(0); readBuffer.GetArray((byte*)data, 0, readBuffer.GetLimit()); data[readBuffer.GetLimit()] ='\0'; //String str = String(data); String str; r = StringUtil::Utf8ToString(data, str); delete data; if(IsFailed(r)) { AppLog("File read error. File : %S", fileName.GetPointer()); continue; } file.Seek(FILESEEKPOSITION_BEGIN, 0); file.Read(title); r = TextPic::GetTranslated(title); if (IsFailed(r)) { continue; } int linecount = 0; while(file.Read(iTempStr) != E_END_OF_FILE) { linecount++; iTempStr2.Append(iTempStr); } anciilist.Add(*(new String(iTempStr2))); titlelist.Add(*(new String(title))); filelist.Add(*(new String(fileName))); ItemListForm::AddListItem(*CategoryList, title, iTempStr2, i++, linecount); file.Flush(); } } } delete pDirEnum; delete pDir; return r; }