Пример #1
0
externC void
cyg_start( void )
{
    int i;
    
    diag_init();

    diag_write_string("Philosophers\n");
    diag_write_string("Started\n");

    // Zero last element in state so it acts like
    // a string.
    pstate[PHILOSOPHERS] = 0;

#if 1
    for( i = 0; i < PHILOSOPHERS; i++ )
    {
        change_state(i,'T');            // starting state

        cyg_thread_create(4, Philosopher, (cyg_addrword_t)i, "philosopher",
            (void *)(&thread_stack[i]), STACKSIZE,
            &thread_handle[i], &thread[i]);

        // resume it
        cyg_thread_resume(thread_handle[i]);

        // and make the matching chopstick present
        cyg_semaphore_init( &chopstick[i], 1);
    }
#endif
    
    // Get the world going
    cyg_scheduler_start();

}
Пример #2
0
/*
 * Initialization code.
 *
 * Called from kernel_start() routine that is
 * implemented in HAL.
 * We assume that the following machine state has
 * been already set before this routine.
 *	- Kernel BSS section is filled with 0.
 *	- Kernel stack is configured.
 *	- All interrupts are disabled.
 *	- Minimum page table is set. (MMU systems only)
 */
int
main(void)
{

	sched_lock();
	diag_init();
	DPRINTF((BANNER));

	/*
	 * Initialize memory managers.
	 */
	page_init();
	kmem_init();

	/*
	 * Do machine-dependent
	 * initialization.
	 */
	machine_startup();

	/*
	 * Initialize kernel core.
	 */
	vm_init();
	task_init();
	thread_init();
	sched_init();
	exception_init();
	timer_init();
	object_init();
	msg_init();

	/*
	 * Enable interrupt and
	 * initialize devices.
	 */
	irq_init();
	clock_init();
	device_init();

	/*
	 * Set up boot tasks.
	 */
	task_bootstrap();

	/*
	 * Start scheduler and
	 * enter idle loop.
	 */
	sched_unlock();
	thread_idle();

	/* NOTREACHED */
	return 0;
}
int main(int argc, char *argv[]) {

    int ret = 0;

    pthread_t pid_wait, pid_handle;

    ALOGI("%s mmi_diag start", __FUNCTION__);
    sem_init(&g_msg_sem, 0, 0);
    sem_init(&g_cmd_complete_sem, 0, 0);

    ret = diag_init();
    if(ret < 0)
        goto out;

    /** Connect to MMI server via socket*/
    g_sock = connect_server(MMI_SOCKET);
    if(g_sock < 0)
        goto out;

     /**Ready, say hello to server*/
    say_hello(g_sock, CLIENT_DIAG_NAME);

    ret = pthread_create(&pid_wait, NULL, msg_waiting_thread, &g_sock);
    if(ret < 0) {
        ALOGE("%s:Can't create msg waiting pthread: %s\n", __FUNCTION__, strerror(errno));
        goto out;
    }

    ret = pthread_create(&pid_handle, NULL, msg_handle_thread, NULL);
    if(ret < 0) {
        ALOGE("%s:Can't create msg handle pthread: %s\n", __FUNCTION__, strerror(errno));
        goto out;
    }

    pthread_join(pid_wait, NULL);
    pthread_join(pid_handle, NULL);

  out:
    ALOGI("%s: mmi diag exit to clear resource", __FUNCTION__);
    diag_deinit();
    sem_close(&g_msg_sem);
    sem_close(&g_cmd_complete_sem);
    exit(1);
}
Пример #4
0
int main() {
	uint8_t r = 0;
	diag_init();
	BSP_PB_Init(0, 0);
	new_task(0, led_handler, NULL);

	while (1) {
		int state = BSP_PB_GetState(0);
		if (state) {
			r++;
			r %= 8;
		}
		ksleep(100);
		diag_putc(r);
		ksleep(100);
	}

	return 0;
}
Пример #5
0
//cmd_watch : this creates a diag_l3_conn
//TODO: "press any key to stop" ...
static int
cmd_watch(int argc, char **argv)
{
	int rv;
	struct diag_l2_conn *d_l2_conn;
	struct diag_l3_conn *d_l3_conn=NULL;
	struct diag_l0_device *dl0d;
	int rawmode = 0;
	int nodecode = 0;
	int nol3 = 0;

	if (argc > 1) {
		if (strcasecmp(argv[1], "raw") == 0)
			rawmode = 1;
		else if (strcasecmp(argv[1], "nodecode") == 0)
			nodecode = 1;
		else if (strcasecmp(argv[1], "nol3") == 0)
			nol3 = 1;
		else {
			printf("Don't understand \"%s\"\n", argv[1]);
			return CMD_USAGE;
		}
	}

	rv = diag_init();
	if (rv != 0) {
		fprintf(stderr, "diag_init failed\n");
		diag_end();
		return CMD_FAILED;
	}
	dl0d = diag_l2_open(l0_names[set_interface_idx].longname, set_subinterface, global_cfg.L1proto);
	if (dl0d == NULL) {
		rv = diag_geterr();
		printf("Failed to open hardware interface, ");
		if (rv == DIAG_ERR_PROTO_NOTSUPP)
			printf("does not support requested L1 protocol\n");
		else if (rv == DIAG_ERR_BADIFADAPTER)
			printf("adapter probably not connected\n");
		else
			printf("%s\n",diag_errlookup(rv));
		return CMD_FAILED;
	}
	if (rawmode) {
		d_l2_conn = diag_l2_StartCommunications(dl0d, DIAG_L2_PROT_RAW,
			0, global_cfg.speed,
			global_cfg.tgt,
			global_cfg.src);
	} else {
		d_l2_conn = diag_l2_StartCommunications(dl0d, global_cfg.L2proto,
			DIAG_L2_TYPE_MONINIT, global_cfg.speed, global_cfg.tgt, global_cfg.src);
	}

	if (d_l2_conn == NULL) {
		printf("Failed to connect to hardware in monitor mode\n");
		diag_l2_close(dl0d);
		return CMD_FAILED;
	}
	//here we have a valid d_l2_conn over dl0d.

	if (rawmode == 0) {
		/* Put the SAE J1979 stack on top of the ISO device */

		if (nol3 == 0) {
			d_l3_conn = diag_l3_start("SAEJ1979", d_l2_conn);
			if (d_l3_conn == NULL) {
				printf("Failed to enable SAEJ1979 mode\n");
				diag_l2_StopCommunications(d_l2_conn);
				diag_l2_close(dl0d);
				return CMD_FAILED;
			}
		} else {
			d_l3_conn = NULL;
		}

		printf("Waiting for data to be received\n");
		while (1) {
			if (d_l3_conn != NULL) {
				rv = diag_l3_recv(d_l3_conn, 10000,
					j1979_watch_rcv,
					(nodecode) ? NULL:(void *)d_l3_conn);
			} else {
				rv = diag_l2_recv(d_l2_conn, 10000,
					j1979_watch_rcv, NULL);
			}
			if (rv == 0)
				continue;
			if (rv == DIAG_ERR_TIMEOUT)
				continue;
		}
	} else {
		//rawmode !=0 here
		/*
		 * And just read stuff, callback routine will print out the data
		 */
		printf("Waiting for data to be received\n");
		while (1) {
			rv = diag_l2_recv(d_l2_conn, 10000,
				j1979_data_rcv, (void *)&_RQST_HANDLE_WATCH);
			if (rv == 0)
				continue;
			if (rv == DIAG_ERR_TIMEOUT)
				continue;
			printf("recv returns %d\n", rv);
			break;
		}
	}
	if (d_l3_conn != NULL)
		diag_l3_stop(d_l3_conn);

	diag_l2_StopCommunications(d_l2_conn);
	diag_l2_close(dl0d);

	return CMD_OK;
}
Пример #6
0
int ANSC_EXPORT_API
COSA_Init
    (
        ULONG                       uMaxVersionSupported,
        void*                       hCosaPlugInfo         /* PCOSA_PLUGIN_INFO passed in by the caller */
    )
{
    PCOSA_PLUGIN_INFO               pPlugInfo                   = (PCOSA_PLUGIN_INFO                 )hCosaPlugInfo;
    COSAGetParamValueStringProc     pGetStringProc              = (COSAGetParamValueStringProc       )NULL;
    COSAGetParamValueUlongProc      pGetParamValueUlongProc     = (COSAGetParamValueUlongProc        )NULL;
    COSAGetCommonHandleProc         pGetCHProc                  = (COSAGetCommonHandleProc           )NULL;
    COSAValidateHierarchyInterfaceProc
                                    pValInterfaceProc           = (COSAValidateHierarchyInterfaceProc)NULL;
    COSAGetHandleProc               pGetRegistryRootFolder      = (COSAGetHandleProc                 )NULL;
    COSAGetInstanceNumberByIndexProc
                                    pGetInsNumberByIndexProc    = (COSAGetInstanceNumberByIndexProc  )NULL;
    COSAGetHandleProc               pGetMessageBusHandleProc    = (COSAGetHandleProc                 )NULL;
    COSAGetInterfaceByNameProc      pGetInterfaceByNameProc     = (COSAGetInterfaceByNameProc        )NULL;

    if ( uMaxVersionSupported < THIS_PLUGIN_VERSION )
    {
      /* this version is not supported */
        return -1;
    }

    pPlugInfo->uPluginVersion       = THIS_PLUGIN_VERSION;
    g_pDslhDmlAgent                 = pPlugInfo->hDmlAgent;

    /* register the back-end apis for the data model */

    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "X_CISCO_COM_ARP_GetParamBoolValue",  X_CISCO_COM_ARP_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "X_CISCO_COM_ARP_GetParamIntValue",  X_CISCO_COM_ARP_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "X_CISCO_COM_ARP_GetParamUlongValue",  X_CISCO_COM_ARP_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "X_CISCO_COM_ARP_GetParamStringValue",  X_CISCO_COM_ARP_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_GetEntryCount",  ARPTable_GetEntryCount);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_GetEntry",  ARPTable_GetEntry);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_IsUpdated",  ARPTable_IsUpdated);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_Synchronize",  ARPTable_Synchronize);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_GetParamBoolValue",  ARPTable_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_GetParamIntValue",  ARPTable_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_GetParamUlongValue",  ARPTable_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "ARPTable_GetParamStringValue",  ARPTable_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_GetParamBoolValue",  IPPing_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_GetParamIntValue",  IPPing_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_GetParamUlongValue",  IPPing_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_GetParamStringValue",  IPPing_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_SetParamBoolValue",  IPPing_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_SetParamIntValue",  IPPing_SetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_SetParamUlongValue",  IPPing_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_SetParamStringValue",  IPPing_SetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_Validate",  IPPing_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_Commit",  IPPing_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "IPPing_Rollback",  IPPing_Rollback);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_GetParamBoolValue",  TraceRoute_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_GetParamIntValue",  TraceRoute_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_GetParamUlongValue",  TraceRoute_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_GetParamStringValue",  TraceRoute_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_SetParamBoolValue",  TraceRoute_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_SetParamIntValue",  TraceRoute_SetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_SetParamUlongValue",  TraceRoute_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_SetParamStringValue",  TraceRoute_SetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_Validate",  TraceRoute_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_Commit",  TraceRoute_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "TraceRoute_Rollback",  TraceRoute_Rollback);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_GetEntryCount",  RouteHops_GetEntryCount);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_GetEntry",  RouteHops_GetEntry);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_IsUpdated",  RouteHops_IsUpdated);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_Synchronize",  RouteHops_Synchronize);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_GetParamBoolValue",  RouteHops_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_GetParamIntValue",  RouteHops_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_GetParamUlongValue",  RouteHops_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "RouteHops_GetParamStringValue",  RouteHops_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_GetParamBoolValue",  DownloadDiagnostics_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_GetParamIntValue",  DownloadDiagnostics_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_GetParamUlongValue",  DownloadDiagnostics_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_GetParamStringValue",  DownloadDiagnostics_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_SetParamBoolValue",  DownloadDiagnostics_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_SetParamIntValue",  DownloadDiagnostics_SetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_SetParamUlongValue",  DownloadDiagnostics_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_SetParamStringValue",  DownloadDiagnostics_SetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_Validate",  DownloadDiagnostics_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_Commit",  DownloadDiagnostics_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "DownloadDiagnostics_Rollback",  DownloadDiagnostics_Rollback);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_GetParamBoolValue",  UploadDiagnostics_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_GetParamIntValue",  UploadDiagnostics_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_GetParamUlongValue",  UploadDiagnostics_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_GetParamStringValue",  UploadDiagnostics_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_SetParamBoolValue",  UploadDiagnostics_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_SetParamIntValue",  UploadDiagnostics_SetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_SetParamUlongValue",  UploadDiagnostics_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_SetParamStringValue",  UploadDiagnostics_SetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_Validate",  UploadDiagnostics_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_Commit",  UploadDiagnostics_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UploadDiagnostics_Rollback",  UploadDiagnostics_Rollback);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_GetParamBoolValue",  UDPEchoConfig_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_GetParamIntValue",  UDPEchoConfig_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_GetParamUlongValue",  UDPEchoConfig_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_GetParamStringValue",  UDPEchoConfig_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_SetParamBoolValue",  UDPEchoConfig_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_SetParamIntValue",  UDPEchoConfig_SetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_SetParamUlongValue",  UDPEchoConfig_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_SetParamStringValue",  UDPEchoConfig_SetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_Validate",  UDPEchoConfig_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_Commit",  UDPEchoConfig_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "UDPEchoConfig_Rollback",  UDPEchoConfig_Rollback);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "X_RDKCENTRAL-COM_SpeedTest_GetParamBoolValue",  SpeedTest_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "X_RDKCENTRAL-COM_SpeedTest_SetParamBoolValue",  SpeedTest_SetParamBoolValue);

    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_GetParamBoolValue",  NSLookupDiagnostics_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_GetParamIntValue",  NSLookupDiagnostics_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_GetParamUlongValue",  NSLookupDiagnostics_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_GetParamStringValue",  NSLookupDiagnostics_GetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_SetParamBoolValue",  NSLookupDiagnostics_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_SetParamIntValue",  NSLookupDiagnostics_SetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_SetParamUlongValue",  NSLookupDiagnostics_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_SetParamStringValue",  NSLookupDiagnostics_SetParamStringValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_Validate",  NSLookupDiagnostics_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_Commit",  NSLookupDiagnostics_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "NSLookupDiagnostics_Rollback",  NSLookupDiagnostics_Rollback);

    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_GetEntryCount",  Result_GetEntryCount);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_GetEntry",  Result_GetEntry);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_IsUpdated",  Result_IsUpdated);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_Synchronize",  Result_Synchronize);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_GetParamBoolValue",  Result_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_GetParamIntValue",  Result_GetParamIntValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_GetParamUlongValue",  Result_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "Result_GetParamStringValue",  Result_GetParamStringValue);

    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_GetParamBoolValue",  LogBackup_GetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_SetParamBoolValue",  LogBackup_SetParamBoolValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_GetParamUlongValue",  LogBackup_GetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_SetParamUlongValue",  LogBackup_SetParamUlongValue);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_Validate",  LogBackup_Validate);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_Commit",  LogBackup_Commit);
    pPlugInfo->RegisterFunction(pPlugInfo->hContext, "LogBackup_Rollback",  LogBackup_Rollback);    

    
    pGetCHProc = (COSAGetCommonHandleProc)pPlugInfo->AcquireFunction("COSAGetDiagPluginInfo");

    if( pGetCHProc != NULL)
    {
        g_pCosaDiagPluginInfo = pGetCHProc(NULL);
    }
    else
    {
        goto EXIT;
    }

    pGetStringProc = (COSAGetParamValueStringProc)pPlugInfo->AcquireFunction("COSAGetParamValueString");

    if( pGetStringProc != NULL)
    {
        g_GetParamValueString = pGetStringProc;
    }
    else
    {
        goto EXIT;
    }

    pGetParamValueUlongProc = (COSAGetParamValueUlongProc)pPlugInfo->AcquireFunction("COSAGetParamValueUlong");

    if( pGetParamValueUlongProc != NULL)
    {
        g_GetParamValueUlong = pGetParamValueUlongProc;
    }
    else
    {
        goto EXIT;
    }

    pValInterfaceProc = (COSAValidateHierarchyInterfaceProc)pPlugInfo->AcquireFunction("COSAValidateHierarchyInterface");

    if ( pValInterfaceProc )
    {
        g_ValidateInterface = pValInterfaceProc;
    }
    else
    {
        goto EXIT;
    }

