size_t CDBL_ComputeResult::ReadItem(void* buffer, size_t buffer_size, bool* is_null) { if ((unsigned int) m_CurrItem >= GetDefineParams().GetNum()) { if (is_null) *is_null = true; return 0; } const BYTE* d_ptr = Check(dbadata(GetCmd(), m_ComputeId, m_CurrItem + 1)); DBINT d_len = Check(dbadlen(GetCmd(), m_ComputeId, m_CurrItem + 1)); if (d_ptr == 0 || d_len < 1) { // NULL value ++m_CurrItem; m_Offset = 0; if (is_null) *is_null = true; return 0; } if (is_null) *is_null = false; if ((size_t) d_len - m_Offset < buffer_size) buffer_size = (size_t) d_len - m_Offset; memcpy(buffer, d_ptr + m_Offset, buffer_size); m_Offset += buffer_size; if (m_Offset >= (size_t) d_len) { m_Offset = 0; ++m_CurrItem; } return buffer_size; }
size_t CDBL_SendDataCmd::SendChunk(const void* pChunk, size_t nof_bytes) { CHECK_DRIVER_ERROR( !pChunk || !nof_bytes, "Wrong (zero) arguments." + GetDbgInfo(), 290000 ); if (!GetBytes2Go()) return 0; if (nof_bytes > GetBytes2Go()) nof_bytes = GetBytes2Go(); if (Check(dbmoretext(GetCmd(), (DBINT) nof_bytes, (BYTE*) pChunk)) != SUCCEED) { Check(dbcancel(GetCmd())); DATABASE_DRIVER_ERROR( "dbmoretext failed." + GetDbgInfo(), 290001 ); } SetBytes2Go(GetBytes2Go() - nof_bytes); if (GetBytes2Go() <= 0) { // if (dbsqlok(m_Cmd) != SUCCEED || dbresults(m_Cmd) == FAIL) { if (Check(dbsqlok(GetCmd())) != SUCCEED || GetConnection().x_Results(GetCmd()) == FAIL) { DATABASE_DRIVER_ERROR( "dbsqlok/results failed." + GetDbgInfo(), 290002 ); } } return nof_bytes; }
CDBL_RowResult::CDBL_RowResult(CDBL_Connection& conn, DBPROCESS* cmd, unsigned int* res_status, bool need_init) : CDBL_ResultBase(conn, cmd, res_status) { if (!need_init) return; unsigned int col_num = Check(dbnumcols(cmd)); m_CmdNum = DBCURCMD(cmd); m_ColFmt = new SDBL_ColDescr[col_num]; for (unsigned int n = 0; n < col_num; n++) { m_ColFmt[n].max_length = Check(dbcollen(GetCmd(), n + 1)); m_ColFmt[n].data_type = GetDataType(n + 1); const char* s = Check(dbcolname(GetCmd(), n + 1)); m_ColFmt[n].col_name = s ? s : ""; m_CachedRowInfo.Add( s ? s : "", Check(dbcollen(GetCmd(), n + 1)), GetDataType(n + 1) ); } }
bool CDBL_BlobResult::Fetch() { if (m_EOR) return false; STATUS s; if (m_CurrItem == 0) { while ((s = Check(dbreadtext(GetCmd(), m_Buff, (DBINT) sizeof(m_Buff)))) > 0) { ; } switch (s) { case 0: break; case NO_MORE_ROWS: m_EOR = true; return false; default: DATABASE_DRIVER_ERROR( "Error in fetching row." + GetDbgInfo(), 280003 ); } } else { m_CurrItem = 0; } s = Check(dbreadtext(GetCmd(), m_Buff, (DBINT) sizeof(m_Buff))); if (s == NO_MORE_ROWS) return false; if (s < 0) { DATABASE_DRIVER_ERROR( "Error in fetching row." + GetDbgInfo(), 280003 ); } m_BytesInBuffer= s; m_ReadedBytes= 0; return true; }
CDBL_ITDescriptor::CDBL_ITDescriptor(CDBL_Connection& conn, DBPROCESS* dblink, int col_num) : CDBL_Result(conn, dblink) { // !!! This is a hack !!! // dbcolname returns char* DBCOLINFO* col_info = (DBCOLINFO*) Check(dbcolname(GetCmd(), col_num)); CHECK_DRIVER_ERROR( col_info == 0, "Cannot get the DBCOLINFO*." + GetDbgInfo(), 280000 ); if (!x_MakeObjName(col_info)) { m_ObjName.erase(); } DBBINARY* p = Check(dbtxptr(GetCmd(), col_num)); if (p) { memcpy(m_TxtPtr, p, DBTXPLEN); m_TxtPtr_is_NULL = false; } else m_TxtPtr_is_NULL = true; p = Check(dbtxtimestamp(GetCmd(), col_num)); if (p) { memcpy(m_TimeStamp, p, DBTXTSLEN); m_TimeStamp_is_NULL = false; } else m_TimeStamp_is_NULL = true; }
EDB_Type CDBL_Result::GetDataType(int n) { switch (Check(dbcoltype(GetCmd(), n))) { case SYBBINARY: return (Check(dbcollen(GetCmd(), n)) > 255) ? eDB_LongBinary : eDB_VarBinary; #if 0 case SYBBITN: #endif case SYBBIT: return eDB_Bit; case SYBCHAR: return (Check(dbcollen(GetCmd(), n)) > 255) ? eDB_LongChar : eDB_VarChar; case SYBDATETIME: return eDB_DateTime; case SYBDATETIME4: return eDB_SmallDateTime; case SYBINT1: return eDB_TinyInt; case SYBINT2: return eDB_SmallInt; case SYBINT4: return eDB_Int; case SYBDECIMAL: case SYBNUMERIC: break; case SYBFLT8: return eDB_Double; case SYBREAL: return eDB_Float; case SYBTEXT: return eDB_Text; case SYBIMAGE: return eDB_Image; default: return eDB_UnsupportedType; } DBTYPEINFO* t = Check(dbcoltypeinfo(GetCmd(), n)); return t->scale == 0 && t->precision < 20 ? eDB_BigInt : eDB_Numeric; }
CDBL_ComputeResult::CDBL_ComputeResult(CDBL_Connection& conn, DBPROCESS* cmd, unsigned int* res_stat) : CDBL_ResultBase(conn, cmd, res_stat) { m_ComputeId = DBROWTYPE(cmd); if (m_ComputeId == REG_ROW || m_ComputeId == NO_MORE_ROWS) { DATABASE_DRIVER_ERROR( "No compute row found." + GetDbgInfo(), 270000 ); } unsigned int col_num = Check(dbnumalts(cmd, m_ComputeId)); if (col_num < 1) { DATABASE_DRIVER_ERROR( "Compute id is invalid." + GetDbgInfo(), 270001 ); } m_CmdNum = DBCURCMD(cmd); m_ColFmt = new SDBL_ColDescr[col_num]; for (unsigned int n = 0; n < col_num; n++) { m_ColFmt[n].max_length = Check(dbaltlen(GetCmd(), m_ComputeId, n+1)); m_ColFmt[n].data_type = AltGetDataType(m_ComputeId, n + 1); int op = Check(dbaltop(GetCmd(), m_ComputeId, n + 1)); const char* s = op != -1 ? Check(dbprtype(op)) : "Unknown"; m_ColFmt[n].col_name = s ? s : ""; m_CachedRowInfo.Add( s ? s : "", Check(dbaltlen(GetCmd(), m_ComputeId, n+1)), AltGetDataType(m_ComputeId, n + 1) ); } m_1stFetch = true; }
bool CDBL_BCPInCmd::Send(void) { char param_buff[2048]; // maximal row size, assured of buffer overruns if (!x_AssignParams(param_buff)) { SetHasFailed(); DATABASE_DRIVER_ERROR( "Cannot assign params." + GetDbgInfo(), 223004 ); } SetWasSent(); if (Check(bcp_sendrow(GetCmd())) != SUCCEED) { SetHasFailed(); DATABASE_DRIVER_ERROR( "bcp_sendrow failed." + GetDbgInfo(), 223005 ); } if (m_HasTextImage) { // send text/image data char buff[1800]; // text/image page size for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); i++) { if (GetBindParamsImpl().GetParamStatus(i) == 0) continue; CDB_Object& param = *GetBindParamsImpl().GetParam(i); if (param.GetType() != eDB_Text && param.GetType() != eDB_Image) continue; CDB_Stream& val = dynamic_cast<CDB_Stream&> (param); size_t s = val.Size(); do { size_t l = val.Read(buff, sizeof(buff)); if (l > s) l = s; if (Check(bcp_moretext(GetCmd(), (DBINT) l, (BYTE*) buff)) != SUCCEED) { SetHasFailed(); string error; if (param.GetType() == eDB_Text) { error = "bcp_moretext for text failed."; } else { error = "bcp_moretext for image failed."; } DATABASE_DRIVER_ERROR( error + GetDbgInfo(), 223006 ); } if (!l) break; s -= l; } while (s); } } ++m_RowCount; return true; }
CDBL_BlobResult::CDBL_BlobResult(CDBL_Connection& conn, DBPROCESS* cmd) : CDBL_Result(conn, cmd), m_CurrItem(-1), m_EOR(false) { m_CmdNum = DBCURCMD(cmd); const char* s = Check(dbcolname(GetCmd(), 1)); m_CachedRowInfo.Add( s ? s : "", Check(dbcollen(GetCmd(), 1)), GetDataType(1) ); }
// Aux. for CDBL_ParamResult::GetItem() // CDB_Image and CDB_Text are not handled by this function ... CDB_Object* CDBL_Result::RetGetItem(int item_no, SDBL_ColDescr* fmt, CDB_Object* item_buff) { EDB_Type b_type = item_buff ? item_buff->GetType() : eDB_UnsupportedType; const BYTE* d_ptr = Check(dbretdata(GetCmd(), item_no)); DBINT d_len = Check(dbretlen (GetCmd(), item_no)); CDB_Object* val = s_GenericGetItem(fmt->data_type, item_buff, b_type, d_ptr, d_len); if (!val) { DATABASE_DRIVER_ERROR( "Unexpected result type." + GetDbgInfo(), 230004 ); } return val; }
//***************************************************************************** // //! GetMsg - Gets the Message from User //! //! \param uiDataLength - DataLength Used //! \param pucMsgBuff - Message Buffer into which Message will be populated //! //! \return Pointer to Input Data //! //***************************************************************************** unsigned char* GetMsg( char *pucMsgBuff,unsigned int *uiDataLength) { int iMod=0; unsigned int uiMsgLen,iSize; unsigned char *uiData; UART_PRINT("\n\r Enter the Message \n\r"); uiMsgLen=GetCmd(pucMsgBuff, BUFFER_LEN); // // For ECB and CBC, data should be blocks of 16 bytes. // iSize=uiMsgLen; // if (ui32DesMode != DES_CFG_MODE_CFB) { iMod=uiMsgLen%8; if(iMod!=0) { iSize=((uiMsgLen/8)+1)*8; } } // // Allocate Memory Buffer // *uiDataLength=iSize; uiData=(unsigned char *)malloc(*uiDataLength); memset(uiData,0,*uiDataLength); memcpy(uiData,pucMsgBuff,(uiMsgLen)); return uiData; }
//**************************************************************************** // //! Get Ssid name form the user over UART //! //! \param pcSsidName is a pointer to the array which will contain the ssid name //! //! This function //! 1. gets the ssid name string over uart //! //! \return iRetVal is the length of the ssid(user input). // //**************************************************************************** static int GetSsidName(char *pcSsidName, unsigned int uiMaxLen) { char ucRecvdAPDetails = 0; int iRetVal = 0; char acCmdStore[128]; do { ucRecvdAPDetails = 0; // // Get the AP name to connect over the UART // iRetVal = GetCmd(acCmdStore, sizeof(acCmdStore)); if(iRetVal > 0) { // // Parse the AP name // strncpy(pcSsidName, acCmdStore, iRetVal); if(pcSsidName != NULL) { ucRecvdAPDetails = 1; } } }while(ucRecvdAPDetails == 0); pcSsidName[iRetVal] = '\0'; return(iRetVal); }
TZipIn::TZipIn(const TStr& FNm) : TSBase(), TSIn(), ZipStdoutRd(NULL), ZipStdoutWr(NULL), SNm(FNm.CStr()), FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) { EAssertR(! FNm.Empty(), "Empty file-name."); EAssertR(TFile::Exists(FNm), TStr::Fmt("File %s does not exist", FNm.CStr()).CStr()); FLen = 0; // non-zip files not supported, need uncompressed file length information // TODO: find the correct set of supported extensions //if (FNm.GetFExt() != ".zip" && FNm.GetFExt() != ".gz") { // printf("*** Error: file %s, compression format %s not supported\n", FNm.CStr(), FNm.GetFExt().CStr()); // EFailR(TStr::Fmt("File %s: compression format %s not supported", FNm.CStr(), FNm.GetFExt().CStr()).CStr()); //} FLen = TZipIn::GetFLen(FNm); // return for malformed files if (FLen == 0) { return; } // empty file #ifdef GLib_WIN // create pipes SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; // Create a pipe for the child process's STDOUT. const int PipeBufferSz = 32*1024; EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed"); // Ensure the read handle to the pipe for STDOUT is not inherited. SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0); #else // no implementation needed #endif CreateZipProcess(GetCmd(FNm), FNm); Bf = new char[MxBfL]; BfC = BfL=-1; FillBf(); }
//***************************************************************************** // //! ReadFromUser - Populate the parameters from User //! //! \param uiConfig - Configuration Value //! \param uiDataLength- Datalength //! \param puiResult - CRC Result //! //! \return pointer to Input Data //! //***************************************************************************** unsigned int* ReadFromUser(unsigned int *uiConfig,unsigned int *uiDataLength, unsigned int *puiResult) { char ucCmdBuffer[INPUT_MESSAGE_SIZE],*pucMsgBuff; unsigned int *uiData; pucMsgBuff=( char*)&puiPlainMsg[0]; // // Get the Command // UsageDisplay(); UART_PRINT("cmd# "); GetCmd(ucCmdBuffer,INPUT_MESSAGE_SIZE); if(CRCParser(ucCmdBuffer,uiConfig)) { uiData=GetMsg(pucMsgBuff,uiDataLength,uiConfig); memset(puiResult,0,sizeof(unsigned int)); } else { return NULL; } return uiData; }
static void DriveTask(void *pvParameters) { portTickType xLastWakeTime; (void)pvParameters; xLastWakeTime = xTaskGetTickCount(); for(;;) { while (GetCmd()==ERR_OK) { /* returns ERR_RXEMPTY if queue is empty */ /* process incoming commands */ } TACHO_CalcSpeed(); if (DRV_Status.mode==DRV_MODE_SPEED) { PID_Speed(TACHO_GetSpeed(TRUE), DRV_Status.speed.left, TRUE); PID_Speed(TACHO_GetSpeed(FALSE), DRV_Status.speed.right, FALSE); } else if (DRV_Status.mode==DRV_MODE_STOP) { PID_Speed(TACHO_GetSpeed(TRUE), 0, TRUE); PID_Speed(TACHO_GetSpeed(FALSE), 0, FALSE); } else if (DRV_Status.mode==DRV_MODE_POS) { PID_Pos(Q4CLeft_GetPos(), DRV_Status.pos.left, TRUE); PID_Pos(Q4CRight_GetPos(), DRV_Status.pos.right, FALSE); } else if (DRV_Status.mode==DRV_MODE_NONE) { /* do nothing */ } FRTOS1_vTaskDelayUntil(&xLastWakeTime, 5/portTICK_RATE_MS); } /* for */ }
bool CDBL_ComputeResult::Fetch() { if (m_1stFetch) { // we didn't get the items yet; m_1stFetch = false; m_CurrItem= 0; return true; } STATUS s = Check(dbnextrow(GetCmd())); switch (s) { case REG_ROW: case NO_MORE_ROWS: *m_ResStatus ^= 0x10; break; case FAIL: DATABASE_DRIVER_ERROR( "Error in fetching row." + GetDbgInfo(), 270003 ); case BUF_FULL: DATABASE_DRIVER_ERROR( "Buffer is full." + GetDbgInfo(), 270006 ); default: break; } m_EOR = true; m_CurrItem= -1; return false; }
void Command(std::string _Cmd) { Cmd = _Cmd; std::vector<std::string> Args = _ParseArgs(); GetCmd(Args.at(0), Args); }
CDBL_BlobResult::~CDBL_BlobResult() { try { if (!m_EOR) Check(dbcanquery(GetCmd())); } NCBI_CATCH_ALL_X( 2, NCBI_CURRENT_FUNCTION ) }
CDB_Object* CDBL_BlobResult::GetItem(CDB_Object* item_buff, I_Result::EGetItem policy) { if (m_CurrItem) return 0; EDB_Type b_type = item_buff ? item_buff->GetType() : eDB_UnsupportedType; if (item_buff && b_type != eDB_Text && b_type != eDB_Image) { DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 230020 ); } CDB_Stream* val = NULL; if (item_buff) { val = static_cast<CDB_Stream*>(item_buff); if (policy == I_Result::eAssignLOB) { // Explicitly truncate previous value ... val->Truncate(); } } else if (m_ColFmt.data_type == eDB_Text) { val = new CDB_Text; } else { val = new CDB_Image; } _ASSERT(val); // check if we do have something in buffer if(m_ReadedBytes < m_BytesInBuffer) { val->Append(m_Buff + m_ReadedBytes, m_BytesInBuffer - m_ReadedBytes); m_ReadedBytes= m_BytesInBuffer; } if(m_BytesInBuffer == 0) { return item_buff; } STATUS s; while ((s = Check(dbreadtext(GetCmd(), m_Buff, (DBINT) sizeof(m_Buff)))) > 0) { val->Append(m_Buff, (size_t(s) < sizeof(m_Buff))? size_t(s) : sizeof(m_Buff)); } switch (s) { case NO_MORE_ROWS: m_EOR = true; case 0: m_CurrItem = 1; break; default: DATABASE_DRIVER_ERROR( "dbreadtext failed." + GetDbgInfo(), 280003 ); } return item_buff; }
EDB_Type CDBL_Result::AltGetDataType(int id, int n) { switch (Check(dbalttype(GetCmd(), id, n))) { case SYBBINARY: return (Check(dbaltlen(GetCmd(), id, n)) > 255)? eDB_LongBinary : eDB_VarBinary; case SYBBIT: return eDB_Bit; case SYBCHAR: return (Check(dbaltlen(GetCmd(), id, n)) > 255)? eDB_LongChar : eDB_VarChar; case SYBDATETIME: return eDB_DateTime; case SYBDATETIME4: return eDB_SmallDateTime; case SYBINT1: return eDB_TinyInt; case SYBINT2: return eDB_SmallInt; case SYBINT4: return eDB_Int; case SYBFLT8: return eDB_Double; case SYBREAL: return eDB_Float; default: return eDB_UnsupportedType; } }
bool CDBL_SendDataCmd::Cancel(void) { if (GetBytes2Go() > 0) { Check(dbcancel(GetCmd())); SetBytes2Go(0); return true; } return false; }
bool CDBL_BCPInCmd::Cancel() { if (WasSent()) { DBINT outrow = Check(bcp_done(GetCmd())); SetWasSent(false); return outrow == 0; } return true; }
int MkView::SetCmd() { if (objc < 4) return GetCmd(); int index = asIndex(view, objv[2], false); if (_error) return _error; return SetValues(view[index], objc - 3, objv + 3, view); }
void shell_handler() { printf(" ---- Shell le coquillage de l'espace V0.1 \n"); while(1){ Prompt(); GetCmd(); if (!ExecCmd()) printf("Commande inconnu, tapez ''help'' pour voir la liste des commandes valides. \n"); } }
HRESULT Dot11ConfigGetCmd( OUT PCMD_INFO Cmd, int argc, char **argv) { Cmd->IoCtrlCode = 0; Cmd->Parameter = 0; return GetCmd(Cmd, argc, argv); }
CTpnsMsgBase* CTpnsMsgManager::GetMsg(uint8_t *buf, size_t len) { if(HEADER_LEN > len) { return NULL; } uint8_t cmd; int ret = GetCmd(buf, len, cmd); CTpnsMsgBase* pMsg = BuildMsg(cmd, buf + HEADER_LEN, len - HEADER_LEN); return pMsg; }
int main(int argc, char **argv) { /*start cmdline here*/ while(1) { printf("%s::%s>>",prompt,dbname); GetCmd(cmdbuf,MAX_STR_LEN); ExecCmd(cmdbuf); } return; }
bool CDBL_BCPInCmd::CommitBCPTrans(void) { if(WasSent()) { DBINT outrow = Check(bcp_batch(GetCmd())); if(outrow < 0) { SetHasFailed(); DATABASE_DRIVER_ERROR( "bcp_batch failed." + GetDbgInfo(), 223020 ); } return outrow > 0; } return false; }
CDBL_RowResult::~CDBL_RowResult() { try { if (m_ColFmt) { delete[] m_ColFmt; m_ColFmt = 0; } if (!m_EOR) Check(dbcanquery(GetCmd())); } NCBI_CATCH_ALL_X( 1, NCBI_CURRENT_FUNCTION ) }
bool CDBL_BCPInCmd::EndBCP(void) { if(WasSent()) { DBINT outrow = Check(bcp_done(GetCmd())); if(outrow < 0) { SetHasFailed(); DATABASE_DRIVER_ERROR( "bcp_done failed." + GetDbgInfo(), 223020 ); } SetWasSent(false); return outrow > 0; } return false; }