void handleAPPCCSetupInd(SignalType * TheSignal, ApplicationInstanceType * applicationInstanceData) { SignalType *appccSetupAckReqSignal; char StatusString[256]; char* tmp = StatusString; tmp = StringPrint(tmp, "\r\nApplication: outgoing call start: Calling party number: "); tmp = StringPrint(tmp, (char*) (getSignalData(TheSignal) + 1)); PrintStatus(0, StatusString); applicationInstanceData->state = outgoingcall; NewSignal(sizeof(SignalType) + 9, (void**) &appccSetupAckReqSignal); memcpy(appccSetupAckReqSignal->Address, TheSignal->Address, 4); getSignalData(appccSetupAckReqSignal)[0] = 0x08; /*//info element offset*/ getSignalData(appccSetupAckReqSignal)[1] = 0x01; /*UplaneEndpointStart*/ getSignalData(appccSetupAckReqSignal)[2] = 0x02; /*UplaneEndpointStart*/ getSignalData(appccSetupAckReqSignal)[3] = 0x00; /*UplaneEndpointStart*/ getSignalData(appccSetupAckReqSignal)[4] = 0x00; /*UplaneEndpointStart*/ getSignalData(appccSetupAckReqSignal)[5] = 0x1e; getSignalData(appccSetupAckReqSignal)[6] = 0x02; getSignalData(appccSetupAckReqSignal)[7] = 0x85; getSignalData(appccSetupAckReqSignal)[8] = 0x88; SendSignal(appccSetupAckReqSignal, APP_CC_PROCESS_ID, APP_CC_PRIMITIVE, APPCCSetupAckReq); }
static void EEPROMWriteReadTestHandler(SignalType * Signal) { switch (Signal->Event) { case EE_PRIMITIVE: switch (Signal->SubEvent) { case EE_READ_DATA_cfm: { char* ptr; EeStoreDataReqType *EeStoreDataReq; ptr = StringPrint(StatusString, "EE_READ_DATA_cfm["); ptr = StrPrintHexWord(ptr, EEP_UserDataArea); ptr = StringPrint(ptr, "]=["); ptr = StrPrintHexByte(ptr, eepromData[0]); ptr = StringPrint(ptr, "]"); PrintStatus(0, StatusString); eepromData[0]++; NewSignal(sizeof(EeStoreDataReqType) + 1, (void **) &EeStoreDataReq); getSignalData(EeStoreDataReq)[0] = eepromData[0]; EeStoreDataReq->DataTypes = EEDT_ANYADDRESS; EeStoreDataReq->SubsNo = 0; setAddressData(EEP_UserDataArea, 1); SendSignal((SignalType *) EeStoreDataReq, EE_PROCESS_ID, EE_PRIMITIVE, EE_STORE_DATA_req); setSignalHandler(APPLICATION_PROCESS_ID_PP, PPconnectionHandler, 0); } break; } } DeleteBuffer(Signal); }
int processCustomerRequest(String* name, String* object, int quantity, int num) { String Bottles = StringCreate("Bottles"); String Diapers = StringCreate("Diapers"); String Rattles = StringCreate("Rattles"); int error = 0; if (StringIsEqualTo(object, &Bottles)) { if (quantity <= store_inv.bottles) { store_inv.bottles -= quantity; customers[num].bottles += quantity; error = 0; } else { //error message printf("Sorry "); StringPrint(name); printf(", we only have %d Bottles\n", store_inv.bottles); error = 1; } } else if (StringIsEqualTo(object, &Diapers)) { if (quantity <= store_inv.diapers) { store_inv.diapers -= quantity; customers[num].diapers += quantity; error = 0; } else { //error message printf("Sorry "); StringPrint(name); printf(", we only have %d Diapers\n", store_inv.diapers); error = 1; } } else if (StringIsEqualTo(object, &Rattles)) { if (quantity <= store_inv.rattles) { store_inv.rattles -= quantity; customers[num].rattles += quantity; error = 0; } else { //error message printf("Sorry "); StringPrint(name); printf(", we only have %d Rattles\n", store_inv.rattles); error = 1; } } StringDestroy(&Bottles); StringDestroy(&Diapers); StringDestroy(&Rattles); if (error == 0) { return 0; } else { return 1; } }
void CVersion::setString() { #ifdef COPASI_DEBUG mVersion = StringPrint("%d.%d.%d (Debug)", mMajor, mMinor, mDevel); #else if (mComment == "stable") mVersion = StringPrint("%d.%d (Build %d)", mMajor, mMinor, mDevel); else if (mComment != "") mVersion = StringPrint("%d.%d.%d (%s)", mMajor, mMinor, mDevel, mComment.c_str()); else mVersion = StringPrint("%d.%d.%d", mMajor, mMinor, mDevel); #endif }
void processSummarize() { int max_bottles = 0; int max_diapers = 0; int max_rattles = 0; int bottle_loc = 0; int diaper_loc = 0; int rattle_loc = 0; printf("There are %d Bottles, %d Diapers and %d Rattles in inventory\n", store_inv.bottles, store_inv.diapers, store_inv.rattles); printf("we have had a total of %d different customers\n", num_customers); //find max bottles, diapers, and rattles purchasers for (int k = 0; k < num_customers; k += 1) { if (customers[k].bottles > max_bottles) { max_bottles = customers[k].bottles; bottle_loc = k; } if (customers[k].diapers > max_diapers) { max_diapers = customers[k].diapers; diaper_loc = k; } if (customers[k].rattles > max_rattles) { max_rattles = customers[k].rattles; rattle_loc = k; } } if (max_bottles == 0) { printf("no one has purchased any Bottles\n"); } else { StringPrint(&(customers[bottle_loc].name)); printf(" has purchased the most Bottles (%d)\n", max_bottles); } if (max_diapers == 0) { printf("no one has purchased any Diapers\n"); } else { StringPrint(&(customers[diaper_loc].name)); printf(" has purchased the most Diapers (%d)\n", max_diapers); } if (max_rattles == 0) { printf("no one has purchased any Rattles\n"); } else { StringPrint(&(customers[rattle_loc].name)); printf(" has purchased the most Rattles (%d)\n", max_rattles); } }
bool CExperimentObjectMap::setNumCols(const size_t & numCols) { if (numCols == size()) return true; // We only clear the vector of parameter. We do not destroy the parameter they are still // accessible through CCopasiContainer::mObjects and thus will be automatically destroyed. clear(); bool success = true; for (size_t col = 0; col < numCols; col++) { CCopasiParameterGroup * pGrp = assertGroup(StringPrint("%d", col)); // assertGroup() adds only newly created groups to mValue.pGROUP. We need to add the existing // ones. if (size() < col + 1) static_cast< elements * >(mpValue)->push_back(pGrp); success &= (elevate<CDataColumn, CCopasiParameterGroup>(pGrp) != NULL); } return success; }
const std::vector<std::string> & CDataArray::getAnnotationsString(size_t d, bool display) const { assert(d < mModes.size()); std::vector< std::string >::iterator itName = mAnnotationsString[d].begin(); std::vector< std::string >::iterator endName = mAnnotationsString[d].end(); if (mModes[d] == Mode::Numbers) { size_t Index = 1; for (; itName != endName; ++Index, ++itName) { *itName = StringPrint("%d", Index); } } else { std::vector<CRegisteredCommonName>::const_iterator itCN = mAnnotationsCN[d].begin(); for (; itName != endName; ++itCN, ++itName) { *itName = createDisplayName(*itCN); } } return mAnnotationsString[d]; }
bool DataIndex::DecodeFromString(const std::string &str) { if (!StringStartsWith(str, kIndexBlockMagic)) { LOG(ERROR)<< "invalid data index header"; return false; } block_info_.clear(); const char *begin = str.c_str() + kIndexBlockMagic.size(); const char *end = str.c_str() + str.size(); while (begin < end) { DataBlockInfo info; info.offset = ReadInt64(&begin); info.data_size = ReadInt32(&begin); int key_len = ReadVint(&begin, end); info.key = std::string(begin, key_len); begin += key_len; block_info_.push_back(info); } // Check if the content is overflow if (begin > end) { LOG(ERROR) << "incomplete file, " << StringPrint("begin: %p, end: %p", begin, end); return false; } return true; }
int main(void) { String s = StringCreate("Craig"); String t = s; // YOU STILL ONLY HAVE ONE STRING. Remember that t is a shallow reference, only a pointer to the same string. // printf() won't work since our string doesn't have a null terminator printf("Hello "); StringPrint(s); printf(" I see you're %d characters long\n", s.length); // using s.ptr and s.length is BAD, don't do this for the project! StringDestroy(s); }
std::string CCopasiTimeVariable::LL2String(const C_INT64 & value, const C_INT32 & digits) { std::string format; if (digits > 0) format = "%0" + StringPrint("%d", digits); else format = "%"; #ifdef WIN32 format += "I64d"; #else format += "lld"; #endif return StringPrint(format.c_str(), value); }
CExperiment::Type CExperimentObjectMap::getRole(const size_t & index) const { const CDataColumn * pColumn = dynamic_cast< const CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->getRole(); else return CExperiment::ignore; }
std::string CExperimentObjectMap::getObjectCN(const size_t & index) const { const CDataColumn * pColumn = dynamic_cast< const CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->getObjectCN(); else return ""; }
C_FLOAT64 CExperimentObjectMap::getDefaultScale(const size_t & index) const { const CDataColumn * pColumn = dynamic_cast< const CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->getDefaultScale(); else return std::numeric_limits<C_FLOAT64>::quiet_NaN(); }
bool CExperimentObjectMap::setRole(const size_t & index, const CExperiment::Type & role) { CDataColumn * pColumn = dynamic_cast< CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->setRole(role); else return false; }
bool CExperimentObjectMap::setScale(const size_t & index, const C_FLOAT64 & weight) { CDataColumn * pColumn = dynamic_cast< CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->setScale(weight); else return false; }
bool CExperimentObjectMap::setObjectCN(const size_t & index, const std::string & CN) { CDataColumn * pColumn = dynamic_cast< CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->setObjectCN((CCopasiObjectName) CN); else return false; }
void CQExperimentData::slotFileAdd() { QString File = CopasiFileDialog::getOpenFileName(this, "Open File Dialog", "", "Data Files (*.txt *.csv);;All Files (*)", "Open Data Files"); if (File.isNull()) return; std::map<std::string, std::string>::const_iterator it = mFileMap.begin(); std::map<std::string, std::string>::const_iterator end = mFileMap.end(); int i; for (; it != end; ++it) if (it->second == TO_UTF8(File)) { for (i = 0; i < mpBoxFile->count(); i++) if (it->first == TO_UTF8(mpBoxFile->item(i)->text())) { mpBoxFile->setCurrentRow(i); break; } return; } std::string FileName = CDirEntry::fileName(TO_UTF8(File)); i = 0; while (mFileMap.find(FileName) != mFileMap.end()) FileName = StringPrint("%s_%d", CDirEntry::fileName(TO_UTF8(File)).c_str(), i++); mFileMap[FileName] = TO_UTF8(File); mpBoxFile->addItem(FROM_UTF8(FileName)); mpBoxFile->setCurrentRow(mpBoxFile->count() - 1); size_t First, Last; if (mpFileInfo->getFirstUnusedSection(First, Last)) { do { slotExperimentAdd(); } while (mpBtnExperimentAdd->isEnabled()); mpBoxExperiment->setCurrentRow(0); } }
// virtual const std::string & CExperimentObjectMap::getName(const size_t & index) const { static const std::string NoName(""); const CDataColumn * pColumn = dynamic_cast< const CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) return pColumn->getObjectName(); else return NoName; }
int main(void) { String s = StringCreate("Craig"); String t = StringDup(s); t = s; printf("Hello "); StringPrint(s); printf(" I see you're %d characters long\n", StringSize(s)); StringDestroy(s); StringDestroy(t); }
void handleReleasePrim(SignalType * TheSignal, ApplicationInstanceType * applicationInstanceData) { char* tmp = StatusString; tmp = StringPrint(tmp, "Deleting application_fp node: "); tmp = StrPrintHexByte(tmp, applicationInstanceData->pmid[2]); PrintStatus(0, StatusString); if (applicationInstanceData->msfState != msf_idle) { applicationInstanceData->state = idle; PrintStatus(0, "Not deleted msf not idle."); } else if (DeleteNode(&applicationTree, applicationInstanceData->pmid)) { DeleteBuffer(applicationInstanceData); applicationInstanceData = 0; created--; PrintStatus(0, "deleted----: \r\n"); } else { PrintStatus(0, "Not deleted"); } }
const CDataObject * CDataArray::addElementReference(const CDataArray::index_type & index) const { CDataArray::name_index_type CNIndex(index.size()); CDataArray::name_index_type::iterator to = CNIndex.begin(); CDataArray::index_type::const_iterator it = index.begin(); CDataArray::index_type::const_iterator end = index.end(); std::vector< std::vector<CRegisteredCommonName> >::const_iterator itCN = mAnnotationsCN.begin(); for (; it != end; ++it, ++to, ++itCN) { *to = *it < itCN->size() ? itCN->operator [](*it) : CRegisteredCommonName(""); if (to->empty()) { *to = StringPrint("%d", *it); } } return addElementReference(CNIndex); }
CExperiment * CExperimentSet::addExperiment(const CExperiment & experiment) { // We need to make sure that the experiment name is unique. std::string name = experiment.getObjectName(); int i = 0; while (getParameter(name)) { i++; name = StringPrint("%s_%d", experiment.getObjectName().c_str(), i); } CExperiment * pExperiment = new CExperiment(experiment, NO_PARENT); pExperiment->setObjectName(name); addParameter(pExperiment); sort(); return pExperiment; }
CString CSqlDataBase::GetArithmeticName(uint32 nArithmetic, uint32 nHashRate) { CString oRet; char sLen[64]; switch(nArithmetic) { case MDB_RBTREE_INDEX: oRet += "rbtree"; break; /* case MDB_NTREE_INDEX: oRet += "ntree"; break; */ case MDB_HASH_INDEX: oRet += "hash"; StringPrint(sLen, "(%u)", nHashRate); oRet += sLen; break; } return oRet; }
bool DataBlock::DecodeInternal(const std::string &str) { if (!StringStartsWith(str, kDataBlockMagic)) { LOG(INFO)<< "invalid data block header."; return false; } data_items_.clear(); const char *begin = str.c_str() + kDataBlockMagic.size(); const char *end = str.c_str() + str.length(); while (begin < end) { int key_length = ReadInt32(&begin); int value_length = ReadInt32(&begin); std::string key = std::string(begin, key_length); begin += key_length; std::string value = std::string(begin, value_length); begin += value_length; data_items_.push_back(make_pair(key, value)); } if (begin > end) { LOG(ERROR) << "not a complete data block, " << StringPrint("begin: %p, end: %p", begin, end); return false; } return true; }
static void DSPMonitorTask(MailType *MailPtr) { switch (MailPtr->Primitive) { case INITTASK: { char *ptr; ptr = StringPrint(StatusString, "DSP[0x"); ptr = StrPrintHexWord(ptr, DSP_SEGMENT_SIZE); ptr = StringPrint(ptr, "] = [0x"); ptr = StrPrintHexAddr(ptr, (unsigned long) &DSPCodeAndRamArea[0]); ptr = StringPrint(ptr, "] -> [0x"); ptr = StrPrintHexAddr(ptr, (unsigned long) &DSPCodeAndRamArea[DSP_SEGMENT_SIZE - 1]); ptr = StringPrint(ptr, "]"); PrintStatus(0, StatusString); /* OSStartTimer(DSPMONITORTIMER, 100);*/ } break; case 0x2a: { } break; case TIMEOUT: { char* ptr = StringPrint(StatusString, "DSP tick["); ptr = StrPrintHexWord(ptr, dsp_interrupt_counter); ptr = StringPrint(ptr, "]"); __disable_interrupt(); dsp_interrupt_counter = 0; __enable_interrupt(); PrintStatus(0, StatusString); OSStartTimer(DSPMONITORTIMER, 100); } break; } }
void ConvertIpeiToSN(PPIDType user, char SerialNumber[17], IPEIType Hex_SN) { unsigned long first_part = 0; unsigned long second_part = 0; // 0x xx xm mm mm where x is the vendor number and m is the serial number first_part += (((unsigned long)Hex_SN[0] & 0x0F) << 12); // 0000 xxxx first_part += (((unsigned long)Hex_SN[1] & 0xFF) << 4); // xxxx xxxx first_part += (((unsigned long)Hex_SN[2] & 0xF0) >> 4); // xxxx 0000 second_part += (((unsigned long)Hex_SN[2] & 0x0F) << 16); // 0000 xxxx second_part += (((unsigned long)Hex_SN[3] & 0xFF) << 8); // xxxx xxxx second_part += (((unsigned long)Hex_SN[4] & 0xFF)); // xxxx xxxx unsigned long num = first_part; unsigned long test, power = 0; int count, i; for (i = 0; i < 4; i++) { switch(i) { case 0: power = 10000; break; case 1: power = 1000; break; case 2: power = 100; break; case 3: power = 10; break; } test = 0; count = 0; while (num >= test) { if ((test + power) > num) { num -= test; test += power; } else { test += power; count++; } } SerialNumber[i] = (unsigned char)(count + 48); } SerialNumber[4] = (unsigned char)(num + 48); SerialNumber[5] = ' '; num = second_part; for (i = 6; i < 12; i++) { switch(i) { case 6: power = 1000000; break; case 7: power = 100000; break; case 8: power = 10000; break; case 9: power = 1000; break; case 10: power = 100; break; case 11: power = 10; break; } test = 0; count = 0; while (num >= test) { if ((test + power) > num) { num -= test; test += power; } else { test += power; count++; } } SerialNumber[i] = (unsigned char)(count + 48); } SerialNumber[12] = (unsigned char)(num + 48); SerialNumber[13] = ' '; if (getRunMode()) // FP { if ((base_station).ListenOnly[user] == 0x01) { SerialNumber[14] = 'L'; SerialNumber[15] = 'O'; } else { SerialNumber[14] = ' '; SerialNumber[15] = ' '; } } else { if (headset.SystemMode == LISTEN_ONLY_MODE) { SerialNumber[14] = 'L'; SerialNumber[15] = 'O'; } else { SerialNumber[14] = ' '; SerialNumber[15] = ' '; } } SerialNumber[16] = '\0'; if (!(getRunMode())) // PP { char * tmp = StatusString; tmp = StringPrint(tmp, "***** Headset SN = "); tmp = StringPrint(tmp, SerialNumber); tmp = StringPrint(tmp, " *****"); PrintStatus(0, StatusString); } }
void ConvertHexSNtoAriSN(IPEIType Hex_SN, char SerialNumber[11]) { char * ptr; int i; BOOLEAN AfterFirstDigit = FALSE; unsigned long long int combined_hex_SN = 0, count, test, power = 0; combined_hex_SN += (unsigned long long int)Hex_SN[4]; combined_hex_SN += (unsigned long long int)Hex_SN[3] << 8; combined_hex_SN += (unsigned long long int)Hex_SN[2] << 16; combined_hex_SN += (unsigned long long int)Hex_SN[1] << 24; if (Hex_SN[0] == 0x01) combined_hex_SN += (unsigned long long int)0x01 << 32; for (i = 0; i < 9; i++) { switch(i) { case 0: power = 1000000000; break; case 1: power = 100000000; break; case 2: power = 10000000; break; case 3: power = 1000000; break; case 4: power = 100000; break; case 5: power = 10000; break; case 6: power = 1000; break; case 7: power = 100; break; case 8: power = 10; break; } test = 0; count = 0; while (combined_hex_SN >= test) { if ((test + power) > combined_hex_SN) { combined_hex_SN -= test; test += power; } else { test += power; count++; } } switch (count) { case 1: SerialNumber[i] = '1'; AfterFirstDigit = TRUE; break; case 2: SerialNumber[i] = '2'; AfterFirstDigit = TRUE; break; case 3: SerialNumber[i] = '3'; AfterFirstDigit = TRUE; break; case 4: SerialNumber[i] = '4'; AfterFirstDigit = TRUE; break; case 5: SerialNumber[i] = '5'; AfterFirstDigit = TRUE; break; case 6: SerialNumber[i] = '6'; AfterFirstDigit = TRUE; break; case 7: SerialNumber[i] = '7'; AfterFirstDigit = TRUE; break; case 8: SerialNumber[i] = '8'; AfterFirstDigit = TRUE; break; case 9: SerialNumber[i] = '9'; AfterFirstDigit = TRUE; break; } if (count == 0 && AfterFirstDigit) { SerialNumber[i] = '0'; } } switch (combined_hex_SN) { case 0: SerialNumber[9] = '0'; break; case 1: SerialNumber[9] = '1'; break; case 2: SerialNumber[9] = '2'; break; case 3: SerialNumber[9] = '3'; break; case 4: SerialNumber[9] = '4'; break; case 5: SerialNumber[9] = '5'; break; case 6: SerialNumber[9] = '6'; break; case 7: SerialNumber[9] = '7'; break; case 8: SerialNumber[9] = '8'; break; case 9: SerialNumber[9] = '9'; break; } SerialNumber[10] = '\0'; ptr = StringPrint(StatusString, "***** BaseStation ARI = "); ptr = StringPrint(ptr, SerialNumber); ptr = StringPrint(ptr, " *****"); PrintStatus(0, StatusString); }
bool CQExperimentData::load(CExperimentSet * pExperimentSet, CCopasiDataModel * pDataModel) { mpDataModel = pDataModel; #ifdef COPASI_CROSSVALIDATION mCrossValidation = (dynamic_cast< CCrossValidationSet * >(pExperimentSet) != NULL); #endif // COPASI_CROSSVALIDATION if (mCrossValidation) { setWindowTitle("Validation Data"); mpLblWeight->show(); mpEditWeight->show(); mpLblThreshold->show(); mpEditThreshold->show(); mpLineCrossValidation->show(); #ifdef COPASI_CROSSVALIDATION mpEditWeight->setText(QString::number(static_cast< CCrossValidationSet * >(pExperimentSet)->getWeight())); mpEditThreshold->setText(QString::number(static_cast< CCrossValidationSet * >(pExperimentSet)->getThreshold())); #endif // COPASI_CROSSVALIDATION } else { mpLblWeight->hide(); mpEditWeight->hide(); mpLblThreshold->hide(); mpEditThreshold->hide(); mpLineCrossValidation->hide(); } if (!pExperimentSet) return false; mpExperiment = NULL; mShown = -1; mpExperimentSet = pExperimentSet; pdelete(mpExperimentSetCopy); mpExperimentSetCopy = new CExperimentSet(*pExperimentSet); #ifdef COPASI_CROSSVALIDATION if (mCrossValidation) mpExperimentSetCopy = elevate< CCrossValidationSet, CExperimentSet >(mpExperimentSetCopy); #endif // COPASI_CROSSVALIDATION pdelete(mpFileInfo); mpFileInfo = new CExperimentFileInfo(*mpExperimentSetCopy); // Build the key map so that we are able to update the correct experiments // on OK. mKeyMap.clear(); size_t i, imax = mpExperimentSet->getExperimentCount(); for (i = 0; i < imax; i++) mKeyMap[mpExperimentSet->getExperiment(i)->CCopasiParameter::getKey()] = mpExperimentSetCopy->getExperiment(i)->CCopasiParameter::getKey(); // fill file list box mpBoxFile->clear(); std::vector< std::string > FileNames = mpExperimentSetCopy->getFileNames(); std::vector< std::string >::const_iterator it = FileNames.begin(); std::vector< std::string >::const_iterator end = FileNames.end(); std::string FileName; i = 0; mFileMap.clear(); for (; it != end; ++it) { FileName = CDirEntry::fileName(*it); while (mFileMap.find(FileName) != mFileMap.end()) FileName = StringPrint("%s_%d", CDirEntry::fileName(*it).c_str(), i++); mFileMap[FileName] = *it; mpBoxFile->addItem(FROM_UTF8(FileName)); } if (mpBoxFile->count()) mpBoxFile->setCurrentRow(0); // This triggers the rest of the update :) else slotFileChanged(NULL, NULL); return true; }
void PPconnectionHandler(SignalType * Signal) { switch (Signal->Event) { case APPLICATION_PRIMITIVE: { switch (Signal->SubEvent) { case MSFInd: { AppMSFType* msfInd = (AppMSFType*) Signal; char* msf = mem_malloc(msfInd->length + 1, 100); memcpy(msf, getAppMSFTypeIE(msfInd), msfInd->length); msf[msfInd->length] = '\0'; PrintStatus(0, msf); if (strlen(msf) > 4) { if (memcmp(msf, "DIAL", 4) == 0) { char *number = &msf[4]; if (strlen(number) < 5) { TimerType * timer = NewTimer(APPLICATION_PROCESS_ID_PP, WAIT_CONNECTION, 0); StartTimer(timer, 200); /* wait 2 sec before dialing call*/ memcpy(numberToDial, number, strlen(number)); numberToDial[strlen(number)] = '\0'; } } } mem_free(msf); break; } } } break; case IWU_PRIMITIVE: { switch (Signal->SubEvent) { case CC_SETUP_prim: { char* ptr; char CallingPartyNo[INFO_BUFSIZE]; CcSetupPrimType *CcSetupPrim = (CcSetupPrimType *) Signal; CallingPartyNoType *CallingPartyNoPtr; SignalIEType *SignalIE; TimerType * timer = NewTimer(APPLICATION_PROCESS_ID_PP, OFFHOOKTIMER, 0); StartTimer(timer, 200); /* wait 2 sec before accepting call*/ CallingPartyNoPtr = (CallingPartyNoType *) FindInfoElement(CallingPartyNoId, getCcSetupPrimTypeIE(CcSetupPrim) - 2, CcSetupPrim-> SignalHeader. SignalLength - sizeof(CcSetupPrimType) + 2); GetCallingPartyNo(CallingPartyNoPtr, CallingPartyNo, 32); SignalIE = (SignalIEType *) FindInfoElement(SignalId, getCcSetupPrimTypeIE(CcSetupPrim) - 2, CcSetupPrim->SignalHeader. SignalLength - sizeof(CcSetupPrimType) + 2); if (SignalIE) { } else { PrintStatus(0, "No SignalIE! EXTERNAL_RING"); } Signal->SignalLength = sizeof(CcAlertingPrimType); SendSignal(Signal, IWU_PROCESS_ID, IWU_PRIMITIVE, CC_ALERTING_prim); ptr = StringPrint(StatusString, "CallingPartyNo ["); ptr = StringPrint(ptr, CallingPartyNo); ptr = StringPrint(ptr, "]"); PrintStatus(0, StatusString); connected = 1; return; } case CC_RELEASE_COM_prim: break; case CC_RELEASE_prim: { SignalType* stopAudio; Signal->SignalLength = sizeof(CcReleaseComPrimType); SendSignal(Signal, IWU_PROCESS_ID, IWU_PRIMITIVE, CC_RELEASE_COM_prim); NewSignal(sizeof(SignalType), (void**) &stopAudio); SendSignal((SignalType*) stopAudio, DSP_PROCESS_ID, STOPAUDIO_EVENT, 0); return; } case CC_CONNECT_ACK_prim: { EeReadDataReqType *EeReadDataReq; NewSignal(sizeof(EeReadDataReqType) + sizeof(void *), (void **) &EeReadDataReq); EeReadDataReq->ReturnTIPD = TIPD_APPLICATION; EeReadDataReq->DataTypes = EEDT_ANYADDRESS; /* getEeReadDataReqTypeDataPtr(EeReadDataReq)[0] = (void *) &eepromData; */ memset(&eepromData, 0x00, 1); setAddressData(EEP_UserDataArea, 1); SendSignal((SignalType *) EeReadDataReq, EE_PROCESS_ID, EE_PRIMITIVE, EE_READ_DATA_req); setSignalHandler(APPLICATION_PROCESS_ID_PP, EEPROMWriteReadTestHandler, 0); } break; case CC_CONNECT_prim: { if (firsttime) { UByte * tmp; /* UByte cnt;*/ /*MuteTransmitter();*/ /*for (cnt=0; cnt < 6; cnt++)*/ { tmp = pp_get_speech_buffer(0); if (tmp != 0) { UByte count; char* ptr; ptr = StringPrint(StatusString, "***Buffer: ["); ptr = StrPrintHexAddr(ptr, (unsigned long) tmp); for (count = 0; count < 40; count++) { tmp[count] = 0x00; } tmp[0] = 0xCA; tmp[1] = 0xFE; tmp[2] = 0xBA; tmp[3] = 0xBE; tmp[4] = 0; tmp[5] = 0; tmp[6] = 0xff; tmp[7] = 0xff; ptr = StringPrint(ptr, "]"); PrintStatus(0, StatusString); { TimerType* connectionTimer = NewTimer(APPLICATION_PROCESS_ID_PP, PEIODICTIMER, 0); StartTimer(connectionTimer, 500); /* Wait 1 sec*/ PrintStatus(0, "start the timer"); } } else { PrintStatus(0, "tmp==0"); } } firsttime = 0; } } case CC_INFO_prim: /*do not break*/ break; case CC_SETUP_ACK_prim: break; case CC_CALL_PROC_prim: break; case CC_ALERTING_prim: break; case SS_SETUP_prim: handle_ss_setup(Signal); break; case SS_FACILITY_prim: handle_ss_facility(Signal); break; default: { char* ptr; ptr = StringPrint(StatusString, "Unknown IWU_PRIMITIVE [0x"); ptr = StrPrintHexByte(ptr, Signal->SubEvent); ptr = StringPrint(ptr, "]"); PrintStatus(0, StatusString); } } } break; case TIME_OUT_EVENT: { switch (Signal->SubEvent) { case SENDMSFTIMER: { /* PrintStatus(0, "Sending MSF");*/ /* SendMsfMessage("2001", "OK!");*/ } break; case WAIT_CONNECTION: { callUser_PP(numberToDial, 0); setSignalHandler(APPLICATION_PROCESS_ID_PP, PPDialingHandler, 0); } break; case OFFHOOKTIMER: { if (connected) { PrintStatus(0, "Accepting call!"); off_hook(); } } break; case PEIODICTIMER: { UByte * tmp; TimerType* connectionTimer = NewTimer(APPLICATION_PROCESS_ID_PP, PEIODICTIMER, 0); PrintStatus(0, "PEIODICTIMER"); StartTimer(connectionTimer, 500); /* Wait 1 sec*/ tmp = pp_get_speech_buffer(1); if (tmp != 0) { int c; char* ptr; ptr = StringPrint(StatusString, "***Buffer: ["); ptr = StrPrintHexAddr(ptr, (unsigned long) tmp); ptr = StringPrint(ptr, "-"); for (c = 0; c < 8; c++) { ptr = StrPrintHexByte(ptr, tmp[c]); ptr = StringPrint(ptr, ","); } ptr = StringPrint(ptr, "]"); PrintStatus(0, StatusString); } else { PrintStatus(0, "tmp==0"); } } break; default: { PrintStatus(0, "Unknown TIME_OUT_EVENT in connection handler"); } } } break; default: { PrintStatus(0, "Unknown event to connection handler"); } } DeleteBuffer(Signal); }
virtual bool OnInitialize() { uint32 nLength; const char* sVal = NULL; CTextAccess oAccess; CInitConfigSystem* pConfigSystem = CInitConfigSystem::GetInstance(); //Register telnet command line interface CCmdSystem::GetInstance()->RegisterCmd("/Mdb", "Mdb<CR>:\r\n\t sql command line", MdbSqlCmdFunc); //Create Local Memory Database uint32 nMdbSvr = 0; if(pConfigSystem->OpenConfig(oAccess, "MdbService", true)) { oAccess.OpenIdxVal(); if(oAccess.Query()) { sVal = oAccess.GetVal("MdbSvr", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbService.ServerPort' is invalid")); return false; } nMdbSvr = CString::Atoi(sVal); sVal = oAccess.GetVal("MdbList", nLength); } } bool bInitializeMdbDataSource = false; bool bInitializeMdbStorageAttr = false; bool bCreateMdbReplicator = false; bool bConfigMdbDomain = false; if(sVal && sVal[0]) { bool bCreated = false; char*pShift, *pDbName = (char*)sVal; while(pDbName) { pShift = (char*)CString::CharOfString(pDbName, ','); if(pShift) pShift[0] = 0; if(m_pMdbItf == NULL) { m_pMdbItf = new CLocalMdbItf; if(!m_pMdbItf->Valid()) { if(pShift) pShift[0] = ','; return false; } } if(!m_pMdbItf->CreateMemoryDataBase(pDbName)) { if(pShift) pShift[0] = ','; return false; } bCreated = true; CCmdSession oSession; char sDbfScript[FOCP_MAX_PATH]; const char* sHome = CFilePathInfo::GetInstance()->GetHome(); StringPrint(sDbfScript, "%s/dbf/%s.Create.sql", sHome, pDbName); oSession.ProcessScript(sDbfScript); pDbName = pShift; if(pDbName) { pDbName[0] = ','; ++pDbName; } } if(bCreated)//创建了本地数据库 { if(pConfigSystem->OpenConfig(oAccess, "MdbStorage", true)) { oAccess.OpenIdxVal(); while(oAccess.Query()) { sVal = oAccess.GetVal("MdbName", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.MdbName' is invalid")); return false; } CString oMdbName(sVal); sVal = oAccess.GetVal("CacheName", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.CacheName' is invalid")); return false; } CString oMdbTabName(sVal); sVal = oAccess.GetVal("TableName", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.TableName' is invalid")); return false; } CString oDbTabName(sVal?sVal:(char*)""); sVal = oAccess.GetVal("LoadWhere", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.LoadWhere' is invalid")); return false; } CString oLoadWhere(sVal?sVal:""); sVal = oAccess.GetVal("StorageWhere", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.StorageWhere' is invalid")); return false; } CString oStorageWhere(sVal?sVal:(char*)""); sVal = oAccess.GetVal("CacheWhere", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.CacheWhere' is invalid")); return false; } CString oCacheWhere(sVal?sVal:(char*)""); sVal = oAccess.GetVal("StorageIdx", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.StorageIdx' is invalid")); return false; } CString oStorageIdx(sVal); sVal = oAccess.GetVal("FieldList", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.FieldList' is invalid")); return false; } CString oFieldList(sVal?sVal:(char*)""); if(m_pStoItf == NULL) { m_pStoItf = new CMdbStoItf; if(!m_pStoItf->Valid()) return false; } if(!m_pStoItf->InitializeMdbStorageAttr(oMdbName.GetStr(), oMdbTabName.GetStr(), oDbTabName.GetStr(), oLoadWhere.GetStr(), oStorageWhere.GetStr(), oCacheWhere.GetStr(), oStorageIdx.GetStr(), oFieldList.GetStr())) return false; bInitializeMdbStorageAttr = true; } } if(pConfigSystem->OpenConfig(oAccess, "MdbReplication", true)) { oAccess.OpenIdxVal(); while(oAccess.Query()) { sVal = oAccess.GetVal("MdbName", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.MdbName' is invalid")); return false; } CString oDbName(sVal); sVal = oAccess.GetVal("TableName", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.TableName' is invalid")); return false; } CString oTabName(sVal); sVal = oAccess.GetVal("ReplicateTable", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.ReplicateTable' is invalid")); return false; } uint32 bTableReplicative = CString::Atoi(sVal); sVal = oAccess.GetVal("WithoutFields", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.WithoutFields' is invalid")); return false; } uint32 bWithout = CString::Atoi(sVal); sVal = oAccess.GetVal("Fields", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.Fields' is invalid")); return false; } CString oFields(sVal?sVal:(char*)""); sVal = oAccess.GetVal("Where", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.Where' is invalid")); return false; } CString oWhere(sVal?sVal:(char*)""); sVal = oAccess.GetVal("TransferIdx", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.TransferIdx' is invalid")); return false; } if(!m_pRepItf) { m_pRepItf = new CMdbRepItf; if(!m_pRepItf->Valid()) return false; } if(!m_pRepItf->CreateMdbReplicator(oDbName.GetStr(), oTabName.GetStr(), sVal, bTableReplicative?true:false, bWithout?true:false, oFields.GetStr(), oWhere.GetStr())) return false; bCreateMdbReplicator = true; } } if( (bCreateMdbReplicator || bInitializeMdbStorageAttr) && pConfigSystem->OpenConfig(oAccess, "MdbDomain", true)) { oAccess.OpenIdxVal(); while(oAccess.Query()) { sVal = oAccess.GetVal("MdbDomain", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.MdbDomain' is invalid")); return false; } uint32 nDomain = CString::Atoi(sVal); sVal = oAccess.GetVal("MdbName", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.MdbName' is invalid")); return false; } if(bCreateMdbReplicator) { if(!m_pRepItf->ConfigMdbDomain(sVal, nDomain)) return false; bConfigMdbDomain = true; } if(bInitializeMdbStorageAttr) { CString oMdbName(sVal); sVal = oAccess.GetVal("OdbcSource", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.OdbcSource' is invalid")); return false; } if(!sVal) continue; CString oOdbcDsn, oOdbcUser, oOdbcPasswd; if(!GetOdbcSourceInfo(sVal, oOdbcDsn, oOdbcUser, oOdbcPasswd)) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.OdbcSource' is invalid")); return false; } sVal = oAccess.GetVal("EventDb", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.EventDb' is invalid")); return false; } CString oEventDb(sVal?sVal:""); sVal = oAccess.GetVal("EventTable", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.EventTable' is invalid")); return false; } CString oEventTable(sVal?sVal:""); uint32 nSupportStorage = 0; sVal = oAccess.GetVal("SupportStorage", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.SupportStorage' is invalid")); return false; } if(sVal) nSupportStorage = CString::Atoi(sVal); if(!m_pStoItf->InitializeMdbDataSource(oMdbName.GetStr(), nDomain, (nSupportStorage!=0), oOdbcDsn.GetStr(), oOdbcUser.GetStr(), oOdbcPasswd.GetStr(), oEventDb.GetStr(), oEventTable.GetStr())) return false; bInitializeMdbDataSource = true; } } if(bConfigMdbDomain && !m_pRepItf->RegisterMdbTransfer()) return false; } } } //Create Remote Memory Database if(pConfigSystem->OpenConfig(oAccess, "RemoteMdb", true)) { CString oServerAddr; uint32 nServerPort; const char* sDbList; oAccess.OpenIdxVal(); while(oAccess.Query()) { sVal = oAccess.GetVal("ServerPort", nLength); if(!sVal || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerPort' is invalid")); return false; } nServerPort = CString::Atoi(sVal); if(!nServerPort || nServerPort > 65535) { FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerPort' is invalid")); return false; } sVal = oAccess.GetVal("ServerAddr", nLength); if(!sVal || !sVal[0] || sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerAddr' is invalid")); return false; } oServerAddr = sVal; sVal = oAccess.GetVal("MdbList", nLength); if(sVal && sVal[nLength-1]) { FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.MdbList' is invalid")); return false; } sDbList = sVal; if(m_pRdbItf == NULL) { m_pRdbItf = new CRemoteMdbItf; if(!m_pRdbItf->Valid()) return false; } void* pRdbList = m_pRdbItf->CreateMdbClient(sDbList, oServerAddr.GetStr(), (uint16)nServerPort); if(pRdbList == NULL) return false; m_oMdbClients.Insert((char*)pRdbList); } } // Create Mdb Server if(nMdbSvr) { CService* pService = CServiceManager::GetInstance()->QueryService("AcmService"); if(!pService) { FocpLog(FOCP_LOG_ERROR, ("MdbService need AcmService for MdbSvrModule, but there isn't it")); return false; } if(!Wait(pService, FOCP_SERVICE_INITIALIZED)) return false; if(!pService->HaveAbility(ACM_TCPSVR_ABILITY)) { FocpLog(FOCP_LOG_ERROR, ("MdbService need AcmService's tcp server ability for MdbSvrModule, but there isn't it")); return false; } m_pSvrItf = new CMdbServerItf; if(!m_pSvrItf->Valid()) return false; } if(!bConfigMdbDomain && m_pRepItf) { m_pRepItf->CleanupMdbReplication(); delete m_pStoItf; m_pStoItf = NULL; } if(!bInitializeMdbDataSource && m_pStoItf) { m_pStoItf->CleanupMdbStorage(); delete m_pStoItf; m_pStoItf = NULL; } const char* sCreateCode = GetEnvVar("CreateMdbCode"); if(sCreateCode && sCreateCode[0] == '1') CMdb::CreateCppCode(); return true; }