#ifndef _ANSC_WINDOWSNT
#ifdef _SOFTWAREMODULES_SUPPORT_NAF
    CosaSoftwareModulesInit(hCosaPlugInfo);
#endif
#endif

    pGetRegistryRootFolder = (COSAGetHandleProc)pPlugInfo->AcquireFunction("COSAGetRegistryRootFolder");

    if ( pGetRegistryRootFolder != NULL )
    {
        g_GetRegistryRootFolder = pGetRegistryRootFolder;
    }
    else
    {
        printf("!!! haha, catcha !!!\n");
        goto EXIT;
    }

    pGetInsNumberByIndexProc = (COSAGetInstanceNumberByIndexProc)pPlugInfo->AcquireFunction("COSAGetInstanceNumberByIndex");

    if ( pGetInsNumberByIndexProc != NULL )
    {
        g_GetInstanceNumberByIndex = pGetInsNumberByIndexProc;
    }
    else
    {
        goto EXIT;
    }

    pGetInterfaceByNameProc = (COSAGetInterfaceByNameProc)pPlugInfo->AcquireFunction("COSAGetInterfaceByName");

    if ( pGetInterfaceByNameProc != NULL )
    {
        g_GetInterfaceByName = pGetInterfaceByNameProc;
    }
    else
    {
        goto EXIT;
    }

    g_pTadCcdIf = g_GetInterfaceByName(g_pDslhDmlAgent, CCSP_CCD_INTERFACE_NAME);

    if ( !g_pTadCcdIf )
    {
        CcspTraceError(("g_pTadCcdIf is NULL !\n"));

        goto EXIT;
    }

    /* Get Message Bus Handle */
    g_GetMessageBusHandle = (PFN_CCSPCCDM_APPLY_CHANGES)pPlugInfo->AcquireFunction("COSAGetMessageBusHandle");
    if ( g_GetMessageBusHandle == NULL )
    {
        goto EXIT;
    }

    g_MessageBusHandle = (ANSC_HANDLE)g_GetMessageBusHandle(g_pDslhDmlAgent);
    if ( g_MessageBusHandle == NULL )
    {
        goto EXIT;
    }
    g_MessageBusHandle_Irep = g_MessageBusHandle;

    g_GetSubsystemPrefix = (COSAGetSubsystemPrefixProc)pPlugInfo->AcquireFunction("COSAGetSubsystemPrefix");
    if ( g_GetSubsystemPrefix != NULL )
    {
        char*  tmpSubsystemPrefix;

        if ( tmpSubsystemPrefix = g_GetSubsystemPrefix(g_pDslhDmlAgent) )
        {
            AnscCopyString(g_SubSysPrefix_Irep, tmpSubsystemPrefix);
        }
    }

    /* Create backend framework */
    g_pCosaBEManager = (PCOSA_BACKEND_MANAGER_OBJECT)CosaBackEndManagerCreate();

    if ( g_pCosaBEManager && g_pCosaBEManager->Initialize )
    {
        g_pCosaBEManager->hCosaPluginInfo = pPlugInfo;

        g_pCosaBEManager->Initialize   ((ANSC_HANDLE)g_pCosaBEManager);
    }

    if (diag_init() != DIAG_ERR_OK)
        goto EXIT;

    return  0;

