static rsRetVal addListener(instanceConf_t* iconf){ struct lstn_s* pData; DEFiRet; CHKmalloc(pData=(struct lstn_s*)MALLOC(sizeof(struct lstn_s))); pData->next = NULL; pData->pRuleset = iconf->pBindRuleset; /* Create the zeromq socket */ /* ------------------------ */ pData->sock = zsock_new(iconf->sockType); if (!pData->sock) { errmsg.LogError(0, RS_RET_NO_ERRCODE, "imczmq: new socket failed for endpoints: %s", iconf->sockEndpoints); ABORT_FINALIZE(RS_RET_NO_ERRCODE); } DBGPRINTF ("imczmq: created socket...\n"); /* Create the beacon actor if configured */ /* ------------------------------------- */ if((iconf->beacon != NULL) && (iconf->beaconPort > 0)) { DBGPRINTF ("imczmq: starting beacon actor...\n"); pData->beaconActor = zactor_new(zbeacon, NULL); if (!pData->beaconActor) { errmsg.LogError(0, RS_RET_NO_ERRCODE, "imczmq: could not create beacon service"); ABORT_FINALIZE (RS_RET_NO_ERRCODE); } zsock_send(pData->beaconActor, "si", "CONFIGURE", iconf->beaconPort); char *hostname = zstr_recv(pData->beaconActor); if (!*hostname) { errmsg.LogError(0, RS_RET_NO_ERRCODE, "imczmq: no UDP broadcasting available"); ABORT_FINALIZE (RS_RET_NO_ERRCODE); } zsock_send(pData->beaconActor, "sbi", "PUBLISH", pData->beaconActor, strlen(iconf->beacon)); DBGPRINTF ("omczmq: beacon is lit: hostname: '%s', port: '%d'...\n", hostname, iconf->beaconPort); } DBGPRINTF("imczmq: authtype is: %s\n", iconf->authType); if (iconf->authType != NULL) { /* CURVESERVER */ /* ----------- */ if (!strcmp(iconf->authType, "CURVESERVER")) { zsock_set_zap_domain(pData->sock, "global"); zsock_set_curve_server(pData->sock, 1); pData->serverCert = zcert_load(iconf->serverCertPath); if (!pData->serverCert) { errmsg.LogError(0, NO_ERRCODE, "could not load server cert"); ABORT_FINALIZE(RS_RET_ERR); } zcert_apply(pData->serverCert, pData->sock); zstr_sendx(authActor, "CURVE", iconf->clientCertPath, NULL); zsock_wait(authActor); DBGPRINTF("imczmq: CURVESERVER: serverCertPath: '%s'\n", iconf->serverCertPath); DBGPRINTF("mczmq: CURVESERVER: clientCertPath: '%s'\n", iconf->clientCertPath); } /* CURVECLIENT */ /* ----------- */ else if (!strcmp(iconf->authType, "CURVECLIENT")) { if (!strcmp(iconf->clientCertPath, "*")) { pData->clientCert = zcert_new(); } else { pData->clientCert = zcert_load(iconf->clientCertPath); } if (!pData->clientCert) { errmsg.LogError(0, NO_ERRCODE, "could not load client cert"); ABORT_FINALIZE(RS_RET_ERR); } zcert_apply(pData->clientCert, pData->sock); pData->serverCert = zcert_load(iconf->serverCertPath); if (!pData->serverCert) { errmsg.LogError(0, NO_ERRCODE, "could not load server cert"); ABORT_FINALIZE(RS_RET_ERR); } char *server_key = zcert_public_txt(pData->serverCert); zsock_set_curve_serverkey (pData->sock, server_key); DBGPRINTF("imczmq: CURVECLIENT: serverCertPath: '%s'\n", iconf->serverCertPath); DBGPRINTF("imczmq: CURVECLIENT: clientCertPath: '%s'\n", iconf->clientCertPath); DBGPRINTF("imczmq: CURVECLIENT: server_key: '%s'\n", server_key); } else { errmsg.LogError(0, NO_ERRCODE, "unrecognized auth type: '%s'", iconf->authType); ABORT_FINALIZE(RS_RET_ERR); } } /* subscribe to topics */ /* ------------------- */ if (iconf->sockType == ZMQ_SUB) { char topic[256], *list = iconf->topicList; while (list) { char *delimiter = strchr(list, ','); if (!delimiter) { delimiter = list + strlen (list); } if (delimiter - list > 255) { errmsg.LogError(0, NO_ERRCODE, "iconf->topicList must be under 256 characters"); ABORT_FINALIZE(RS_RET_ERR); } memcpy(topic, list, delimiter - list); topic[delimiter - list] = 0; zsock_set_subscribe(pData->sock, topic); if (*delimiter == 0) { break; } list = delimiter + 1; } } switch (iconf->sockType) { case ZMQ_SUB: iconf->serverish = false; break; case ZMQ_PULL: case ZMQ_ROUTER: iconf->serverish = true; break; } int rc = zsock_attach(pData->sock, (const char*)iconf->sockEndpoints, iconf->serverish); if (rc == -1) { errmsg.LogError(0, NO_ERRCODE, "zsock_attach to %s", iconf->sockEndpoints); ABORT_FINALIZE(RS_RET_ERR); } /* add this struct to the global */ /* ----------------------------- */ if(lcnfRoot == NULL) { lcnfRoot = pData; } if(lcnfLast == NULL) { lcnfLast = pData; } else { lcnfLast->next = pData; lcnfLast = pData; } finalize_it: RETiRet; }
/*=========================================================================== FUNCTION CallDemoApp_InitAppData DESCRIPTION This function initializes app specific data. PROTOTYPE: static boolean CallDemoApp_InitAppData(IApplet* pi); PARAMETERS: pi [in]: Pointer to the IApplet structure. DEPENDENCIES None. RETURN VALUE TRUE: If the app has app data is allocated and initialized successfully FALSE: Either app data could not be allocated or initialized SIDE EFFECTS None. ===========================================================================*/ static boolean CallDemoApp_InitAppData(IApplet* pi) { CallDemoApp * pMe = (CallDemoApp*)pi; int charHeight, pnAscent, pnDescent; AEEDeviceInfo di; int nErr; // Make sure the pointers we'll be using are valid if (pMe == NULL || pMe->a.m_pIShell == NULL) return FALSE; pMe->m_pIMenu = NULL; // Determine the amount of available screen space ZEROAT(&di); di.wStructSize = sizeof(di); ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&di); pMe->m_rc.dx = di.cxScreen; pMe->m_rc.dy = di.cyScreen; // Determine the height of a line of text charHeight = IDISPLAY_GetFontMetrics (pMe->a.m_pIDisplay, AEE_FONT_NORMAL, &pnAscent, &pnDescent); // Number of available lines equals the available screen // space divided by the height of a line, minus 3 for the // lines we always print at the top and bottom of the screen pMe->m_cMaxLine = (di.cyScreen / charHeight) - 3; pMe->m_pCallMgr = NULL; pMe->m_pOutgoingCall = NULL; pMe->m_pIncomingCall = NULL; nErr =ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_CALLMGR, (void**) &pMe->m_pCallMgr); DBGPRINTF("CreateInst AEECLSID_CALLMGR ret %d", nErr); if(nErr != AEE_SUCCESS) { return FALSE; } if(SUCCESS != ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_TELEPHONE, (void **) &pMe->m_pTelephone)) { return FALSE; } if(SUCCESS != ITELEPHONE_QueryInterface(pMe->m_pTelephone, AEEIID_MODEL, (void **) &pMe->m_pModel)) { return FALSE; } LISTENER_Init((ModelListener *)&pMe->m_lisPhone, MyPhoneListener, (void *) pMe); IMODEL_AddListener(pMe->m_pModel, (ModelListener *) &pMe->m_lisPhone); #ifdef EVENT_AUTO_GET pMe->m_UserAnswerEvent = ISHELL_RegisterEvent(pMe->a.m_pIShell, "user anwser event", NULL ); pMe->m_UserRedirectEvent = ISHELL_RegisterEvent(pMe->a.m_pIShell, "user redirect event", NULL ); #endif pMe->m_isDTMFItem = FALSE; pMe->m_isParty3Item= FALSE; pMe->m_isRedirectItem = FALSE; return TRUE; }
/*=========================================================================== FUNCTION SampleAppWizard_HandleEvent DESCRIPTION This is the EventHandler for this app. All events to this app are handled in this function. All APPs must supply an Event Handler. PROTOTYPE: boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam) PARAMETERS: pi: Pointer to the AEEApplet structure. This structure contains information specific to this applet. It was initialized during the AEEClsCreateInstance() function. ecode: Specifies the Event sent to this applet wParam, dwParam: Event specific data. DEPENDENCIES none RETURN VALUE TRUE: If the app has processed the event FALSE: If the app did not process the event SIDE EFFECTS none ===========================================================================*/ static boolean MemChecker_HandleEvent(MemChecker* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam) { #if 1 // for debugging if (EVT_POINTER_DOWN == eCode) { AEERect rc; int x, y; AEE_POINTER_GET_XY((char *)dwParam, &x, &y); SETAEERECT(&rc, x, y, 2, 2); IDisplay_FillRect(pMe->a.m_pIDisplay, &rc, RGB_BLACK); IDisplay_Update(pMe->a.m_pIDisplay); } #endif if (pMe->m_pIDesktopWindow && IDesktopWindow_HandleEvent(pMe->m_pIDesktopWindow, eCode, wParam, dwParam)) { return TRUE; } switch (eCode) { // App is told it is starting up case EVT_APP_START: DBGPRINTF("##MemChecker_HandleEvent: EVT_APP_START ##############"); if (pMe->m_bBackground) { pMe->m_bBackground = FALSE; IContainer_Invalidate((IContainer *)pMe->m_pIDesktopWindow, NULL, NULL); return TRUE; } ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_APPLETCTL, (void **)&pMe->m_pIAppletCtl); IniFileParser_LoadFile(pMe->a.m_pIShell, MemChecker_ParseLineCB, pMe); // ClassFactory & DestopWindow pMe->m_pIClassFactory = XClassFactory_New(); IClassFactory_CreateInstance(pMe->m_pIClassFactory, XCLSID_DesktopWindow, (void **)&pMe->m_pIDesktopWindow); IWidget_SetName((IWidget*)pMe->m_pIDesktopWindow, "DesktopWindow"); IDesktopWindow_SetDisplay(pMe->m_pIDesktopWindow, pMe->a.m_pIDisplay); IWidget_SetRectEx((IWidget*)pMe->m_pIDesktopWindow, 0, 0, pMe->DeviceInfo.cxScreen, pMe->DeviceInfo.cyScreen); MemChecker_CreateMainMenu(pMe); return(TRUE); // App is told it is exiting case EVT_APP_STOP: DBGPRINTF("##MemChecker_HandleEvent: EVT_APP_STOP ###################"); if (pMe->m_bBackground) { *(boolean *)dwParam = FALSE; return TRUE; } CALLBACK_Cancel(&pMe->m_cbModUnload); CALLBACK_Cancel(&pMe->m_cbWaitForAppStartup); MemHook_Uninstall(); RELEASEIF(pMe->m_pIClassFactory); RELEASEIF(pMe->m_pIDesktopWindow); RELEASEIF(pMe->m_pIAppletCtl); return(TRUE); // App is being suspended case EVT_APP_SUSPEND: DBGPRINTF("##MemChecker_HandleEvent: EVT_APP_SUSPEND ################"); return(TRUE); // App is being resumed case EVT_APP_RESUME: DBGPRINTF("##MemChecker_HandleEvent: EVT_APP_RESUME #################"); IContainer_Invalidate((IContainer *)pMe->m_pIDesktopWindow, NULL, NULL); return(TRUE); // An SMS message has arrived for this app. Message is in the dwParam above as (char *) // sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World case EVT_APP_MESSAGE: // Add your code here... return(TRUE); // If nothing fits up to this point then we'll just break out default: break; } return FALSE; }
/*=========================================================================== ===========================================================================*/ static void SamplePosDet_GetGPSInfo_Paint( CSamplePosDet *pMe, GetGPSInfo_PaintRegions rgn ) { struct _GetGPSInfo *pGetGPSInfo = SamplePosDet_GetScreenData( pMe ); if( rgn == GETGPSINFO_PAINT_ALL ) { IDISPLAY_ClearScreen( pMe->theApp.m_pIDisplay ); SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_LEFT, "GetGPSInfo" ); if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_ONE_SHOT ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "One Shot" ); } else if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_TRACK_LOCAL ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "Track L" ); } else if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_TRACK_NETWORK ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "Track N" ); } else if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_TRACK_AUTO ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "Track A" ); } } if( rgn == GETGPSINFO_PAINT_FIXCOUNT || rgn == GETGPSINFO_PAINT_ALL ) { SamplePosDet_Printf( pMe, 1, 4, AEE_FONT_NORMAL, IDF_ALIGN_LEFT, "Failed : %d", pGetGPSInfo->dwFail+pGetGPSInfo->dwTimeout ); SamplePosDet_Printf( pMe, 1, 4, AEE_FONT_NORMAL, IDF_ALIGN_RIGHT, "Timeout : %d", pGetGPSInfo->dwTimeout ); } if( rgn == GETGPSINFO_PAINT_FIXDATA || rgn == GETGPSINFO_PAINT_ALL ) { #define MAXTEXTLEN 22 AECHAR wcText[MAXTEXTLEN]; char latlonStr[MAXTEXTLEN]; SamplePosDet_Printf( pMe, 2, 4, AEE_FONT_NORMAL, IDF_ALIGN_LEFT, "Fixes : %d", pGetGPSInfo->dwFixNumber ); FLOATTOWSTR( pGetGPSInfo->theInfo.lat, wcText, MAXTEXTLEN * sizeof(AECHAR) ); WSTR_TO_STR( wcText, latlonStr, MAXTEXTLEN ); SamplePosDet_Printf( pMe, 3, 4, AEE_FONT_BOLD, IDF_ALIGN_CENTER|IDF_RECT_FILL, "%s d", latlonStr ); FLOATTOWSTR( pGetGPSInfo->theInfo.lon, wcText, MAXTEXTLEN * sizeof(AECHAR) ); WSTR_TO_STR( wcText, latlonStr, MAXTEXTLEN ); SamplePosDet_Printf( pMe, 4, 4, AEE_FONT_BOLD, IDF_ALIGN_CENTER|IDF_RECT_FILL, "%s d", latlonStr ); SamplePosDet_Printf( pMe, 5, 4, AEE_FONT_BOLD, IDF_ALIGN_RIGHT|IDF_RECT_FILL, "%d m", pGetGPSInfo->theInfo.height ); { double fv; fv = FASSIGN_INT( pGetGPSInfo->dwFixDuration ); if( pGetGPSInfo->dwFixNumber ) { fv = FDIV(fv, pGetGPSInfo->dwFixNumber); } FLOATTOWSTR( fv, wcText, MAXTEXTLEN * sizeof(AECHAR) ); WSTR_TO_STR( wcText, latlonStr, MAXTEXTLEN ); SamplePosDet_Printf( pMe, 6, 4, AEE_FONT_BOLD, IDF_ALIGN_RIGHT|IDF_RECT_FILL, "Avg %ss", latlonStr ); } } if( rgn == GETGPSINFO_PAINT_ERROR ) { SamplePosDet_Printf( pMe, 7, 4, AEE_FONT_BOLD, IDF_ALIGN_BOTTOM|IDF_ALIGN_CENTER|IDF_TEXT_INVERTED, "ABORTED 0x%x", pGetGPSInfo->theInfo.nErr ); } if( rgn == GETGPSINFO_PAINT_FIXANIM || rgn == GETGPSINFO_PAINT_ALL ) { SamplePosDet_Printf( pMe, 7, 4, AEE_FONT_NORMAL, IDF_ALIGN_BOTTOM|IDF_ALIGN_CENTER|IDF_RECT_FILL, ".....%d.....", pGetGPSInfo->wProgress ); } //if (FABS(pGetGPSInfo->theInfo.lat) > 0) { Coordinate c1, c2; double dis = 0; char szDis[64]; AECHAR wcharbuf[32]; //shanghai 31.1774276, 121.5272106 c1.lat = 31.1774276; c1.lon = 121.5272106; //beijing 39.911954, 116.377817 c2.lat = 39.911954; c2.lon = 116.377817; //shenzhen 22.543847, 113.912316 //c1.lat = 22.543847; //c1.lon = 113.912316; c1.lat = pGetGPSInfo->theInfo.lat; c1.lon = pGetGPSInfo->theInfo.lon; dis = Track_Calc_Distance(c1.lat, c1.lon, c2.lat, c2.lon); MEMSET(szDis,0,sizeof(szDis)); FLOATTOWSTR(dis, wcharbuf, 32); WSTRTOSTR(wcharbuf,szDis, 64); DBGPRINTF("Track_cbOrientInfo dis:%s", szDis); SamplePosDet_Printf( pMe, 7, 4, AEE_FONT_BOLD, IDF_ALIGN_LEFT|IDF_RECT_FILL, "%s m", szDis ); } { uint16 d1 = 0; uint8 d2 = 0; d1 = ((uint16)(pGetGPSInfo->theInfo.wAzimuth & (~0x3f)))>>6; d2 = (uint8)(pGetGPSInfo->theInfo.wAzimuth & 0x3f); SamplePosDet_Printf( pMe, 8, 4, AEE_FONT_BOLD, IDF_ALIGN_LEFT|IDF_RECT_FILL, "Head %d.%d", d1, d2 ); SamplePosDet_Printf( pMe, 9, 4, AEE_FONT_BOLD, IDF_ALIGN_LEFT|IDF_RECT_FILL, "Heading %d", pGetGPSInfo->theInfo.heading); } }
static void MyPhoneListener(CallDemoApp *pMe, ModelEvent *pEvent) { char incom_info[100]; AEETCallEvent * pCallEvent = (AEETCallEvent*) pEvent; if (pCallEvent && (AEET_EVENT_CALL_INCOM == pCallEvent->evCode)) { AEETCallEventData * pTCallEventData = (AEETCallEventData *)&(pCallEvent->call); AEETCalls calls = {0}; int iResult = EFAILED; iResult = ITELEPHONE_GetCalls(pMe->m_pTelephone, &calls, sizeof(AEETCalls)); if ((iResult != SUCCESS) || (calls.dwCount == 0)) { DBGPRINTF("ITELEPHONE_GetCalls ret: %d, count=%d", iResult, calls.dwCount); return; } DBGPRINTF("ITELEPHONE_GetCalls AEECallDesc=%d", calls.calls[0]); ICALLMGR_GetCall(pMe->m_pCallMgr, calls.calls[0], &pMe->m_pIncomingCall); SPRINTF(incom_info, "Rx: CALL INCOM EVENT with num: %s", pTCallEventData->number.buf); WriteLine(pMe, incom_info, NULL, FALSE); DBGPRINTF("Rx: CALL INCOM EVENT with num: %s", pTCallEventData->number.buf); if(pMe->m_isRedirectItem) { #ifdef EVENT_AUTO_GET ISHELL_PostEvent(pMe->a.m_pIShell, AEECLSID_CALLDEMO, pMe->m_UserRedirectEvent, 0, 0); #else ISHELL_PostEvent(pMe->a.m_pIShell, AEECLSID_CALLDEMO, EVT_MY_REDIRECT, 0, 0); #endif } else { DBGPRINTF("handler of call incoming by answer"); if (pMe->m_pIncomingCall) { int nError; nError = ICALL_Answer(pMe->m_pIncomingCall); if (SUCCESS != nError) { DBGPRINTF("ICALL_Answer failed ret=%d", nError); } else { DBGPRINTF("ICALL_Answer -->"); WriteLine(pMe, "ICALL_Answer -->", NULL, FALSE); } } #if 0 #ifdef EVENT_AUTO_GET ISHELL_PostEvent(pMe->a.m_pIShell, AEECLSID_CALLDEMO, pMe->m_UserAnswerEvent, 0, 0); #else ISHELL_PostEvent(pMe->a.m_pIShell, AEECLSID_CALLDEMO, EVT_MY_ANSWER, 0, 0); #endif #endif } } if (pCallEvent && (AEET_EVENT_CALL_CALLER_ID == pCallEvent->evCode)) { AEETCallEventData * pTCallEventData = (AEETCallEventData *)&(pCallEvent->call); SPRINTF(incom_info, "Rx: CALL INCOM EVENT with num: %s", pTCallEventData->number.buf); WriteLine(pMe, incom_info, NULL, FALSE); DBGPRINTF("Rx: CALLER ID : %s", pTCallEventData->number.buf); } if (pCallEvent && (AEET_EVENT_CALL_ANSWER == pCallEvent->evCode)) { DBGPRINTF("Rx: AEET_EVENT_CALL_ANSWER"); } if (pCallEvent && (AEET_EVENT_CALL_CONNECT == pCallEvent->evCode)) { DBGPRINTF("Rx: AEET_EVENT_CALL_CONNECT"); } if (pCallEvent && (AEET_EVENT_CALL_END == pCallEvent->evCode)) { if(pMe->m_isRedirectItem) { pMe->m_isRedirectItem = FALSE; } DBGPRINTF("Rx: AEET_EVENT_CALL_END"); } }
STDMETHODIMP_(ULONG) CClassFactory::AddRef() { DBGPRINTF(("CClassFactory::AddRef()\n")); return InterlockedIncrement(&_cntRef); }
STDMETHODIMP CClassFactory::LockServer(BOOL bLock) { DBGPRINTF(("CClassFactory::LockServer()\n")); return S_OK; }
void test_ONFI_ReadPage_ShouldWork(void) { unsigned const int data_bytes = kKLEN_DATA << 1; unsigned const int data_pack = kNLEN_DATA << 1; unsigned const int aux_bytes = kKLEN_AUX << 1; unsigned const int aux_pack = kNLEN_AUX << 1; setup_page_buff(); setup_NFC_FTL(); TEST_ASSERT_EQUAL_HEX32(0x40, NFC_REG[NFC_DMARFF_SLOT]); //---------------------------------------------------------------- // Set up DMAR NFC_REG[NFC_DMAR_ENDCNT] = (data_bytes / 8) - 1; //---------------------------------------------------------------- // Enable Paths NFC_REG[NFC_ENABLE] |= NFC_ENABLE_DMAR | NFC_ENABLE_F2H | NFC_ENABLE_BCHD; ONFI_ReadPage(0x010004, 0x0); ONFI_dma_read((data_pack / 2), 0); ONFI_ChangeReadColumn(0x010D); ONFI_dma_read((aux_pack / 2), ONFI_AUX_DATA); receive(page_buff, data_bytes); //---------------------------------------------------------------- // Check FLASH data DBGPRINTF("ReadPage_via_RSDM1:\n"); for (int i = 0; i < 2; i++) DBGPRINTF("%08x, ", page_buff[i]); DBGPRINTF("\n"); for (int i = 0; i < 4; i++) DBGPRINTF("%08x, ", page_buff[(data_bytes / 4) - 2 + i]); DBGPRINTF("\n"); //---------------------------------------------------------------- // Disable Paths NFC_REG[NFC_ENABLE] &= (~NFC_ENABLE_DMAR); // Writing FTLRAM //---------------------------------------------------------------- // Enable Paths NFC_REG[NFC_ENABLE] |= NFC_ENABLE_FTLWR; //---------------------------------------------------------------- // wait for FTL_DONE while ((NFC_REG[NFC_STATE] >> 24) != 1) {} //---------------------------------------------------------------- // Disable Paths NFC_REG[NFC_ENABLE] &= (~NFC_ENABLE_FTLWR); NFC_DMARFFRD[0] = 2; // pop NFC_DMARFFRD[0] = 0; // lower DOWRD DBGPRINTF("%x, ", NFC_DMAWFFRD[0]); NFC_DMARFFRD[0] = 1; // upper DWORD DBGPRINTF("%x, ", NFC_DMAWFFRD[0]); TEST_ASSERT_EQUAL_HEX32(0x40, NFC_REG[NFC_DMARFF_SLOT]); }
int main( int argc, char *argv[] ) { MPI_Info infos[MAX_INFOS]; char key[64], value[64]; int errs = 0; int i, j; MTest_Init( &argc, &argv ); /* We create max_info items, then delete the middle third of them, then recreate them, then check them, then delete them all. This checks that the MPICH algorithm for handling large numbers of items works correctly; other MPI implementations should also be able to handle this */ /* Create them all */ for (i=0; i<MAX_INFOS; i++) { MPI_Info_create( &infos[i] ); DBGPRINTF( ( "Info handle is %x\n", infos[i] ) ); for (j=0; j<info_list; j++) { sprintf( key, "key%d-%d", i, j ); sprintf( value, "value%d-%d", i, j ); DBGPRINTF( ( "Creating key/value %s=%s\n", key, value )); MPI_Info_set( infos[i], key, value ); } #ifdef DBG { int nkeys; MPI_Info_get_nkeys( infos[0], &nkeys ); if (nkeys != info_list) { printf( "infos[0] changed at %d info\n", i );} } #endif } /* Delete the middle set */ for (i=MAX_INFOS/3; i<(2*MAX_INFOS/3); i++) { MPI_Info_free( &infos[i] ); } /* Recreate the middle set */ for (i=MAX_INFOS/3; i<(2*MAX_INFOS/3); i++) { MPI_Info_create( &infos[i] ); DBGPRINTF( ( "Info handle is %x\n", infos[i] ) ); for (j=0; j<info_list; j++) { sprintf( key, "key%d-%d", i, j ); sprintf( value, "value%d-%d", i, j ); DBGPRINTF( ( "Creating key/value %s=%s\n", key, value )); MPI_Info_set( infos[i], key, value ); } } /* Now, check that they are still valid */ for (i=0; i<MAX_INFOS; i++) { int nkeys; /*printf( "info = %x\n", infos[i] ); print_handle( infos[i] ); printf( "\n" );*/ MPI_Info_get_nkeys( infos[i], &nkeys ); if (nkeys != info_list) { errs++; if (errs < MAX_ERRORS) { printf( "Wrong number of keys for info %d; got %d, should be %d\n", i, nkeys, info_list ); } } for (j=0; j<nkeys; j++) { char keystr[64]; char valstr[64]; int flag; MPI_Info_get_nthkey( infos[i], j, key ); sprintf( keystr, "key%d-%d", i, j ); if (strcmp( keystr, key ) != 0) { errs++; if (errs < MAX_ERRORS) { printf( "Wrong key for info %d; got %s expected %s\n", i, key, keystr ); } continue; } MPI_Info_get( infos[i], key, 64, value, &flag ); if (!flag) { errs++; if (errs < MAX_ERRORS) { printf( "Get failed to return value for info %d\n", i ); } continue; } sprintf( valstr, "value%d-%d", i, j ); if (strcmp( valstr, value ) != 0) { errs++; if (errs < MAX_ERRORS) { printf( "Wrong value for info %d; got %s expected %s\n", i, value, valstr ); } } } } for (i=0; i<MAX_INFOS; i++) { MPI_Info_free( &infos[i] ); } MTest_Finalize( errs ); MPI_Finalize( ); return 0; }
static rsRetVal addListener(instanceConf_t* iconf){ DEFiRet; DBGPRINTF("imczmq: addListener called..\n"); struct listener_t* pData; CHKmalloc(pData=(struct listener_t*)MALLOC(sizeof(struct listener_t))); pData->ruleset = iconf->pBindRuleset; pData->sock = zsock_new(iconf->sockType); if(!pData->sock) { errmsg.LogError(0, RS_RET_NO_ERRCODE, "imczmq: new socket failed for endpoints: %s", iconf->sockEndpoints); ABORT_FINALIZE(RS_RET_NO_ERRCODE); } DBGPRINTF("imczmq: created socket of type %d..\n", iconf->sockType); if(runModConf->authType) { if(!strcmp(runModConf->authType, "CURVESERVER")) { DBGPRINTF("imczmq: we are a CURVESERVER\n"); zcert_t *serverCert = zcert_load(runModConf->serverCertPath); if(!serverCert) { errmsg.LogError(0, NO_ERRCODE, "could not load cert %s", runModConf->serverCertPath); ABORT_FINALIZE(RS_RET_ERR); } zsock_set_zap_domain(pData->sock, "global"); zsock_set_curve_server(pData->sock, 1); zcert_apply(serverCert, pData->sock); zcert_destroy(&serverCert); } else if(!strcmp(runModConf->authType, "CURVECLIENT")) { DBGPRINTF("imczmq: we are a CURVECLIENT\n"); zcert_t *serverCert = zcert_load(runModConf->serverCertPath); if(!serverCert) { errmsg.LogError(0, NO_ERRCODE, "could not load cert %s", runModConf->serverCertPath); ABORT_FINALIZE(RS_RET_ERR); } const char *server_key = zcert_public_txt(serverCert); zcert_destroy(&serverCert); zsock_set_curve_serverkey(pData->sock, server_key); zcert_t *clientCert = zcert_load(runModConf->clientCertPath); if(!clientCert) { errmsg.LogError(0, NO_ERRCODE, "could not load cert %s", runModConf->clientCertPath); ABORT_FINALIZE(RS_RET_ERR); } zcert_apply(clientCert, pData->sock); zcert_destroy(&clientCert); } } switch(iconf->sockType) { case ZMQ_SUB: #if defined(ZMQ_DISH) case ZMQ_DISH: #endif iconf->serverish = true; break; case ZMQ_PULL: #if defined(ZMQ_GATHER) case ZMQ_GATHER: #endif case ZMQ_ROUTER: #if defined(ZMQ_SERVER) case ZMQ_SERVER: #endif iconf->serverish = true; break; } if(iconf->topics) { char topic[256]; while(*iconf->topics) { char *delimiter = strchr(iconf->topics, ','); if(!delimiter) { delimiter = iconf->topics + strlen(iconf->topics); } memcpy (topic, iconf->topics, delimiter - iconf->topics); topic[delimiter-iconf->topics] = 0; DBGPRINTF("imczmq: subscribing to %s\n", topic); if(iconf->sockType == ZMQ_SUB) { zsock_set_subscribe (pData->sock, topic); } #if defined(ZMQ_DISH) else if(iconf->sockType == ZMQ_DISH) { int rc = zsock_join (pData->sock, topic); if(rc != 0) { errmsg.LogError(0, NO_ERRCODE, "could not join group %s", topic); ABORT_FINALIZE(RS_RET_ERR); } } #endif if(*delimiter == 0) { break; } iconf->topics = delimiter + 1; } } int rc = zsock_attach(pData->sock, (const char*)iconf->sockEndpoints, iconf->serverish); if (rc == -1) { errmsg.LogError(0, NO_ERRCODE, "zsock_attach to %s failed", iconf->sockEndpoints); ABORT_FINALIZE(RS_RET_ERR); } DBGPRINTF("imczmq: attached socket to %s\n", iconf->sockEndpoints); rc = zlist_append(listenerList, (void *)pData); if(rc != 0) { errmsg.LogError(0, NO_ERRCODE, "could not append listener"); ABORT_FINALIZE(RS_RET_ERR); } finalize_it: RETiRet; }
static rsRetVal rcvData(){ DEFiRet; if(!listenerList) { listenerList = zlist_new(); if(!listenerList) { errmsg.LogError(0, NO_ERRCODE, "could not allocate list"); ABORT_FINALIZE(RS_RET_ERR); } } zactor_t *authActor; zcert_t *serverCert; if(runModConf->authenticator == 1) { authActor = zactor_new(zauth, NULL); zstr_sendx(authActor, "CURVE", runModConf->clientCertPath, NULL); zsock_wait(authActor); } instanceConf_t *inst; for(inst = runModConf->root; inst != NULL; inst=inst->next) { CHKiRet(addListener(inst)); } zpoller_t *poller = zpoller_new(NULL); if(!poller) { errmsg.LogError(0, NO_ERRCODE, "could not create poller"); ABORT_FINALIZE(RS_RET_ERR); } DBGPRINTF("imczmq: created poller\n"); struct listener_t *pData; pData = zlist_first(listenerList); if(!pData) { errmsg.LogError(0, NO_ERRCODE, "imczmq: no listeners were " "started, input not activated.\n"); ABORT_FINALIZE(RS_RET_NO_RUN); } while(pData) { int rc = zpoller_add(poller, pData->sock); if(rc != 0) { errmsg.LogError(0, NO_ERRCODE, "imczmq: could not add " "socket to poller, input not activated.\n"); ABORT_FINALIZE(RS_RET_NO_RUN); } pData = zlist_next(listenerList); } zframe_t *frame; zsock_t *which = (zsock_t *)zpoller_wait(poller, -1); while(which) { if (zpoller_terminated(poller)) { break; } pData = zlist_first(listenerList); while(pData->sock != which) { pData = zlist_next(listenerList); } if(which == pData->sock) { DBGPRINTF("imczmq: found matching socket\n"); } frame = zframe_recv(which); char *buf = zframe_strdup(frame); if(buf == NULL) { DBGPRINTF("imczmq: null buffer\n"); continue; } smsg_t *pMsg; if(msgConstruct(&pMsg) == RS_RET_OK) { MsgSetRawMsg(pMsg, buf, strlen(buf)); MsgSetInputName(pMsg, s_namep); MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName())); MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp()); MsgSetRcvFromIP(pMsg, glbl.GetLocalHostIP()); MsgSetMSGoffs(pMsg, 0); MsgSetFlowControlType(pMsg, eFLOWCTL_NO_DELAY); MsgSetRuleset(pMsg, pData->ruleset); pMsg->msgFlags = NEEDS_PARSING | PARSE_HOSTNAME; submitMsg2(pMsg); } free(buf); which = (zsock_t *)zpoller_wait(poller, -1); } finalize_it: zframe_destroy(&frame); zpoller_destroy(&poller); pData = zlist_first(listenerList); while(pData) { zsock_destroy(&pData->sock); free(pData->ruleset); pData = zlist_next(listenerList); } zlist_destroy(&listenerList); zactor_destroy(&authActor); zcert_destroy(&serverCert); RETiRet; }
/* This functions looks at the given message and checks if it matches the * provided filter condition. */ static rsRetVal shouldProcessThisMessage(rule_t *pRule, msg_t *pMsg, int *bProcessMsg) { DEFiRet; unsigned short pbMustBeFreed; uchar *pszPropVal; int bRet = 0; size_t propLen; vm_t *pVM = NULL; var_t *pResult = NULL; ISOBJ_TYPE_assert(pRule, rule); assert(pMsg != NULL); /* we first have a look at the global, BSD-style block filters (for tag * and host). Only if they match, we evaluate the actual filter. * rgerhards, 2005-10-18 */ if(pRule->eHostnameCmpMode == HN_NO_COMP) { /* EMPTY BY INTENSION - we check this value first, because * it is the one most often used, so this saves us time! */ } else if(pRule->eHostnameCmpMode == HN_COMP_MATCH) { if(rsCStrSzStrCmp(pRule->pCSHostnameComp, (uchar*) getHOSTNAME(pMsg), getHOSTNAMELen(pMsg))) { /* not equal, so we are already done... */ dbgprintf("hostname filter '+%s' does not match '%s'\n", rsCStrGetSzStrNoNULL(pRule->pCSHostnameComp), getHOSTNAME(pMsg)); FINALIZE; } } else { /* must be -hostname */ if(!rsCStrSzStrCmp(pRule->pCSHostnameComp, (uchar*) getHOSTNAME(pMsg), getHOSTNAMELen(pMsg))) { /* not equal, so we are already done... */ dbgprintf("hostname filter '-%s' does not match '%s'\n", rsCStrGetSzStrNoNULL(pRule->pCSHostnameComp), getHOSTNAME(pMsg)); FINALIZE; } } if(pRule->pCSProgNameComp != NULL) { int bInv = 0, bEqv = 0, offset = 0; if(*(rsCStrGetSzStrNoNULL(pRule->pCSProgNameComp)) == '-') { if(*(rsCStrGetSzStrNoNULL(pRule->pCSProgNameComp) + 1) == '-') offset = 1; else { bInv = 1; offset = 1; } } if(!rsCStrOffsetSzStrCmp(pRule->pCSProgNameComp, offset, (uchar*) getProgramName(pMsg, LOCK_MUTEX), getProgramNameLen(pMsg, LOCK_MUTEX))) bEqv = 1; if((!bEqv && !bInv) || (bEqv && bInv)) { /* not equal or inverted selection, so we are already done... */ DBGPRINTF("programname filter '%s' does not match '%s'\n", rsCStrGetSzStrNoNULL(pRule->pCSProgNameComp), getProgramName(pMsg, LOCK_MUTEX)); FINALIZE; } } /* done with the BSD-style block filters */ if(pRule->f_filter_type == FILTER_PRI) { /* skip messages that are incorrect priority */ dbgprintf("testing filter, f_pmask %d\n", pRule->f_filterData.f_pmask[pMsg->iFacility]); if ( (pRule->f_filterData.f_pmask[pMsg->iFacility] == TABLE_NOPRI) || \ ((pRule->f_filterData.f_pmask[pMsg->iFacility] & (1<<pMsg->iSeverity)) == 0) ) bRet = 0; else bRet = 1; } else if(pRule->f_filter_type == FILTER_EXPR) { CHKiRet(vm.Construct(&pVM)); CHKiRet(vm.ConstructFinalize(pVM)); CHKiRet(vm.SetMsg(pVM, pMsg)); CHKiRet(vm.ExecProg(pVM, pRule->f_filterData.f_expr->pVmprg)); CHKiRet(vm.PopBoolFromStack(pVM, &pResult)); dbgprintf("result of expression evaluation: %lld\n", pResult->val.num); /* VM is destructed on function exit */ bRet = (pResult->val.num) ? 1 : 0; } else { assert(pRule->f_filter_type == FILTER_PROP); /* assert() just in case... */ pszPropVal = MsgGetProp(pMsg, NULL, pRule->f_filterData.prop.propID, &propLen, &pbMustBeFreed); /* Now do the compares (short list currently ;)) */ switch(pRule->f_filterData.prop.operation ) { case FIOP_CONTAINS: if(rsCStrLocateInSzStr(pRule->f_filterData.prop.pCSCompValue, (uchar*) pszPropVal) != -1) bRet = 1; break; case FIOP_ISEQUAL: if(rsCStrSzStrCmp(pRule->f_filterData.prop.pCSCompValue, pszPropVal, ustrlen(pszPropVal)) == 0) bRet = 1; /* process message! */ break; case FIOP_STARTSWITH: if(rsCStrSzStrStartsWithCStr(pRule->f_filterData.prop.pCSCompValue, pszPropVal, ustrlen(pszPropVal)) == 0) bRet = 1; /* process message! */ break; case FIOP_REGEX: if(rsCStrSzStrMatchRegex(pRule->f_filterData.prop.pCSCompValue, (unsigned char*) pszPropVal, 0, &pRule->f_filterData.prop.regex_cache) == RS_RET_OK) bRet = 1; break; case FIOP_EREREGEX: if(rsCStrSzStrMatchRegex(pRule->f_filterData.prop.pCSCompValue, (unsigned char*) pszPropVal, 1, &pRule->f_filterData.prop.regex_cache) == RS_RET_OK) bRet = 1; break; default: /* here, it handles NOP (for performance reasons) */ assert(pRule->f_filterData.prop.operation == FIOP_NOP); bRet = 1; /* as good as any other default ;) */ break; } /* now check if the value must be negated */ if(pRule->f_filterData.prop.isNegated) bRet = (bRet == 1) ? 0 : 1; if(Debug) { dbgprintf("Filter: check for property '%s' (value '%s') ", propIDToName(pRule->f_filterData.prop.propID), pszPropVal); if(pRule->f_filterData.prop.isNegated) dbgprintf("NOT "); dbgprintf("%s '%s': %s\n", getFIOPName(pRule->f_filterData.prop.operation), rsCStrGetSzStrNoNULL(pRule->f_filterData.prop.pCSCompValue), bRet ? "TRUE" : "FALSE"); } /* cleanup */ if(pbMustBeFreed) free(pszPropVal); } finalize_it: /* destruct in any case, not just on error, but it makes error handling much easier */ if(pVM != NULL) vm.Destruct(&pVM); if(pResult != NULL) var.Destruct(&pResult); *bProcessMsg = bRet; RETiRet; }
int sci_conmin(char * fname) { int n_x, m_x, * pi_x = NULL; double * x = NULL; // Input - X + ndv int fobj_lhs, fobj_rhs, l_fobj; // Input - f_obj int gobj_lhs, gobj_rhs, l_gobj; // Input - g_obj + ncon int n_vub, m_vub, * pi_vub = NULL; double * vub = NULL; // Input - VUB + NSIDE = 1 if vub and / or vlb are present int n_vlb, m_vlb, * pi_vlb = NULL; double * vlb = NULL; // Input - VLB int n_itmax, m_itmax, * pi_itmax = NULL; double * itmax = NULL; // Input - ITMAX int n_ncon, m_ncon, * pi_ncon = NULL; double * ncon = NULL; // Input - NCON // Temporary variables for the call to objective function and constraints int n_x1_tmp = 0, m_x1_tmp = 0; double * x1_tmp = NULL; int n_x2_tmp = 0, m_x2_tmp = 0; double * x2_tmp = NULL; int n_x3_tmp = 0, m_x3_tmp = 0; double * x3_tmp = NULL; int n_fobj_tmp = 0, m_fobj_tmp = 0, * pi_fobj_tmp = NULL; double * fobj_tmp = NULL; int n_dfobj_tmp = 0, m_dfobj_tmp = 0, * pi_dfobj_tmp = NULL; double * dfobj_tmp = NULL; int n_gobj_tmp = 0, m_gobj_tmp = 0, * pi_gobj_tmp = NULL; double * gobj_tmp = NULL; int n_dgobj_tmp = 0, m_dgobj_tmp = 0, * pi_dgobj_tmp = NULL; double * dgobj_tmp = NULL; int n_ic = 0, m_ic = 0, * pi_ic = NULL; double * ic = NULL; int * ic_int = NULL; // Output variables int n_x_opt = 0, m_x_opt = 0; double * x_opt = NULL; // Output int n_f_opt = 0, m_f_opt = 0; double * f_opt = NULL; // Output - optional int n_df_opt = 0, m_df_opt = 0; double * df_opt = NULL; // Output - optional int n_g_opt = 0, m_g_opt = 0; double * g_opt = NULL; // Output - optional int n_dg_opt = 0, m_dg_opt = 0; double * dg_opt = NULL; // Output - optional int n_ic_res = 0, m_ic_res = 0; double * ic_opt = NULL; // Output - optional int n1,n2,n3,n4,n5; int ibegin; // To be used in SciFunction int i,j; int tmp_int, tmp_int_2, tmp_res; double tmp_dbl; int * pi_param = NULL; int * pIsc = NULL; double * pScal = NULL; int szIsc = 0, szScal = 0; int Isc_mallocated = 0, Scal_mallocated = 0; int nbvars_old = Nbvars; double * G = NULL; double * A = NULL; double * S = NULL; double * G1 = NULL; double * G2 = NULL; double * B = NULL; double * C = NULL; double * DF = NULL; int * MS1 = NULL; SciErr _SciErr; // Order of the parameters: // x0 // fobj // gobj // ncon // nacmx // vub // vlb // itmax // isc // scal // nscal // nfdg // icndir // fdch // fdchm // ct // ctmin // ctl // ctlmin // theta // delfun // dabfun // linobj // itrm // alphax // abobj1 // infog // info // iprint #ifdef DEBUG DBGPRINTF("conmin_optim: Lhs = %d Rhs = %d\n",Lhs,Rhs); #endif if (Rhs<LAST_PARAM) { Scierror(999,"%s: %d parameters are required\n", fname, LAST_PARAM); return 0; } /* End If */ //////////////////////// // Get the parameters // //////////////////////// _SciErr = getVarAddressFromPosition(pvApiCtx, X0_IN, &pi_x); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_x, &n_x, &m_x, &x); CONMIN_ERROR; tmp_int = n_x*m_x; C2F(set_ndv)(&tmp_int); GetRhsVar(FOBJ_IN, EXTERNAL_DATATYPE, &fobj_lhs, &fobj_rhs, &l_fobj); GetRhsVar(GOBJ_IN, EXTERNAL_DATATYPE, &gobj_lhs, &gobj_rhs, &l_gobj); ///////////////////////////////////////////// // Initialization of some "size" variables // ///////////////////////////////////////////// _SciErr = getVarAddressFromPosition(pvApiCtx, NCON_IN, &pi_ncon); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_ncon, &n_ncon, &m_ncon, &ncon); CONMIN_ERROR; tmp_int = (int)ncon[0]; C2F(set_ncon)(&tmp_int); _SciErr = getVarAddressFromPosition(pvApiCtx, VUB_IN, &pi_vub); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_vub, &n_vub, &m_vub, &vub); CONMIN_ERROR; if (n_vub*m_vub!=n_x*m_x) { Scierror(999,"%s: upper must have the same length as x\n", fname); return 0; } _SciErr = getVarAddressFromPosition(pvApiCtx, VLB_IN, &pi_vlb); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_vlb, &n_vlb, &m_vlb, &vlb); CONMIN_ERROR; if (n_vlb*m_vlb!=n_x*m_x) { Scierror(999,"%s: upper must have the same length as x\n", fname); return 0; } _SciErr = getVarAddressFromPosition(pvApiCtx, ITMAX_IN, &pi_itmax); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_itmax, &n_itmax, &m_itmax, &itmax); CONMIN_ERROR; tmp_int = (int)itmax[0]; C2F(set_itmax)(&tmp_int); // YC: si nvub != nvlb mettre le plus petit à +inf ou -inf // YC: si nvub != nvlb != ndv mettre tout à +inf et -inf et taille de ndv // C2F(cnmn1).nside = n_vub * m_vub; tmp_int = 2 * n_x * m_x; C2F(set_nside)(&tmp_int); //if (C2F(cnmn1).nside < (n_vlb * m_vlb)) C2F(cnmn1).nside = n_vlb * m_vlb; /////////////////////////////////////// // Get the parameters from the plist // /////////////////////////////////////// _SciErr = initPList(pvApiCtx, PARAM_IN, &pi_param); CONMIN_ERROR; if (!checkPList(pvApiCtx, pi_param)) { Scierror(999, "%s: argument n° %d is not a plist\n", fname, PARAM_IN); return 0; } tmp_int_2 = ncon[0] + 2 * n_x * m_x + 1; _SciErr = getIntInPList(pvApiCtx, pi_param, "nacmx", &tmp_int, &tmp_res, 0, 0, CHECK_NONE); CONMIN_ERROR; n3 = tmp_int; pIsc = (int *)MALLOC(10*sizeof(int)); // Bug in scilab: default value vector not mallocated -> workaround with a memory leak ... _SciErr = getColVectorOfIntInPList(pvApiCtx, pi_param, "isc", pIsc, &tmp_res, 0, 1, &szIsc, 0, CHECK_NONE); CONMIN_ERROR; if (!((tmp_res!=-1) && (szIsc==n_x*m_x))) { if (pIsc) FREE(pIsc); // We must allocate our own pIsc pIsc = (int *)MALLOC(n_x*m_x*sizeof(int)); for(i=0;i<n_x*m_x;i++) pIsc[i] = 0; Isc_mallocated = 1; } pScal = (double *)MALLOC(10*sizeof(double)); // Bug in scilab: default value vector not mallocated -> workaround with a memory leak ... _SciErr = getColVectorOfDoubleInPList(pvApiCtx, pi_param, "scal", pScal, &tmp_res, 0, 1, &szScal, 0, CHECK_NONE); CONMIN_ERROR; if (!((tmp_res!=-1) && (szScal==n_x*m_x))) { if (pScal) FREE(pScal); // We must allocate our own pScal pScal = (double *)MALLOC(n_x*m_x*sizeof(double)); for(i=0;i<n_x*m_x;i++) pScal[i] = 1.0; Scal_mallocated = 1; } _SciErr = getIntInPList(pvApiCtx, pi_param, "nscal", &tmp_int, &tmp_res, 0, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_nscal)(&tmp_int); _SciErr = getIntInPList(pvApiCtx, pi_param, "nfdg", &tmp_int, &tmp_res, 0, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_nfdg)(&tmp_int); _SciErr = getIntInPList(pvApiCtx, pi_param, "icndir", &tmp_int, &tmp_res, n_x*m_x+1, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_icndir)(&tmp_int); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "fdch", &tmp_dbl, &tmp_res, 0.01, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_fdch)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "fdchm", &tmp_dbl, &tmp_res, 0.01, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_fdchm)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "ct", &tmp_dbl, &tmp_res, -0.1, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_ct)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "ctmin", &tmp_dbl, &tmp_res, 0.004, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_ctmin)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "ctl", &tmp_dbl, &tmp_res, -0.01, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_ctl)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "ctlmin", &tmp_dbl, &tmp_res, 0.001, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_ctlmin)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "theta", &tmp_dbl, &tmp_res, 1.0, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_theta)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "delfun", &tmp_dbl, &tmp_res, 0.001, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_delfun)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "dabfun", &tmp_dbl, &tmp_res, 0.001, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_dabfun)(&tmp_dbl); _SciErr = getIntInPList(pvApiCtx, pi_param, "linobj", &tmp_int, &tmp_res, 0, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_linobj)(&tmp_int); _SciErr = getIntInPList(pvApiCtx, pi_param, "itrm", &tmp_int, &tmp_res, 3, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_itrm)(&tmp_int); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "alphax", &tmp_dbl, &tmp_res, 0.3, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_alphax)(&tmp_dbl); _SciErr = getDoubleInPList(pvApiCtx, pi_param, "abobj1", &tmp_dbl, &tmp_res, 0.2, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_abobj1)(&tmp_dbl); _SciErr = getIntInPList(pvApiCtx, pi_param, "infog", &tmp_int, &tmp_res, 0, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_infog)(&tmp_int); _SciErr = getIntInPList(pvApiCtx, pi_param, "info", &tmp_int, &tmp_res, 1, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_info)(&tmp_int); _SciErr = getIntInPList(pvApiCtx, pi_param, "iprint", &tmp_int, &tmp_res, 0, 0, CHECK_NONE); CONMIN_ERROR; if (tmp_res!=-1) C2F(set_iprint)(&tmp_int); // Verification: // size(x) = size(vlb) = size(vub) // size(x) = size(scal) ou (size(scal)==0 et nscal = 0) // size(isc) = ncon ou 0 n1 = n_x*m_x + 2; n2 = ncon[0] + 2*n_x*m_x; n4 = (n3>n_x*m_x)?n3:n_x*m_x; n5 = 2*n4; ///////////////////////////////////////////////////// // First call to objective function and constraint // ///////////////////////////////////////////////////// //////////////////////////////// // Call to objective function // //////////////////////////////// ibegin = Rhs + 1; Nbvars = ibegin + MAX(fobj_rhs,fobj_lhs); // Create the first variable: x n_x1_tmp = n_x; m_x1_tmp = m_x; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin, n_x1_tmp, m_x1_tmp, &x1_tmp); CONMIN_ERROR; memcpy(x1_tmp,x,n_x*m_x*sizeof(double)); // Create a fake 2nd variable on the stack. This will allow to call GetRhsVar to retrieve the 2nd output argument n_x2_tmp = 1; m_x2_tmp = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin + 1, n_x2_tmp, m_x2_tmp, &x2_tmp); CONMIN_ERROR; // Call to the scilab function SciFunction(&ibegin,&l_fobj,&fobj_lhs,&fobj_rhs); if (Err>0) { sciprint("conmin: error when calling objective function\n"); return 0; } /* End If */ // YC: we should add a check on fobj_lhs and fobj_rhs to check the scilab prototype of fobj // Get fobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin, &pi_fobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_fobj_tmp, &n_fobj_tmp, &m_fobj_tmp, &fobj_tmp); CONMIN_ERROR; // Get gradient of fobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin + 1, &pi_dfobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_dfobj_tmp, &n_dfobj_tmp, &m_dfobj_tmp, &dfobj_tmp); CONMIN_ERROR; Nbvars = nbvars_old; // Fill C2F(cnmn1).obj: objective function value C2F(set_obj)(fobj_tmp); // DF(N1) Analytic gradient of the objective function for the current decision variables, X(I). DF(I) contains the partial derivative // of OBJ with respect to X(I). Calculate DF(I), I = 1, NDV if INFO = 3 or INFO = 4 and if NFDG = 0 or NFDG = 2. DF = (double *)MALLOC(n1*sizeof(double)); // Fill DF(N1): gradient of objective function value memcpy(DF,dfobj_tmp,n_x*m_x*sizeof(double)); //////////////////////// // Call to constraint // //////////////////////// ibegin = Rhs + 1; // YC: for SciFunction Nbvars = ibegin + MAX(gobj_rhs,gobj_lhs); // YC: test nombre de param en entree (2) / sortie (3) // First parameter: the vector x n_x1_tmp = n_x; m_x1_tmp = m_x; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin, n_x1_tmp, m_x1_tmp, &x1_tmp); CONMIN_ERROR; memcpy(x1_tmp,x,n_x*m_x*sizeof(double)); // Second parameter: the scalar CT (Constraint Threshold) n_x2_tmp = 1; m_x2_tmp = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin + 1, n_x2_tmp, m_x2_tmp, &x2_tmp); CONMIN_ERROR; C2F(get_ct)(x2_tmp); // Third parameter: a fake parameter which will receive IC (index of active constraints) n_x3_tmp = 1; m_x3_tmp = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin + 2, n_x3_tmp, m_x3_tmp, &x3_tmp); CONMIN_ERROR; SciFunction(&ibegin,&l_gobj,&gobj_lhs,&gobj_rhs); if (Err>0) { sciprint("conmin: error when calling constraints function\n"); return 0; } /* End If */ // YC: we should add a check on gobj_lhs and gobj_rhs to check the scilab prototype of gobj // After the first call to the constraints, we get the number of constraints via the first variable returned by constraint function // Get gobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin, &pi_gobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_gobj_tmp, &n_gobj_tmp, &m_gobj_tmp, &gobj_tmp); CONMIN_ERROR; // Get gradient of gobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin + 1, &pi_dgobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_dgobj_tmp, &n_dgobj_tmp, &m_dgobj_tmp, &dgobj_tmp); CONMIN_ERROR; // Get indexes of active constraints _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin + 2, &pi_ic); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_ic, &n_ic, &m_ic, &ic); CONMIN_ERROR; if (ic_int) FREE(ic_int); ic_int = (int *)MALLOC(n_ic*m_ic*sizeof(int)); for(i=0; i<m_ic*m_ic; i++) ic_int[i] = (int)ic[i]; Nbvars = nbvars_old; // dgobj_tmp is of size [ndv][nac] tmp_int = n_ic*m_ic; C2F(set_nac)(&tmp_int); if (tmp_int>0) { // In scilab, the index start from 1. We need an index which start from 0 for(j=0;j<tmp_int;j++) { ic[j] = ic[j] - 1; } /* End For */ } /* End If */ /////////////////////// // Memory allocation // /////////////////////// // S(N1) Move direction in the NDV-dimensional optimization space. S(I) gives the rate at which variable X(I) changes with respect toALPHA. S = (double *)MALLOC(n1*sizeof(double)); // G1(N2) Not used if NCON = NSIDE = NSCAL = 0. Used for temporary storage of constraint values G(J), J = 1, NCON and decision // variables X(I), I = 1, NDV. G1 = (double *)MALLOC(n2*sizeof(double)); // G2(N2) Not used if NCON = NSIDE = 0. Used for temporary storage of constraint values G(J), J = 1, NCON. G2 = (double *)MALLOC(n2*sizeof(double)); // B(N3,N3) Not used if NCON = NSIDE = 0. Used in determining direction vector S for constrained minimization problems. Array B may // be used for temporary storage in external routine SUB1. B = (double *)MALLOC(n3*n3*sizeof(double)); // C(N4) Not used in NCON = NSIDE = 0. Used with array B in determining direction vector S for constrained minimization problems. Used // for temporary storage of vector X if NSCAL.NE.0. routine SUB1. C = (double *)MALLOC(n4*sizeof(double)); // MS1(N5) Not used if NCON = NSIDE = 0. Used with array B in determining direction vector S for constrained minimization problems. Array // MS1 may be used for temporary storage in external routine SUB1. MS1 = (int *)MALLOC(n5*sizeof(int)); // G(N2) Not used if NCON = NSIDE = 0. Vector containing all constraint functions, G(J), J = 1, NCON for current decision variables, X. // Calculate G(J), J = 1, NCON if INFO = 2. G = (double *)MALLOC(n2*sizeof(double)); // Fill G(N2): value of constraint for(i=0;i<ncon[0];i++) G[i] = gobj_tmp[i]; // A(N1,N3) Not used if NCON = NSIDE = 0. Gradients of active or violated constraints, for current decision variables, X(I). // A(J,I) contains the gradient of the Jth active or violated constraint, G(J), with respect to the Ith decision variable, // X(I) for J = 1, NAC and I = 1, NDV. Calculate if INFO = 4 and NFDG = 0. // YC: adress if 0 bytes after a block of size 48 alloc'd A = (double *)MALLOC(n1*n3*sizeof(double)); // Fill A(N1,N3): matrix of gradient of active constraint if (tmp_int>0) // tmp_int is still equal to C2F(cnmn1).nac { memcpy(A,dgobj_tmp,n_dgobj_tmp*m_dgobj_tmp*sizeof(double)); } /* End If */ tmp_int = 0; C2F(set_obj)(fobj_tmp); C2F(set_igoto)(&tmp_int); C2F(set_iter)(&tmp_int); // Start the optimization // Optimization loop for(i=0;i<itmax[0];i++) { #ifdef DEBUG DBGPRINTF("Iteration %d / %d\n",i,itmax[0]); #endif // Call to objective function and constraint function. // Create a new variable: x1_tmp on top of the stack - outside of the loop // Call SciFunction on fobj with ibegin=29 // Get fobj and dfobj on stack at position 30 and 31 // Call SciFunction on gobj with ibegin=29 // Get gobj and dgobj on stack at position 30 and 31 if (i>0) { // We skip the first iteration because we already have made a call to objective function and constraints //////////////////////////////// // Call to objective function // //////////////////////////////// ibegin = Rhs + 1; // YC: for SciFunction Nbvars = ibegin + MAX(fobj_rhs,fobj_lhs); // First parameter: the vector x n_x1_tmp = n_x; m_x1_tmp = m_x; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin, n_x1_tmp, m_x1_tmp, &x1_tmp); CONMIN_ERROR; memcpy(x1_tmp,x,n_x*m_x*sizeof(double)); // Create a fake 2nd variable on the stack. This will allow to call GetRhsVar to retrieve the 2nd output argument n_x2_tmp = 1; m_x2_tmp = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin + 1, n_x2_tmp, m_x2_tmp, &x2_tmp); CONMIN_ERROR; SciFunction(&ibegin,&l_fobj,&fobj_lhs,&fobj_rhs); if (Err>0) { sciprint("conmin: error when calling objective function at iteration %d / %d\n",i,itmax[0]); return 0; } /* End If */ // Get fobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin, &pi_fobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_fobj_tmp, &n_fobj_tmp, &m_fobj_tmp, &fobj_tmp); CONMIN_ERROR; // Get gradient of fobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin + 1, &pi_dfobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_dfobj_tmp, &n_dfobj_tmp, &m_dfobj_tmp, &dfobj_tmp); CONMIN_ERROR; Nbvars = nbvars_old; // Fill C2F(cnmn1).obj: objective function value C2F(set_obj)(fobj_tmp); // Fill DF(N1): gradient of objective function value memcpy(DF,dfobj_tmp,n_x*m_x*sizeof(double)); ////////////////////////////////// // Call to constraints function // ////////////////////////////////// ibegin = Rhs + 1; // YC: for SciFunction Nbvars = ibegin + MAX(gobj_rhs,gobj_lhs); // First parameter: the vector x n_x1_tmp = n_x; m_x1_tmp = m_x; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin, n_x1_tmp, m_x1_tmp, &x1_tmp); CONMIN_ERROR; memcpy(x1_tmp,x,n_x*m_x*sizeof(double)); // Second parameter: the scalar CT (Constraint Threshold) n_x2_tmp = 1; m_x2_tmp = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin + 1, n_x2_tmp, m_x2_tmp, &x2_tmp); CONMIN_ERROR; C2F(get_ct)(x2_tmp); // Third parameter: a fake parameter which will receive the IC (index of active constraint) list n_x3_tmp = 1; m_x3_tmp = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, ibegin + 2, n_x3_tmp, m_x3_tmp, &x3_tmp); CONMIN_ERROR; SciFunction(&ibegin,&l_gobj,&gobj_lhs,&gobj_rhs); if (Err>0) { sciprint("conmin: error when calling constraints function at iteration %d / %d\n",i,itmax[0]); return 0; } /* End If */ // Now, we get the constraint values and the derivate of the constraints // Get gobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin, &pi_gobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_gobj_tmp, &n_gobj_tmp, &m_gobj_tmp, &gobj_tmp); CONMIN_ERROR; // Get gradient of gobj _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin + 1, &pi_dgobj_tmp); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_dgobj_tmp, &n_dgobj_tmp, &m_dgobj_tmp, &dgobj_tmp); CONMIN_ERROR; // Get indexes of active constraints _SciErr = getVarAddressFromPosition(pvApiCtx, ibegin + 2, &pi_ic); CONMIN_ERROR; _SciErr = getMatrixOfDouble(pvApiCtx, pi_ic, &n_ic, &m_ic, &ic); CONMIN_ERROR; if (ic_int) FREE(ic_int); ic_int = (int *)MALLOC(n_ic*m_ic*sizeof(int)); for(i=0; i<m_ic*m_ic; i++) ic_int[i] = (int)ic[i]; Nbvars = nbvars_old; // dgobj_tmp is of size [ndv][nac] tmp_int = n_ic*m_ic; C2F(set_nac)(&tmp_int); // Fill G(N2): value of constraints memcpy(G,gobj_tmp,ncon[0]*sizeof(double)); if (tmp_int>0) // tmp_int is still equal to nac { // In scilab, the index start from 1. We need an index which start from 0 for(j=0;j<tmp_int;j++) { ic[j] = ic[j] - 1; } /* End For */ // Fill A(N1,N3): matrix of gradient of active constraint memcpy(A,dgobj_tmp,n_dgobj_tmp*m_dgobj_tmp*sizeof(double)); } /* End If */ } /* End If */ // X VLB VUB G SCAL DF A S G1 G2 B C //extern void C2F(conmin)(double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, // int *, int *, int *, int *, int *, int *, int *, int *); // ISC IC MS1 N1 N2 N3 N4 N5 // YC: revoir ic: mauvais type C2F(conmin)(x,vlb,vub,G,pScal,DF,A,S,G1,G2,B,C,pIsc,ic_int,MS1,&n1,&n2,&n3,&n4,&n5); C2F(get_igoto)(&tmp_int); if (tmp_int == 0) break; // Optimization has converged } /* End For */ ////////////////////////// // return the variables // ////////////////////////// // x_opt n_x_opt = n_x; m_x_opt = m_x; _SciErr = allocMatrixOfDouble(pvApiCtx, X_OPT_OUT, n_x_opt, m_x_opt, &x_opt); CONMIN_ERROR; memcpy(x_opt,x,n_x*m_x*sizeof(double)); // f_opt n_f_opt = 1; m_f_opt = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, F_OPT_OUT, n_f_opt, m_f_opt, &f_opt); CONMIN_ERROR; C2F(get_obj)(f_opt); // df_opt n_df_opt = n_x; m_df_opt = m_x; _SciErr = allocMatrixOfDouble(pvApiCtx, DF_OPT_OUT, n_df_opt, m_df_opt, &df_opt); CONMIN_ERROR; memcpy(df_opt,DF,n_x*m_x*sizeof(double)); // g_opt n_g_opt = ncon[0]; m_g_opt = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, G_OPT_OUT, n_g_opt, m_g_opt, &g_opt); CONMIN_ERROR; memcpy(g_opt,G,ncon[0]*sizeof(double)); // dg_opt n_dg_opt = n_dgobj_tmp; m_dg_opt = m_dgobj_tmp; _SciErr = allocMatrixOfDouble(pvApiCtx, DG_OPT_OUT, n_dg_opt, m_dg_opt, &dg_opt); CONMIN_ERROR; // Now, we stored the gradient of active constraint in the matrix memcpy(dg_opt,A,n_dgobj_tmp*m_dgobj_tmp*sizeof(double)); // IC C2F(get_nac)(&tmp_int); if (tmp_int!=0) { n_ic_res = tmp_int; m_ic_res = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, IC_OPT_OUT, n_ic_res, m_ic_res, &ic_opt); CONMIN_ERROR; // Now, we stored the gradient of active constraint in the matrix memcpy(ic_opt,ic_int,tmp_int*sizeof(int)); } else { n_ic_res = 1; m_ic_res = 1; _SciErr = allocMatrixOfDouble(pvApiCtx, IC_OPT_OUT, n_ic_res, m_ic_res, &ic_opt); CONMIN_ERROR; ic_opt[0] = -1; } LhsVar(1) = X_OPT_OUT; LhsVar(2) = F_OPT_OUT; LhsVar(3) = DF_OPT_OUT; LhsVar(4) = G_OPT_OUT; LhsVar(5) = DG_OPT_OUT; LhsVar(6) = IC_OPT_OUT; /////////////////////////// // Free allocated memory // /////////////////////////// if (G) FREE(G); if (A) FREE(A); if (DF) FREE(DF); if (S) FREE(S); if (G1) FREE(G1); if (G2) FREE(G2); if (B) FREE(B); if (C) FREE(C); if (MS1) FREE(MS1); if (Isc_mallocated) FREE(pIsc); if (Scal_mallocated) FREE(pScal); return 0; }
/* once the system is fully initialized, we wait for new messages. * We may think about replacing this with a read-loop, thus saving * us the overhead of the poll. * The timeout variable is the timeout to use for poll. During startup, * it should be set to 0 (non-blocking) and later to -1 (infinit, blocking). * This mimics the (strange) behaviour of the original syslogd. * rgerhards, 2010-04-19 */ static inline rsRetVal getMsgs(thrdInfo_t *pThrd, int timeout) { DEFiRet; int nfds; int iMaxLine; uchar *pRcv = NULL; /* receive buffer */ uchar bufRcv[4096+1]; char errStr[1024]; iMaxLine = glbl.GetMaxLine(); /* we optimize performance: if iMaxLine is below 4K (which it is in almost all * cases, we use a fixed buffer on the stack. Only if it is higher, heap memory * is used. We could use alloca() to achive a similar aspect, but there are so * many issues with alloca() that I do not want to take that route. * rgerhards, 2008-09-02 */ if((size_t) iMaxLine < sizeof(bufRcv) - 1) { pRcv = bufRcv; } else { CHKmalloc(pRcv = (uchar*) malloc(sizeof(uchar) * (iMaxLine + 1))); } while(pThrd->bShallStop != RSTRUE) { DBGPRINTF("imsolaris: waiting for next message (timeout %d)...\n", timeout); if(timeout == 0) { nfds = poll(&sun_Pfd, 1, timeout); /* wait without timeout */ if(pThrd->bShallStop == RSTRUE) { break; } if(nfds == 0) { if(timeout == 0) { DBGPRINTF("imsolaris: no more messages, getMsgs() terminates\n"); FINALIZE; } else { continue; } } if(nfds < 0) { if(errno != EINTR) { int en = errno; rs_strerror_r(en, errStr, sizeof(errStr)); DBGPRINTF("imsolaris: poll error: %d = %s.\n", errno, errStr); errmsg.LogError(en, NO_ERRCODE, "imsolaris: poll error: %s", errStr); } continue; } if(sun_Pfd.revents & POLLIN) { readLog(sun_Pfd.fd, pRcv, iMaxLine); } else if(sun_Pfd.revents & (POLLNVAL|POLLHUP|POLLERR)) { tryRecover(); } } else { /* if we have an infinite wait, we do not use poll at all * I'd consider this a waste of time. However, I do not totally * remove the code, as it may be useful if we decide at some * point to provide a capability to support multiple input streams * at once (this may be useful for a jail). In that case, the poll() * loop would be needed, and so it doesn't make much sense to change * the code to not support it. -- rgerhards, 2010-04-20 */ readLog(sun_Pfd.fd, pRcv, iMaxLine); } } finalize_it: if(pRcv != NULL && (size_t) iMaxLine >= sizeof(bufRcv) - 1) free(pRcv); RETiRet; }
// virtual functions of IDispatch HRESULT STDMETHODCALLTYPE CMain::GetTypeInfoCount( /* [out] */ UINT *pctinfo) { DBGPRINTF(("IDispatch::GetTypeInfoCount()\n")); return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE CMain::Close( void) { DBGPRINTF(("IActiveScript::Close()\n")); return S_OK; }
HRESULT STDMETHODCALLTYPE CMain::Invoke( /* [in] */ DISPID dispIdMember, /* [in] */ REFIID riid, /* [in] */ LCID lcid, /* [in] */ WORD wFlags, /* [out][in] */ DISPPARAMS *pDispParams, /* [out] */ VARIANT *pVarResult, /* [out] */ EXCEPINFO *pExcepInfo, /* [out] */ UINT *puArgErr) { DBGPRINTF(("IDispatch::Invoke(%d)\n", dispIdMember)); size_t idx = static_cast<size_t>(dispIdMember); if (idx >= _valListDispatched.size()) { return E_HANDLE; } Gura::Stream *pConsole = _pEnv->GetConsole(); Gura::Value value = _valListDispatched[idx]; Gura::ValueList valListArg; for (UINT iArg = 0; iArg < pDispParams->cArgs; iArg++) { Gura::Value value; if (!Gura::Gura_Module(mswin)::VariantToValue(*_pEnv, _sig, value, pDispParams->rgvarg[iArg])) { pExcepInfo->bstrDescription = L"*************"; pExcepInfo->bstrHelpFile = L""; pExcepInfo->bstrSource = L"Gura"; pExcepInfo->dwHelpContext = 0; pExcepInfo->pfnDeferredFillIn = nullptr; pExcepInfo->pvReserved = nullptr; pExcepInfo->wCode = ERROR_INVALID_DATA; pExcepInfo->wReserved = 0; _sig.PrintSignal(*pConsole); return DISP_E_EXCEPTION; } valListArg.push_back(value); } for (UINT iArg = 0; iArg < pDispParams->cNamedArgs; iArg++) { DISPID dispId = pDispParams->rgdispidNamedArgs[iArg]; } if (wFlags == DISPATCH_METHOD) { if (!value.Is_function()) return E_INVALIDARG; Gura::Object_function *pObjFunc = Gura::Object_function::GetObject(value); Gura::Value result = pObjFunc->Eval(*_pEnv, valListArg); if (_sig.IsSignalled()) { pExcepInfo->bstrDescription = L"*************"; pExcepInfo->bstrHelpFile = L""; pExcepInfo->bstrSource = L"Gura"; pExcepInfo->dwHelpContext = 0; pExcepInfo->pfnDeferredFillIn = nullptr; pExcepInfo->pvReserved = nullptr; pExcepInfo->wCode = ERROR_INVALID_FUNCTION; pExcepInfo->wReserved = 0; _sig.PrintSignal(*pConsole); return DISP_E_EXCEPTION; } if (pVarResult != nullptr) { Gura::Gura_Module(mswin)::ValueToVariant(_sig, *pVarResult, result); } } else if (wFlags == DISPATCH_PROPERTYGET) { if (pVarResult != nullptr) { Gura::Gura_Module(mswin)::ValueToVariant(_sig, *pVarResult, value); } } else if (wFlags == DISPATCH_PROPERTYPUT) { return E_INVALIDARG; } else if (wFlags == DISPATCH_PROPERTYPUTREF) { return E_INVALIDARG; } else { return E_INVALIDARG; } return S_OK; }
HRESULT STDMETHODCALLTYPE CMain::GetCurrentScriptThreadID( /* [out] */ SCRIPTTHREADID *pstidThread) { DBGPRINTF(("IActiveScript::GetCurrentScriptThreadID()\n")); return E_NOTIMPL; }
STDMETHODIMP_(ULONG) CClassFactory::Release() { DBGPRINTF(("CClassFactory::Release()\n")); return InterlockedDecrement(&_cntRef); }
HRESULT STDMETHODCALLTYPE CMain::Clone( /* [out] */ IActiveScript **ppscript) { DBGPRINTF(("IActiveScript::Clone()\n")); return E_NOTIMPL; }
/* submit a message to imklog Syslog() API. In this function, we check if * a kernel timestamp is present and, if so, extract and strip it. * Note that this is heavily Linux specific and thus is not compiled or * used for BSD. * Special thanks to Lennart Poettering for suggesting on how to convert * the kernel timestamp to a realtime timestamp. This method depends on * the fact the the kernel timestamp is written using the monotonic clock. * Shall that change (very unlikely), this code must be changed as well. Note * that due to the way we generate the delta, we are unable to write the * absolutely correct timestamp (system call overhead of the clock calls * prevents us from doing so). However, the difference is very minor. * rgerhards, 2011-06-24 */ static void submitSyslog(modConfData_t *pModConf, syslog_pri_t pri, uchar *buf) { long secs; long usecs; long secOffs; long usecOffs; unsigned i; unsigned bufsize; struct timespec monotonic, realtime; struct timeval tv; struct timeval *tp = NULL; if(!pModConf->bParseKernelStamp) goto done; if(buf[3] != '[') goto done; DBGPRINTF("imklog: kernel timestamp detected, extracting it\n"); /* we now try to parse the timestamp. iff it parses, we assume * it is a timestamp. Otherwise we know for sure it is no ts ;) */ i = 4; /* space or first digit after '[' */ while(buf[i] && isspace(buf[i])) ++i; /* skip space */ secs = 0; while(buf[i] && isdigit(buf[i])) { secs = secs * 10 + buf[i] - '0'; ++i; } if(buf[i] != '.') { DBGPRINTF("no dot --> no kernel timestamp\n"); goto done; /* no TS! */ } ++i; /* skip dot */ usecs = 0; while(buf[i] && isdigit(buf[i])) { usecs = usecs * 10 + buf[i] - '0'; ++i; } if(buf[i] != ']') { DBGPRINTF("no trailing ']' --> no kernel timestamp\n"); goto done; /* no TS! */ } ++i; /* skip ']' */ /* we have a timestamp */ DBGPRINTF("kernel timestamp is %ld %ld\n", secs, usecs); if(!pModConf->bKeepKernelStamp) { bufsize= strlen((char*)buf); memmove(buf+3, buf+i, bufsize - i + 1); } clock_gettime(CLOCK_MONOTONIC, &monotonic); clock_gettime(CLOCK_REALTIME, &realtime); secOffs = realtime.tv_sec - monotonic.tv_sec; usecOffs = (realtime.tv_nsec - monotonic.tv_nsec) / 1000; if(usecOffs < 0) { secOffs--; usecOffs += 1000000l; } usecs += usecOffs; if(usecs > 999999l) { secs++; usecs -= 1000000l; } secs += secOffs; tv.tv_sec = secs; tv.tv_usec = usecs; tp = &tv; done: Syslog(pri, buf, tp); }
HRESULT CMain::InitNew(void) { DBGPRINTF(("CActiveScriptParse32::InitNew()\n")); return S_OK; }
static void OriginateListener(CallDemoApp *pMe, ModelEvent *pEvent) { AEETCallEvent* pCallEvent = (AEETCallEvent*) pEvent; switch (pCallEvent->evCode) { case AEET_EVENT_CALL_CONNECT: { DBGPRINTF("Rx: AEET_EVENT_CALL_CONNECT cd=%d", pCallEvent->call.cd); WriteLine(pMe, "Rx: AEET_EVENT_CALL_CONNECT", NULL, FALSE); break; } case AEET_EVENT_CALL_ERROR: { DBGPRINTF("AEET_EVENT_CALL_ERROR"); WriteLine(pMe, "Rx: AEET_EVENT_CALL_ERROR", NULL, FALSE); LISTENER_Cancel(&pMe->callListener); break; } case AEET_EVENT_INBAND_FWD_BURST_DTMF: { DBGPRINTF("AEET_EVENT_INBAND_FWD_BURST_DTMF"); WriteLine(pMe, "Rx: AEET_EVENT_INBAND_FWD_BURST_DTMF", NULL, FALSE); break; } case AEET_EVENT_CALL_END: { DBGPRINTF("Rx: AEET_EVENT_CALL_END"); WriteLine(pMe, "Rx: AEET_EVENT_CALL_END", NULL, FALSE); LISTENER_Cancel(&pMe->callListener); if (Telephone_EndCall(pMe) != SUCCESS) { if (pMe->m_pOutgoingCall) { ICALL_Release(pMe->m_pOutgoingCall); pMe->m_pOutgoingCall = NULL; } } if(pMe->m_isDTMFItem) { pMe->m_isDTMFItem = FALSE; } if(pMe->m_isParty3Item) { pMe->m_isParty3Item = FALSE; LISTENER_Cancel(&pMe->callListenerB); } if(pMe->m_isRedirectItem) { pMe->m_isRedirectItem = FALSE; } break; } default: { DBGPRINTF("OriginateListener Rx: %d", pCallEvent->evCode); break; } } }
// virtual functions of IActiveScriptError HRESULT STDMETHODCALLTYPE CMain::GetExceptionInfo( /* [out] */ EXCEPINFO *pexcepinfo) { DBGPRINTF(("IActiveScriptError::GetExceptionInfo()\n")); return E_NOTIMPL; }
static boolean CallDemoApp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam) { CallDemoApp * pMe = (CallDemoApp*)pi; switch (eCode) { case EVT_APP_START: // When this applet is started, try to create the main menu // that allows the user to select a usage example to execute. // If we cannot create an instance of the menu class, exit and // indicate that we have handled the event by returning TRUE if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_MENUCTL, (void **)&pMe->m_pIMenu) != SUCCESS) return TRUE; // Succeeded in obtaining a menu instance pointer, so // construct the menu and display it on the screen BuildMainMenu(pMe); return(TRUE); case EVT_APP_STOP: return(TRUE); case EVT_KEY: if(pMe->m_isDTMFItem) { if (wParam == AVK_2) { AECHAR szwStr[32]; char szNumber[32]; int nRet; // get telephone number (main) from resource file ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER_SUB, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); nRet = ICALL_BurstDTMF(pMe->m_pOutgoingCall, AEET_DTMF_ON_95,AEET_DTMF_OFF_60,szNumber); DBGPRINTF("ICALL_BurstDTMF ret %d", nRet); WriteLine(pMe, "ICALL_BurstDTMF -->", NULL, FALSE); } } if (pMe->m_isParty3Item) { if (wParam == AVK_3) { AECHAR szwStr[32]; char szNumber[32]; boolean Result; // get telephone number (main) from resource file ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER_B, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); LISTENER_Init(&pMe->callListenerB, (PFNLISTENER) OriginateListener, pMe); Result = ICALLMGR_Originate(pMe->m_pCallMgr, AEET_CALL_TYPE_VOICE, szNumber, NULL, &pMe->m_pOutgoingCallB, &pMe->callListenerB); if (Result != SUCCESS) { DBGPRINTF("ICALLMGR_Originate failed with res=%d", Result); break; } WriteLine(pMe, "Call Originate B-->", NULL, FALSE); WriteLine(pMe, "Press 1 to unhold A", NULL, FALSE); return TRUE; } if (wParam == AVK_1) { int nRet; if(pMe->m_pOutgoingCall) { nRet = ICALL_SwitchTo( pMe->m_pOutgoingCall ); DBGPRINTF("ICALL_SwitchTo A ret:%d", nRet); } #if 0 if(pMe->m_pOutgoingCallB) { nRet = ICALL_Hold( pMe->m_pOutgoingCallB ); DBGPRINTF("ICALL_Hold B ret:%d", nRet); } #endif WriteLine(pMe, "switch issued", NULL, FALSE); return TRUE; } #if 0 if (wParam == AVK_2) { int nRet; if(pMe->m_pOutgoingCallB) { nRet = ICALL_SwitchTo( pMe->m_pOutgoingCallB ); DBGPRINTF("ICALL_SwitchTo B ret:%d", nRet); } if(pMe->m_pOutgoingCall) { nRet = ICALL_Hold( pMe->m_pOutgoingCall ); DBGPRINTF("ICALL_Hold A ret:%d", nRet); } WriteLine(pMe, "switch issued", NULL, FALSE); return TRUE; } #endif } // ¿ØÖÆÉÏϼüÑ¡Ôñ²Ëµ¥ if (pMe->m_pIMenu) { if ((IMENUCTL_IsActive(pMe->m_pIMenu) == FALSE) && ((wParam == AVK_UP) || (wParam == AVK_DOWN))) { IMENUCTL_SetActive(pMe->m_pIMenu, TRUE); IMENUCTL_Redraw(pMe->m_pIMenu); } return IMENUCTL_HandleEvent(pMe->m_pIMenu, EVT_KEY, wParam, 0); } else return FALSE; case EVT_NOTIFY: break; case EVT_COMMAND: switch(wParam) { // The following commands are generated by user selections // from the main usage app menu. case USAGE_CALL_ORIG: case USAGE_CALL_OUTGOING_END: case USAGE_CALL_INCOMING_END: case USAGE_CALL_DTMF: case USAGE_CALL_PARTY3: case USAGE_CALL_ANSWER: case USAGE_CALL_REDIRECT: // Deactivate main menu to turn off horizontal scrolling of long menu items IMENUCTL_SetActive(pMe->m_pIMenu, FALSE); // Execute the usage example the user has selected CallDemoAppUsage (pMe, wParam); return TRUE; default: return FALSE; } // switch(wPara) case EVT_MY_ANSWER: DBGPRINTF("handler of call incoming by answer"); if (pMe->m_pIncomingCall) { int nError; nError = ICALL_Answer(pMe->m_pIncomingCall); if (SUCCESS != nError) { DBGPRINTF("ICALL_Answer failed ret=%d", nError); } else { DBGPRINTF("ICALL_Answer -->"); WriteLine(pMe, "ICALL_Answer -->", NULL, FALSE); } } return TRUE; case EVT_MY_REDIRECT: DBGPRINTF("handler of call incoming by redirect"); if (pMe->m_pIncomingCall) { int nError; AECHAR szwStr[32]; char szNumber[32]; // get redirect number ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER_REDIRECT, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); nError = ICALL_Redirect(pMe->m_pIncomingCall, szNumber); if (SUCCESS != nError) { DBGPRINTF("ICALL_Redirect failed ret=%d", nError); } else { DBGPRINTF("ICALL_Redirect -->%s", szNumber); WriteLine(pMe, "ICALL_Redirect -->", NULL, FALSE); } } return TRUE; default: break; } // switch (eCode) #ifdef EVENT_AUTO_GET if(eCode == pMe->m_UserAnswerEvent) { DBGPRINTF("handler of call incoming by answer"); if (pMe->m_pIncomingCall) { int nError; nError = ICALL_Answer(pMe->m_pIncomingCall); if (SUCCESS != nError) { DBGPRINTF("ICALL_Answer failed ret=%d", nError); } else { DBGPRINTF("ICALL_Answer -->"); WriteLine(pMe, "ICALL_Answer -->", NULL, FALSE); } } } if(eCode == pMe->m_UserRedirectEvent) { DBGPRINTF("handler of call incoming by redirect"); if (pMe->m_pIncomingCall) { int nError; AECHAR szwStr[32]; char szNumber[32]; // get redirect number ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER_REDIRECT, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); nError = ICALL_Redirect(pMe->m_pIncomingCall, szNumber); if (SUCCESS != nError) { DBGPRINTF("ICALL_Redirect failed ret=%d", nError); } else { DBGPRINTF("ICALL_Redirect -->%s", szNumber); WriteLine(pMe, "ICALL_Redirect -->", NULL, FALSE); } } } #endif return FALSE; }
HRESULT STDMETHODCALLTYPE CMain::GetSourceLineText( /* [out] */ BSTR *pbstrSourceLine) { DBGPRINTF(("IActiveScriptError::GetSourceLineText()\n")); return E_NOTIMPL; }
/*=========================================================================== FUNCTION: CallDemoAppUsage DESCRIPTION This function executes the usage example selected from the main menu by the user. It takes as input the app data pointer and the ID of the example the user selected. After clearing the screen, the selected example is executed. Each example is a self-contained code block that contains any local variables needed to execute the example. Each code block also creates and releases any BREW interfaces that are required, and will exit if any errors are detected. Once the example has been executed, this function prints a heading at the top of the screen to indicate which example was selected, and a message at the bottom of the screen instructing the user how to return to the main menu to execute another example. PROTOTYPE: static void IFileUsage(CallDemoApp * pMe, uint16 wParam) PARAMETERS: pMe: [in]: Contains a pointer to the usage app data structure. wParam: [in]: Identifier of the selected example (example IDs are specified when the main usage app menu is created). DEPENDENCIES None RETURN VALUE None SIDE EFFECTS None ===========================================================================*/ static void CallDemoAppUsage (CallDemoApp * pMe, uint16 wParam) { // Make sure the pointers we'll be using are valid if (pMe == NULL || pMe->a.m_pIShell == NULL || pMe->a.m_pIDisplay == NULL) return; // Erase screen first for display output purposes. DisplayEvent (pMe, USAGE_ERASE_SCREEN); IMENUCTL_SetProperties(pMe->m_pIMenu, MP_NO_REDRAW); IMENUCTL_SetActive(pMe->m_pIMenu, FALSE); // Initialize line number where we will start the output // of each test pMe->m_cLineNum = 1; switch (wParam) { case USAGE_CALL_ORIG: { AECHAR szwStr[32]; char szNumber[32]; boolean Result; // get telephone number from resource file ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); LISTENER_Init(&pMe->callListener, (PFNLISTENER) OriginateListener, pMe); Result = ICALLMGR_Originate(pMe->m_pCallMgr, AEET_CALL_TYPE_VOICE, szNumber, NULL, &pMe->m_pOutgoingCall, &pMe->callListener); if (Result != SUCCESS) { DBGPRINTF("ICALLMGR_Originate failed with res=%d", Result); break; } WriteLine(pMe, "Call Originate -->", NULL, FALSE); } break; case USAGE_CALL_OUTGOING_END: { if (Telephone_EndCall(pMe) != SUCCESS) { if (pMe->m_pOutgoingCall) { ICALL_Release(pMe->m_pOutgoingCall); pMe->m_pOutgoingCall = NULL; } } WriteLine(pMe, "Call End -->", NULL, FALSE); } break; case USAGE_CALL_INCOMING_END: { int iResult = EFAILED; if (pMe->m_pIncomingCall != NULL) { iResult = ICALL_End(pMe->m_pIncomingCall); if (iResult == SUCCESS) { ICALL_Release(pMe->m_pIncomingCall); pMe->m_pIncomingCall = NULL; } } WriteLine(pMe, "Call End -->", NULL, FALSE); } break; case USAGE_CALL_DTMF: { AECHAR szwStr[32]; char szNumber[32]; boolean Result; // get telephone number (main) from resource file ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER_MAIN, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); LISTENER_Init(&pMe->callListener, (PFNLISTENER) OriginateListener, pMe); Result = ICALLMGR_Originate(pMe->m_pCallMgr, AEET_CALL_TYPE_VOICE, szNumber, NULL, &pMe->m_pOutgoingCall, &pMe->callListener); if (Result != SUCCESS) { DBGPRINTF("ICALLMGR_Originate failed with res=%d", Result); break; } WriteLine(pMe, "Call Originate -->", NULL, FALSE); WriteLine(pMe, "Press 2 to DTMF", NULL, FALSE); pMe->m_isDTMFItem = TRUE; } break; case USAGE_CALL_PARTY3: { AECHAR szwStr[32]; char szNumber[32]; boolean Result; // get telephone number (main) from resource file ISHELL_LoadResString(pMe->a.m_pIShell, CALLDEMO_RES_FILE, IDS_STRING_TELEPHONE_NUMBER_A, szwStr, sizeof(szwStr)); WSTRTOSTR(szwStr, szNumber, sizeof(szNumber)); LISTENER_Init(&pMe->callListener, (PFNLISTENER) OriginateListener, pMe); Result = ICALLMGR_Originate(pMe->m_pCallMgr, AEET_CALL_TYPE_VOICE, szNumber, NULL, &pMe->m_pOutgoingCall, &pMe->callListener); if (Result != SUCCESS) { DBGPRINTF("ICALLMGR_Originate failed with res=%d", Result); break; } WriteLine(pMe, "Call Originate A-->", NULL, FALSE); WriteLine(pMe, "Press 3 to call B", NULL, FALSE); pMe->m_isParty3Item = TRUE; } break; case USAGE_CALL_ANSWER: pMe->m_isRedirectItem = FALSE; break; case USAGE_CALL_REDIRECT: pMe->m_isRedirectItem = TRUE; break; default: return; } // Display above event. DisplayEvent (pMe, wParam); return; }
// virtual functions of IActiveScriptGarbageCollector HRESULT STDMETHODCALLTYPE CMain::CollectGarbage( SCRIPTGCTYPE scriptgctype) { DBGPRINTF(("IActiveScriptGarbageCollector::CollectGarbage()\n")); return S_OK; }
// this function is called when your application is exiting void MemChecker_FreeAppData(MemChecker* pMe) { // insert your code here for freeing any resources you have allocated... DBGPRINTF("##MemChecker_FreeAppData######################################"); }
/*-------------------------------------------------------------------------* * DISPLAY_STACK * * * *-------------------------------------------------------------------------*/ static void Display_Stack(WamWord *exp) { int op = exp[0]; WamWord *le = (WamWord *) (exp[1]); WamWord *re = (WamWord *) (exp[2]); switch (op) { case NOT: DBGPRINTF("%s", pl_atom_tbl[Functor_Of(bool_tbl[op])].name); DBGPRINTF(" "); Pl_Write_1(exp[1]); break; case EQUIV: case NEQUIV: case IMPLY: case NIMPLY: case AND: case NAND: case OR: case NOR: DBGPRINTF("("); Display_Stack(le); DBGPRINTF(" "); DBGPRINTF("%s", pl_atom_tbl[Functor_Of(bool_tbl[op])].name); DBGPRINTF(" "); Display_Stack(re); DBGPRINTF(")"); break; case EQ: case NEQ: case LT: case LTE: case GT: case GTE: case EQ_F: case NEQ_F: case LT_F: case LTE_F: case GT_F: case GTE_F: Pl_Write_1(exp[1]); DBGPRINTF(" "); DBGPRINTF("%s", pl_atom_tbl[Functor_Of(bool_tbl[op])].name); DBGPRINTF(" "); Pl_Write_1(exp[2]); break; case ZERO: DBGPRINTF("0"); break; case ONE: DBGPRINTF("1"); break; default: Pl_Write_1(*exp); } }