/// Extract a string from a tuple value Value::operator std::string () const { if (!isString()) throw RunError("trying to cast non-string value to string"); return (std::string)(Tuple)(*this); }
/// Extract a pointer from a value Value::operator void* () const { if (!isPointer()) throw RunError("trying to cast non-pointer value to pointer"); return word.ptr; }
Tuple::Tuple(Value value) { if (!value.isTuple() && !value.isString()) throw RunError("non-tuple value in tuple constructor"); tuple = value; }
/// Extract an integer from a value Value::operator int64_t () const { if (tag != Tag::int64) throw RunError("trying to cast non-integer value to integer"); return word.int64; }
/// Update an integer value Value Value::operator = (int64_t v) { if (tag != Tag::int64) throw RunError("trying to assign non-integer to integer value"); word.int64 = v; return *this; }
void MexFunction::load() { char *error; lib_handle = dlopen(fileName.c_str(), RTLD_LAZY); if (!lib_handle) { // fprintf(stderr, "%s\n", dlerror()); //exit(1); throw RunError(std::string("Error while opening Mex File :") + dlerror()); } fn =dlsym(lib_handle,"mexFunction"); if ((error = dlerror()) != NULL) { //fprintf(stderr, "%s\n", error); //exit(1); throw RunError(std::string("Error while opening Mex File :")+ error); } }
/*************************************************************** * Function: DataObject::convert() * Purpose : Convert the object to the requested type * Initial : Maxime Chevalier-Boisvert on February 18, 2009 **************************************************************** Revisions and bug fixes: */ DataObject* DataObject::convert(DataObject::Type outType) const { // If the requested type is the local type, return a copy if (outType == m_type) return copy(); // By default, throw an exception and deny the type conversion throw RunError( "unsupported type conversion requested: " + getTypeName(m_type) + " => " + getTypeName(outType) ); }
// --------------------------------------------------------------------------- // CDevCertKeyStoreServer::RunL() // --------------------------------------------------------------------------- // void CDevCertKeyStoreServer::RunL() { User::LeaveIfError(iStatus.Int()); switch (iAction) { case ECreateKeyCreate: DoCreateKeyL(); iAction = ECreateKeyFinal; break; case ECreateKeyFinal: DoStoreKeyL(); // Check iKeyInfo was initialised for the caller ASSERT(iKeyInfo->HandleID() != 0); RunError(KErrNone); break; case EImportKey: { TRAPD(err, DoImportKeyL()); if (err == KErrTooBig) { // Returned by ASN library if data is unexpected probably as a result of // bad import data err = KErrArgument; } User::LeaveIfError(err); RunError(KErrNone); break; } case EExportKey: { CompleteKeyExportL(); break; } default: ASSERT(EFalse); } }
/// Value constructor Value::Value(Word w, Tag t) { switch (t) { case Tag::string: if (w.ptr == NULL) throw RunError("null string pointer in value constructor"); break; case Tag::tuple: case Tag::hostfn: if (w.ptr == NULL) throw RunError("null object pointer in value constructor"); break; default: break; } word = w; tag = t; }
/// Get the value of the ith element Value& Tuple::operator [] (size_t i) { if (i >= length()) throw RunError("invalid element index"); // TODO: method to get the value array pointer? // do this refactoring after, have OFS_LENGTH, OFS_VALUES, etc auto ptr = (uint8_t*)(void*)tuple; auto valArr = (Value*)(ptr + sizeof(uint32_t) + 4); return valArr[i]; }
Tuple::Tuple(size_t length, Tag tag) { if (tag != Tag::tuple && tag != Tag::string) throw RunError("non-tuple tag in tuple constructor"); auto numBytes = memSize(length); auto ptr = vm.alloc(numBytes); // Set the internal tuple pointer tuple = Value(ptr, tag); // Set the tuple length *(uint32_t*)ptr = length; }
void CUnifiedCertStore::DoCancel() { // If the current state is the last state involved in handling a request, we // check to see if we have already been completed - in this case we can // simply complete the client with iStatus (this may be KErrNone). If we // have not we cancel the outstanding request and pass the resulting iStatus // back to the client - this too may indicate a successful completion if the // cancel arrived after the request was executed. // // For more complex cases, where there are more states to go through before // we finish servicing the client request, we cancel any outstanding // request, and return KErrCancel to the client. switch (iState) { case EInitializeFinished: case ERetrieve: case EGetCert: case EApplications: case EIsApplicable: case ETrusted: case ERetrieveData: case ERemove: case ESetApplicability: case ESetTrust: if (iStatus == KRequestPending) { // Attempt to cancel outstanding request and pass status back to // client CancelOutstandingRequest(); Complete(iStatus.Int()); } else { // We've already been completed - call RunL() to process results // and complete client TRAPD(err, RunL()); if (err != KErrNone) { RunError(err); } } break; default: CancelOutstandingRequest(); Complete(KErrCancel); break; } }
// --------------------------------------------------------------------------- // CDevCertKeyStoreServer::DoCancel() // --------------------------------------------------------------------------- // void CDevCertKeyStoreServer::DoCancel() { switch (iAction) { case ECreateKeyFinal: ASSERT(iKeyCreator); iKeyCreator->Cancel(); break; default: // Nothing to do break; } RunError(KErrCancel); }
RunError notInAlphabet(QString letter, MarkovAlphabet alphabet_m, QString name="T") { QString old_alphabet = QObject::tr("%1").arg(letter); // QSet<QChar> alphabet = alphabet_m.getAlphabet(); // foreach (const QChar value, alphabet) // { // old_alphabet += QObject::tr(", %1").arg(value); // } old_alphabet += ", " + alphabet_m.getSource(); QString title=QObject::tr("Symbol '%1' is not in alphabet").arg(letter); QString description=QObject::tr("You can add it to alphabet. Examples: '%1 = {%2}'.") .arg(name) .arg(old_alphabet); return RunError(title, description, 305); }
/// Casting operator to extract a string value Tuple::operator std::string () { auto len = length(); std::string str; str.reserve(len); for (size_t i = 0; i < len; ++i) { auto v = (*this)[i]; if (!v.isInt64()) throw RunError("tuple to string cast found non-integer element"); str += (char)(int64_t)v; } return str; }
void CCheckedCertStore::DoCancel() { // (see notes on cancellation in CUnifiedCertStore::DoCancel) switch (iState) { case EGetKeyInfosForList: case EAdd: case ERemove: case ESetApplicability: case ESetTrust: if (iStatus == KRequestPending) { // Attempt to cancel outstanding request and pass status back to // client CancelOutstandingRequest(); Complete(iStatus.Int()); } else { // We've already been completed - call RunL() to process results // and complete client TRAPD(err, RunL()); if (err != KErrNone) { RunError(err); } } break; default: CancelOutstandingRequest(); Complete(KErrCancel); break; } }
/** * * Server session service function * * @param "aMessage" * The message to be serviced. * * @xxxx * */ void CTestFrameworkServerSession::ServiceL(const RMmfIpcMessage& aMessage) { switch (aMessage.Function()) { case ECreateInputWindow: SetOwnCopyOfWindowMessageL(aMessage); iServer->AddInputWindowL(this); break; case ENotifyIfWindowChange: SetOwnCopyOfWindowMessageL(aMessage); break; case ECancelNotifyIfWindowChange: CompleteOwnCopyOfWindowMessage(KErrCancel); aMessage.Complete(KErrNone); break; // logging messages case EOpenLog: { TBuf<KMaxLogFilenameLength> msgBuf; TInt r = MmfMessageUtilX::Read(aMessage, 0, msgBuf); if (r != KErrNone) RunError(aMessage, r); else { iServer->OpenLogL(msgBuf, aMessage.Int1()); aMessage.Complete(KErrNone); } } break; case EWriteLog: { TBuf<KMaxLogLineLength> msgBuf; TInt r = MmfMessageUtilX::Read(aMessage, 0, msgBuf); if (r != KErrNone) RunError(aMessage, r); else { iServer->WriteLog(msgBuf, aMessage.Int1()); aMessage.Complete(KErrNone); } } break; case ECloseLog: iServer->CloseLog(); aMessage.Complete(KErrNone); break; case ELogStatus: { TPckgBuf<TInt> countPckg(iServer->LogStatus()); TInt r = MmfMessageUtilX::Write(aMessage, 0, countPckg); if (r != KErrNone) RunError(aMessage, r); else aMessage.Complete(KErrNone); } break; default: // ? should panic here break; } }
// --------------------------------------------------------------------------- // CDevCertKeyStoreServer::CompleteKeyExportL() // --------------------------------------------------------------------------- // void CDevCertKeyStoreServer::CompleteKeyExportL() { ASSERT(iKeyData); ASSERT(iExportBuf.Ptr()); CDevTokenKeyInfo::EKeyAlgorithm keyAlgorithm = iKeyInfo->Algorithm(); RStoreReadStream privStream; iKeyDataManager->OpenPrivateDataStreamLC(*iKeyData, privStream); CASN1EncSequence* encoded = NULL; switch(keyAlgorithm) { case (CDevTokenKeyInfo::ERSA): { RStoreReadStream pubStream; iKeyDataManager->OpenPublicDataStreamLC(*iKeyData, pubStream); CRSAPublicKey* publicKey = NULL; CreateL(pubStream, publicKey); ASSERT(publicKey); CleanupStack::PushL(publicKey); CRSAPrivateKey* privateKey = NULL; CreateL(privStream, privateKey); ASSERT(privateKey); CleanupStack::PushL(privateKey); encoded = TASN1EncPKCS8::EncodeL(*(static_cast<CRSAPrivateKeyCRT*>(privateKey)), *publicKey, iKeyInfo->PKCS8AttributeSet()); CleanupStack::PopAndDestroy(3, &pubStream); // privateKey, publicKey, pubStream } break; case (CDevTokenKeyInfo::EDSA): { CDSAPrivateKey* privateKey = NULL; CreateL(privStream, privateKey); ASSERT(privateKey); CleanupStack::PushL(privateKey); encoded = TASN1EncPKCS8::EncodeL(*privateKey, iKeyInfo->PKCS8AttributeSet()); CleanupStack::PopAndDestroy(privateKey); } break; case (CDevTokenKeyInfo::EInvalidAlgorithm): default: User::Leave(KErrKeyAlgorithm); break; } // common to all algorithms ASSERT(encoded); CleanupStack::PushL(encoded); if (encoded->LengthDER() > static_cast<TUint>(iExportBuf.MaxLength())) { User::Leave(KErrOverflow); } TUint pos=0; encoded->WriteDERL(iExportBuf, pos); // WriteDERL does not set the length of the buffer, we do it ourselves iExportBuf.SetLength(encoded->LengthDER()); CleanupStack::PopAndDestroy(encoded); CleanupStack::PopAndDestroy(&privStream); RunError(KErrNone); }