EXIT:

    return -1;

}
int main(void) {

	// clock init
	clock_init();

	// two timers for tcp/ip
	timer_set(&periodic_timer, CLOCK_SECOND / 2); /* 0.5s */
	timer_set(&arp_timer, CLOCK_SECOND * 10);	/* 10s */

	diag_init();

	// ethernet init
	tapdev_init();

	// Initialize the uIP TCP/IP stack.
	uip_init();

	uip_ipaddr(ipaddr, MYIP1,MYIP2,MYIP3,MYIP4);
	uip_sethostaddr(ipaddr);
	uip_ipaddr(ipaddr, DRTR1,DRTR2,DRTR3,DRTR4);
	uip_setdraddr(ipaddr);
	uip_ipaddr(ipaddr, SMSK1, SMSK2, SMSK3, SMSK4);
    uip_setnetmask(ipaddr);

	bl_init();

	while(1)
	{
		diag_appcall();
		bl_appcall();

		/* receive packet and put in uip_buf */
		uip_len = tapdev_read(uip_buf);
    	if(uip_len > 0)		/* received packet */
    	{
      		if(BUF->type == htons(UIP_ETHTYPE_IP))	/* IP packet */
      		{
	      		uip_arp_ipin();
	      		uip_input();
	      		/* If the above function invocation resulted in data that
	         		should be sent out on the network, the global variable
	         		uip_len is set to a value > 0. */

	      		if(uip_len > 0)
        		{
	      			uip_arp_out();
	        		tapdev_send(uip_buf,uip_len);
	      		}
      		}
	      	else if(BUF->type == htons(UIP_ETHTYPE_ARP))	/*ARP packet */
	      	{
	        	uip_arp_arpin();
		      	/* If the above function invocation resulted in data that
		         	should be sent out on the network, the global variable
		         	uip_len is set to a value > 0. */
		      	if(uip_len > 0)
	        	{
		        	tapdev_send(uip_buf,uip_len);	/* ARP ack*/
		      	}
	      	}
    	}
    	else if(timer_expired(&periodic_timer))	/* no packet but periodic_timer time out (0.5s)*/
    	{
      		timer_reset(&periodic_timer);

      		for(i = 0; i < UIP_CONNS; i++)
      		{
      			uip_periodic(i);
		        /* If the above function invocation resulted in data that
		           should be sent out on the network, the global variable
		           uip_len is set to a value > 0. */
		        if(uip_len > 0)
		        {
		          uip_arp_out();
		          tapdev_send(uip_buf,uip_len);
		        }
      		}
#if UIP_UDP
			for(i = 0; i < UIP_UDP_CONNS; i++) {
				uip_udp_periodic(i);
				/* If the above function invocation resulted in data that
				   should be sent out on the network, the global variable
				   uip_len is set to a value > 0. */
				if(uip_len > 0) {
				  uip_arp_out();
				  tapdev_send(uip_buf,uip_len);
				}
			}
#endif /* UIP_UDP */
	     	/* Call the ARP timer function every 10 seconds. */
			if(timer_expired(&arp_timer))
			{
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
    	}


	}
	return 0 ;
}
Пример #8
0
int main(int argc, char *argv[])
{
	int c;
	int n = 0;
	int r = EXIT_FAILURE;
	char *in = NULL;

	diag_init();

	while ( (c = getopt(argc, argv, "+Vhi:n:")) >=0) {
		switch (c) {
		case 'V':
			diag_print_version();
			exit(EXIT_SUCCESS);
			break;
		case 'h':
			usage();
			exit(EXIT_SUCCESS);
			break;
		case 'i':
			in = optarg;
			break;
		case 'n':
			n = atoi(optarg);
			if (n < 0) {
				diag_fatal("non-negative integer expected, but %d", n);
			} else if (n == 0) {
				exit(EXIT_SUCCESS);
			}
			break;
		case ':':
		case '?':
			usage();
			exit(EXIT_FAILURE);
			break;
		}
	}
	if (!argv[optind]) {
		usage();
		exit(EXIT_FAILURE);
	}
	if (n == 0) {
		diag_fatal("please specify the number with the -n option");
	}

	char *tfin = NULL;
	if (!in) {
		struct diag_temporary_file *tf = diag_temporary_file_new();
		if (!tf) {
			return EXIT_FAILURE;
		}
		tfin = diag_strdup(tf->path);
		struct diag_port *ip = diag_port_new_stdin();
		assert(ip);
		ssize_t s = diag_port_copy(ip, tf->port);
		diag_port_destroy(ip);
		diag_temporary_file_destroy(tf);
		if (s < 0) {
			assert(tfin);
			diag_remove(tfin);
			diag_free(tfin);
			return EXIT_FAILURE;
		}
	}

	int i = 0;
	char *file = in ? in : tfin;
	struct diag_command *cmd;
 run:
	cmd = diag_command_new(argv + optind, NULL, file, NULL, NULL);
	if (!cmd) {
		goto done;
	}
	struct diag_process *p = diag_run_program(cmd);
	if (!p) {
		goto done;
	}
	diag_process_wait(p);
	int status = p->status;
	diag_process_destroy(p);
	if (status != 0) {
		r = status;
		goto done;
	}

	assert(cmd->err);
	diag_remove(cmd->err);

	if (i) {
		diag_remove(file);
		diag_free(file);
	} else if (tfin) {
		diag_remove(tfin);
		diag_free(tfin);
		tfin = NULL;
	}

	if (++i < n) {
		file = diag_strdup(cmd->out);
		diag_command_destroy(cmd);
		goto run;
	}

	struct diag_port *ip = diag_port_new_path(cmd->out, "rb");
	if (!ip) {
		goto done;
	}
	struct diag_port *op = diag_port_new_stdout();
	assert(op);
	ssize_t s = diag_port_copy(ip, op);
	diag_port_destroy(op);
	diag_port_destroy(ip);
	if (s < 0) {
		goto done;
	}

	diag_remove(cmd->out);
	r = EXIT_SUCCESS;

 done:
	diag_command_destroy(cmd);
	if (tfin) {
		diag_remove(tfin);
		diag_free(tfin);
	}
	return r;
}