DEFINE_FUNCTION_DDL_2(bool_t, bcmp) { if (args.size() != 3) throw FunctionException("3 args required"); int cmpResult = cmp(parse<T>(args[0]), parse<T>(args[2])); if (args[1] == cmp_name_eq()) return cmpResult == 0; if (args[1] == cmp_name_ne()) return cmpResult != 0; if (args[1] == cmp_name_gt()) return cmpResult > 0; if (args[1] == cmp_name_ge()) return cmpResult >= 0; if (args[1] == cmp_name_lt()) return cmpResult < 0; if (args[1] == cmp_name_le()) return cmpResult <= 0; throw FunctionException("unknown cmp:" + args[1]); }
DEFINE_FUNCTION_DHLX_2(bool_t, bcmp) { T arg0(parse<T>(sc)); sc.get(SourceTokenDHLX::TT_OP_COMMA); std::string arg1(sc.get(SourceTokenDHLX::TT_IDENTIFIER).getData()); sc.get(SourceTokenDHLX::TT_OP_COMMA); T arg2(parse<T>(sc)); int cmpResult(cmp(arg0, arg2)); if (arg1 == cmp_name_eq()) return cmpResult == 0; if (arg1 == cmp_name_ne()) return cmpResult != 0; if (arg1 == cmp_name_gt()) return cmpResult > 0; if (arg1 == cmp_name_ge()) return cmpResult >= 0; if (arg1 == cmp_name_lt()) return cmpResult < 0; if (arg1 == cmp_name_le()) return cmpResult <= 0; throw FunctionException("unknown cmp:" + arg1); }
bool CETDongle::OpenETDongle( ) { bool bRet = false; DWORD dwRet = ET_S_SUCCESS; DWORD dwEtCounter = 0; quint8 bSN[ MAX_ID_LEN ] = { 0 }; DWORD dwOut = 0; QString strHID = ""; if ( NULL == DongleEnum ) { return bRet; } dwRet = DongleEnum( NULL, &dwEtCounter ); bRet = ( ET_S_SUCCESS == dwRet || ET_E_INSUFFICIENT_BUFFER == dwRet ); if ( !bRet ) { FunctionException( dwRet ); return bRet; } if ( 0 == dwEtCounter ) { QString strMsg = "请插入正确的加密狗!"; EmitDongleException( strMsg, true, true ); return bRet; } ET_CONTEXT* pContext = new ET_CONTEXT[ dwEtCounter ]; bRet = ( NULL != pContext ); if ( !bRet ) { EmitDongleException( "创建加密狗上下文资源失败。", true, true ); return bRet; } memset( pContext, 0, sizeof ( ET_CONTEXT ) * dwEtCounter ); dwRet = DongleEnum( pContext, &dwEtCounter ); FunctionException( dwRet ); bRet = ( ET_S_SUCCESS == dwRet ); if ( !bRet || 0 == dwEtCounter || NULL == DongleOpen) { delete [ ] pContext; pContext = NULL; return bRet; } QStringList lstIndexs; bool bHaveAdmin = false; for ( DWORD dwItem = 0; dwItem < dwEtCounter; dwItem++ ) { dwRet = DongleOpen( &pContext[ dwItem ] ); bRet = ( ET_S_SUCCESS == dwRet ); if ( !bRet ) { continue; } if ( dwCustomerID == pContext[ dwItem ].dwCustomer && QByteArray( ( LPCSTR ) pContext[ dwItem ].bAtr, pContext[ dwItem ].dwAtrLen ) == QByteArray( ( LPCSTR ) bATR, sizeof ( bATR ) ) ) { if ( 1 < dwEtCounter ) { // 管理员优先 dwRet = DongleControl( &pContext[ dwItem ], ET_GET_SERIAL_NUMBER, NULL, 0, bSN, sizeof ( bSN ), &dwOut); bRet = ( ET_S_SUCCESS == dwRet ); if ( bRet ) { strHID = QString( QByteArray( ( LPCSTR ) bSN, sizeof ( bSN ) ).toHex( ).toUpper( ) ); if ( IsAdminHID( strHID ) ) { if ( bHaveAdmin ) { lstIndexs << QString::number( dwItem ); continue; } bHaveAdmin = true; memcpy( pETContext, ( CONST LPVOID) &pContext[ dwItem ], sizeof ( ET_CONTEXT ) ); continue; } else { lstIndexs << QString::number( dwItem ); continue; } } } else { // One memcpy( pETContext, ( CONST LPVOID) &pContext[ dwItem ], sizeof ( ET_CONTEXT ) ); break; } } DongleClose( &pContext[ dwItem ] ); bRet = false; } if ( !bHaveAdmin && lstIndexs.count( ) > 0 ) { strHID = lstIndexs[ 0 ]; DWORD dwIndex = strHID.toULong( ); memcpy( pETContext, ( CONST LPVOID) &pContext[ dwIndex ], sizeof ( ET_CONTEXT ) ); lstIndexs.removeAt( 0 ); } foreach ( const QString strIndex, lstIndexs ) { DWORD dwIndex = strIndex.toULong( ); DongleClose( &pContext[ dwIndex ] ); }
//------------------------------------------------------------------------------ // bool GmatFunction::Execute(ObjectInitializer *objInit, bool reinitialize) //------------------------------------------------------------------------------ bool GmatFunction::Execute(ObjectInitializer *objInit, bool reinitialize) { if (!fcs) return false; if (!objInit) return false; #ifdef DEBUG_TRACE static Integer callCount = 0; callCount++; clock_t t1 = clock(); ShowTrace(callCount, t1, wxT("GmatFunction::Execute() entered")); #endif #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("======================================================================\n") wxT("GmatFunction::Execute() entered for '%s'\n internalCS is <%p>, ") wxT("reinitialize = %d\n"), functionName.c_str(), internalCoordSys, reinitialize); #endif GmatCommand *current = fcs; GmatCommand *last = NULL; // We want to initialize local objects with new object map, // so do it everytime (loj: 2008.09.26) // This causes to slow down function execution, so initialize if necessary if (reinitialize) objectsInitialized = false; // Reinitialize CoordinateSystem to fix bug 1599 (LOJ: 2009.11.05) // Reinitialize Parameters to fix bug 1519 (LOJ: 2009.09.16) if (objectsInitialized) { if (!objInit->InitializeObjects(true, Gmat::COORDINATE_SYSTEM)) throw FunctionException (wxT("Failed to re-initialize Parameters in the \"") + functionName + wxT("\"")); if (!objInit->InitializeObjects(true, Gmat::PARAMETER)) throw FunctionException (wxT("Failed to re-initialize Parameters in the \"") + functionName + wxT("\"")); } // Go through each command in the sequence and execute. // Once it gets to a real command, initialize local and automatic objects. while (current) { // Call to IsNextAFunction is necessary for branch commands in particular #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("......Function executing <%p><%s> [%s]\n"), current, current->GetTypeName().c_str(), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str()); MessageInterface::ShowMessage(wxT(" objectsInitialized=%d\n"), objectsInitialized); #endif last = current; if (!objectsInitialized) { // Since we don't know where actual mission sequence starts, just check // for command that is not NoOp, Create, Global, and GMAT with equation. // Can we have simple command indicating beginning of the sequence, // such as BeginSequence? (loj: 2008.06.19) // @todo: Now we have BeginMissionSequence, but not all functions have it, // so check it first otherwise do in the old way. (loj: 2010.07.16) Function *func = current->GetCurrentFunction(); bool isEquation = false; wxString cmdType = current->GetTypeName(); if (func && cmdType == wxT("GMAT")) if (((Assignment*)current)->GetMathTree() != NULL) isEquation = true; if (cmdType != wxT("NoOp") && cmdType != wxT("Create") && cmdType != wxT("Global")) { bool beginInit = true; if (cmdType == wxT("GMAT") && !isEquation) beginInit = false; if (cmdType == wxT("BeginMissionSequence") || cmdType == wxT("BeginScript")) beginInit = true; if (beginInit) { objectsInitialized = true; validator->HandleCcsdsEphemerisFile(objectStore, true); #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("============================ Initializing LocalObjects at current\n") wxT("%s\n"), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str()); #endif InitializeLocalObjects(objInit, current, true); } } } // Now execute the function sequence try { #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("Now calling <%p>[%s]->Execute()\n"), current->GetTypeName().c_str(), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str()); #endif if (!(current->Execute())) return false; } catch (BaseException &e) { // If it is user interrupt, rethrow (loj: 2008.10.16) // How can we tell if it is thrown by Stop command? // For now just find the phrase wxT("interrupted by Stop command") wxString msg = e.GetFullMessage(); if (msg.find(wxT("interrupted by Stop command")) != msg.npos) { #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("*** Interrupted by Stop commaned, so re-throwing...\n")); #endif throw; } if (e.IsFatal()) { #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("*** The exception is fatal, so re-throwing...\n")); #endif // Add command line to error message (LOJ: 2010.04.13) throw FunctionException (wxT("In ") + current->GetGeneratingString(Gmat::NO_COMMENTS) + wxT(", ") + e.GetFullMessage()); //throw; } // Let's try initialzing local objects here again (2008.10.14) try { #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("============================ Reinitializing LocalObjects at current\n") wxT("%s\n"), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str()); #endif InitializeLocalObjects(objInit, current, false); #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("......Function re-executing <%p><%s> [%s]\n"), current, current->GetTypeName().c_str(), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str()); #endif if (!(current->Execute())) return false; } catch (HardwareException &he) { // Ignore for hardware exception since spacecraft is associated with Thruster // but Thruster binds with Tank later in the fcs } catch (BaseException &be) { throw FunctionException (wxT("During initialization of local objects before \"") + current->GetGeneratingString(Gmat::NO_COMMENTS) + wxT("\", ") + e.GetFullMessage()); } } // If current command is BranchCommand and still executing, continue to next // command in the branch (LOJ: 2009.03.24) if (current->IsOfType(wxT("BranchCommand")) && current->IsExecuting()) { #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("In Function '%s', still executing current command is <%p><%s>\n"), functionName.c_str(), current, current ? current->GetTypeName().c_str() : wxT("NULL")); #endif continue; } current = current->GetNext(); #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("In Function '%s', the next command is <%p><%s>\n"), functionName.c_str(), current, current ? current->GetTypeName().c_str() : wxT("NULL")); #endif } // Set ObjectMap from the last command to Validator in order to create // valid output wrappers (loj: 2008.11.12) validator->SetObjectMap(last->GetObjectMap()); #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT(" Now about to create %d output wrapper(s) to set results, objectsInitialized=%d\n"), outputNames.size(), objectsInitialized); #endif // create output wrappers and put into map GmatBase *obj; wrappersToDelete.clear(); for (unsigned int jj = 0; jj < outputNames.size(); jj++) { if (!(obj = FindObject(outputNames.at(jj)))) { wxString errMsg = wxT("Function: Output \"") + outputNames.at(jj); errMsg += wxT(" not found for function \"") + functionName + wxT("\""); throw FunctionException(errMsg); } wxString outName = outputNames.at(jj); ElementWrapper *outWrapper = validator->CreateElementWrapper(outName, false, false); #ifdef DEBUG_MORE_MEMORY MessageInterface::ShowMessage (wxT("+++ GmatFunction::Execute() *outWrapper = validator->") wxT("CreateElementWrapper(%s), <%p> '%s'\n"), outName.c_str(), outWrapper, outWrapper->GetDescription().c_str()); #endif outWrapper->SetRefObject(obj); // nested CallFunction crashes if old outWrappers are deleted here. (loj: 2008.11.24) // so collect here and delete when FunctionRunner completes. wrappersToDelete.push_back(outWrapper); // Set new outWrapper outputArgMap[outName] = outWrapper; #ifdef DEBUG_FUNCTION_EXEC // --------------------------------------------------- debug --- MessageInterface::ShowMessage(wxT("GmatFunction: Output wrapper created for %s\n"), (outputNames.at(jj)).c_str()); #endif // -------------------------------------------------------------- end debug --- } #ifdef DEBUG_FUNCTION_EXEC MessageInterface::ShowMessage (wxT("GmatFunction::Execute() exiting true for '%s'\n"), functionName.c_str()); #endif #ifdef DEBUG_TRACE ShowTrace(callCount, t1, wxT("GmatFunction::Execute() exiting"), true); #endif return true; }
//------------------------------------------------------------------------------ // bool Initialize() //------------------------------------------------------------------------------ bool GmatFunction::Initialize() { #ifdef DEBUG_TRACE static Integer callCount = 0; callCount++; clock_t t1 = clock(); ShowTrace(callCount, t1, wxT("GmatFunction::Initialize() entered")); #endif #ifdef DEBUG_FUNCTION_INIT MessageInterface::ShowMessage (wxT("======================================================================\n") wxT("GmatFunction::Initialize() entered for function '%s'\n"), functionName.c_str()); MessageInterface::ShowMessage(wxT(" and FCS is %s set.\n"), (fcs? wxT("correctly") : wxT("NOT"))); MessageInterface::ShowMessage(wxT(" Pointer for FCS is %p\n"), fcs); MessageInterface::ShowMessage(wxT(" First command in fcs is %s\n"), (fcs->GetTypeName()).c_str()); MessageInterface::ShowMessage(wxT(" internalCS is %p\n"), internalCoordSys); #endif if (!fcs) return false; Function::Initialize(); // Initialize the Validator - I think I need to do this each time - or do I? validator->SetFunction(this); validator->SetSolarSystem(solarSys); std::map<wxString, GmatBase *>::iterator omi; // add automatic objects such as sat.X to the FOS (well, actually, clones of them) for (omi = automaticObjectMap.begin(); omi != automaticObjectMap.end(); ++omi) { wxString autoObjName = omi->first; // if name not found, clone it and add to map (loj: 2008.12.15) if (objectStore->find(autoObjName) == objectStore->end()) { GmatBase *autoObj = (omi->second)->Clone(); #ifdef DEBUG_MEMORY MemoryTracker::Instance()->Add (autoObj, autoObjName, wxT("GmatFunction::Initialize()"), wxT("autoObj = (omi->second)->Clone()")); #endif #ifdef DEBUG_FUNCTION_INIT try { MessageInterface::ShowMessage (wxT(" autoObj->EvaluateReal() = %f\n"), autoObj->GetRealParameter(wxT("Value"))); } catch (BaseException &e) { MessageInterface::ShowMessage(e.GetFullMessage()); } #endif autoObj->SetIsLocal(true); objectStore->insert(std::make_pair(autoObjName, autoObj)); } } // first, send all the commands the object store, solar system, etc GmatCommand *current = fcs; while (current) { #ifdef DEBUG_FUNCTION_INIT if (!current) MessageInterface::ShowMessage(wxT("Current is NULL!!!\n")); else MessageInterface::ShowMessage(wxT(" =====> Current command is %s <%s>\n"), (current->GetTypeName()).c_str(), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str()); #endif current->SetObjectMap(objectStore); current->SetGlobalObjectMap(globalObjectStore); current->SetSolarSystem(solarSys); current->SetInternalCoordSystem(internalCoordSys); current->SetTransientForces(forces); #ifdef DEBUG_FUNCTION_INIT MessageInterface::ShowMessage (wxT(" Now about to set object map of type %s to Validator\n"), (current->GetTypeName()).c_str()); #endif // (Re)set object map on Validator (necessary because objects may have been added to the // Local Object Store or Global Object Store during initialization of previous commands) validatorStore.clear(); for (omi = objectStore->begin(); omi != objectStore->end(); ++omi) validatorStore.insert(std::make_pair(omi->first, omi->second)); for (omi = globalObjectStore->begin(); omi != globalObjectStore->end(); ++omi) validatorStore.insert(std::make_pair(omi->first, omi->second)); validator->SetObjectMap(&validatorStore); #ifdef DEBUG_FUNCTION_INIT MessageInterface::ShowMessage (wxT(" Now about to call Validator->ValidateCommand() of type %s\n"), current->GetTypeName().c_str()); #endif // Let's try to ValidateCommand here, this will validate the command // and create wrappers also if (!validator->ValidateCommand(current, false, 2)) { // get error message (loj: 2008.06.04) StringArray errList = validator->GetErrorList(); wxString msg; // Check for empty errList (loj: 2009.03.17) if (errList.empty()) msg = wxT("Error occurred"); else msg = errList[0]; throw FunctionException(msg + wxT(" in the function \"") + functionPath + wxT("\"")); } #ifdef DEBUG_FUNCTION_INIT MessageInterface::ShowMessage (wxT(" Now about to initialize command of type %s\n"), current->GetTypeName().c_str()); #endif // catch exception and add function name to message (loj: 2008.09.23) try { if (!(current->Initialize())) { #ifdef DEBUG_FUNCTION_INIT MessageInterface::ShowMessage (wxT("Exiting GmatFunction::Initialize for function '%s' with false\n"), functionName.c_str()); #endif return false; } } catch (BaseException &e) { throw FunctionException(wxT("Cannot continue due to ") + e.GetFullMessage() + wxT(" in the function \"") + functionPath + wxT("\"")); } // Check to see if the command needs a server startup (loj: 2008.07.25) if (current->NeedsServerStartup()) if (validator->StartMatlabServer(current) == false) throw FunctionException(wxT("Unable to start the server needed by the ") + (current->GetTypeName()) + wxT(" command")); current = current->GetNext(); } // Get automatic global object list and check if they are used in the function // command sequence so that when any global object is declared in the main script // but not used in the function, they can be ignored during function local object // initialization. (LOJ: 2009.12.18) BuildUnusedGlobalObjectList(); fcsFinalized = false; #ifdef DEBUG_FUNCTION_INIT MessageInterface::ShowMessage (wxT("GmatFunction::Initialize() exiting for function '%s' with true\n"), functionName.c_str()); #endif #ifdef DEBUG_TRACE ShowTrace(callCount, t1, wxT("GmatFunction::Initialize() exiting"), true); #endif return true; }