// IShellIconOverlayIdentifier::GetOverlayInfo
// returns The Overlay Icon Location to the system
STDMETHODIMP CACloudSyncedRF::GetOverlayInfo(
             LPWSTR pwszIconFile,
             int cchMax,
             int* pIndex,
             DWORD* pdwFlags)
{
	TCHAR logPath[MAX_PATH];
	char logPathChar[MAX_PATH];
	int result = ShlExtUtility::GetLogDirectory(logPath);
	
	if (result == 0 ) {
		result = ShlExtUtility::ConvertFromTString(logPath, logPathChar, MAX_PATH);
		if (result == 0) {
			LOGInit("pc_shellext", logPathChar);
			int loglevel = ShlExtUtility::SetLogLevel();
			LOG_INFO("logDirectoryString: %s, loglevel: %d", logPathChar, loglevel);
		}
	}

	lastRecordedTime = NULL;

	// Get our module's full path
	GetModuleFileNameW(_AtlBaseModule.GetModuleInstance(), pwszIconFile, cchMax);

	// Use first icon in the resource
	*pIndex=0; 
	*pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;

	return S_OK;
}
Beispiel #2
0
static void LogInit(void) {
    
    syscon_ahb_enable(SYSCON_CLK_IOCON);
    LPC_IOCON->PIO1_6 |= (IOCON_FUNC1 | IOCON_MODE_PULLUP);
    LPC_IOCON->PIO1_7 |= (IOCON_FUNC1 | IOCON_MODE_PULLUP);
    
    LOGInit();
    SYSLOG("The System Start Up[%s %s]\r\n", __DATE__, __TIME__);

}
int main(int argc, char *argv[])
{
    LOGInit("HttpStringStreamTester", NULL);
    LOGSetMax(0);

    VPL_Init();

    HttpStringStreamTester t;
    t.RunTests();

    exit(0);
}
int main(int argc, char ** argv)
#endif
{
#ifndef VPL_PLAT_IS_WINRT
    LOGInit("test_ccd_sync", NULL);
    LOGSetMax(0); // No limit
#endif
    LOG_DISABLE_LEVEL(LOG_LEVEL_DEBUG);
    VPL_Init();
    LOG_INFO("TC_RESULT=PASS ;;; TC_NAME=old_ccd_sync_test(Deprecated)\n");
    return 0;
}
int main(int argc, char** argv)
{
    LOGInit("ccd_link_device", NULL);
    LOGSetMax(0);       // No limit
    int rv;
    {
        rv = CCDITest_SetupCcdiTest();
        if (rv != 0) {
            LOG_ERROR("CCDITest_SetupCcdiTest failed: %d", rv);
            goto out;
        }
        u64 userId = 0;
        {
            ccd::GetSystemStateInput req;
            req.set_get_players(true);
            ccd::GetSystemStateOutput resp;
            rv = CCDIGetSystemState(req, resp);
            if (rv != 0) {
                LOG_ERROR("CCDIGetSystemState failed: %d", rv);
                goto out;
            } else {
                userId = resp.players().players(0).user_id();
            }
        }
        if (argc >= 2) {
            LOG_INFO("Linking device");
            ccd::LinkDeviceInput req;
            req.set_user_id(userId);
            req.set_device_name(argv[1]);
            req.set_is_acer_device((argc > 2));
            rv = CCDILinkDevice(req);
            if (rv != 0) {
                LOG_ERROR("CCDILinkDevice failed: %d", rv);
                goto out;
            }
        } else {
            LOG_INFO("Unlinking device");
            ccd::UnlinkDeviceInput req;
            req.set_user_id(userId);
            rv = CCDIUnlinkDevice(req);
            if (rv != 0) {
                LOG_ERROR("CCDIUnlinkDevice failed: %d", rv);
                goto out;
            }
        }
    }
out:
    // Since the return code usually ends up "mod 256", remap it to avoid ever returning 0 when
    // something actually failed.
    return (rv == 0) ? 0 : 255;
}
Beispiel #6
0
int main (int argc, char **argv) 
{
    const char * option_serialport = "/dev/gprs";
    SerialPort * sp;
    speed_t option_baud = B57600;
	int b;
	int count = MAXATTEMPTS;
	int restartcount =  MAXRESTARTCOUNT;

    LOGInit(GWT_STDERR, GWL_INFO, "Glacsweb gsmat");


    // set up rs232
    sp = initialise(option_serialport, option_baud);
    
    if (sp == NULL) {
        return 1;
    }


if( SERPutString(sp,"at\n\r") == 0) {
	while(restartcount--){
		while(count--){
			b = SERGetByteTimeout(sp,2000000);
			if( b == -1){
				printf("timed out\n");
				if( SERPutString(sp,"at\n") == 0) {
					printf("put AT\n");
				}else{
					printf("put failed\n");
				}
			}else{
				printf("got: %d after %d attempts %d powercycles\n", b, MAXATTEMPTS - count, MAXRESTARTCOUNT - restartcount);
				SERFlushChannel(sp,100000);
				return(0);
				}
			}
		system("/home/root/scripts/gprs-off"); // Change path here to migrage to
                                                //different system
		usleep(5000000);
		system("/home/root/scripts/gprs-on");
		usleep(30000000);
		}
	}
else {
	printf("failed to send AT\n");
	return(-2);
	}
return(1);
}
int main(int argc, char** argv)
{
    LOGInit("ccd_register_storage_node", NULL);
    LOGSetMax(0);
    int rv;
    {
        rv = CCDITest_SetupCcdiTest();
        if (rv != 0) {
            LOG_ERROR("CCDITest_SetupCcdiTest failed: %d", rv);
            goto out;
        }
        u64 userId = 0;
        {
            ccd::GetSystemStateInput req;
            req.set_get_players(true);
            ccd::GetSystemStateOutput resp;
            rv = CCDIGetSystemState(req, resp);
            if (rv != 0) {
                LOG_ERROR("CCDIGetSystemState failed: %d", rv);
                goto out;
            } else {
                userId = resp.players().players(0).user_id();
            }
        }
        if (argc >= 2) {
            LOG_INFO("Registering StorageNode");
            ccd::RegisterStorageNodeInput req;
            req.set_user_id(userId);
            rv = CCDIRegisterStorageNode(req);
            if (rv != 0) {
                LOG_ERROR("CCDIRegisterStorageNode failed: %d", rv);
                goto out;
            }
        } else {
            LOG_INFO("Unregistering StorageNode");
            ccd::UnregisterStorageNodeInput req;
            req.set_user_id(userId);
            rv = CCDIUnregisterStorageNode(req);
            if (rv != 0) {
                LOG_ERROR("CCDIUnregisterStorageNode failed: %d", rv);
                goto out;
            }
        }
    }
out:
    // Since the return code usually ends up "mod 256", remap it to avoid ever returning 0 when
    // something actually failed.
    return (rv == 0) ? 0 : 255;
}
int main (int argc, char **argv)
{
    LOGInit (argv[0], 0);
    VPL_Init();

    is_active = true;
    
    db::object database;
    sync::info sync_info;

    task::processor tasks;
    event::processor events;

    events.default_handler (event::sleep_type, new exit_on_sleep);
    events.default_handler (event::panic_type, new exit_on_panic);
    events.default_handler (event::warn_type, new print_on_warn);
    
    events.listen (event::wake_type, new setup_database_on_wake (database));
    events.listen (event::wake_type, new setup_ccd_on_wake (sync_info));
    events.listen (event::synced_type, new index_path_on_synced (database, sync_info.path));
    events.listen (event::job_type, new enqueue_jobs (tasks));

    events.listen (event::command_type, new command::user_interface (database, sync_info.path));

    command_line_thread input (events);
    ccd_notification_thread notify (events);

    events.enqueue (new event::wake);
    events.enqueue (new event::synced);

    while (is_active)
    {
        events.dispatch ();

        if (!tasks.execute ())
        {
            events.enqueue (new event::warn (tasks.log.errors.str ()));
            tasks.log.errors.clear();
        }
    }

    VPL_Quit();

    return 0;
}
int main(int argc, char *argv[])
{
    LOGInit("TestSyncDownJobs", NULL);
    LOGSetMax(0);
    LOG_DISABLE_LEVEL(LOG_LEVEL_DEBUG);

    VPL_Init();

    if (argc < 2) {
        std::cerr << "Usage: " << argv[0] << " workdir" << std::endl;
        exit(0);
    }
    std::string workdir = argv[1];

    TestSyncDownJobs tsdj(workdir);
    tsdj.RunTests();

    exit(0);
}
int
main(int argc, char **argv)
{
    char *  region           = (char *) getenv("region"         );

    char *  client_user      = (char *) getenv("client_user"    );
    char *  client_device    = (char *) getenv("client_device"  );

    char *  server_user      = (char *) getenv("server_user"    );
    char *  server_device    = (char *) getenv("server_device"  );
    char *  server_instance  = (char *) getenv("server_instance");
    char *  server_ans_blob  = (char *) getenv("ans_blob"       );
    char *  server_ans_key   = (char *) getenv("ans_key"        );

    //pxd_declare_t   declare;  // TODO:  remove

    pxd_open_t      open_client;
    pxd_id_t        client_id;
    pxd_cred_t      client_creds;
    pxd_client_t *  client;

    pxd_open_t      open_server;
    pxd_id_t        server_id;
    pxd_cred_t      server_creds;
    ans_client_t *  ans_client;

    pxd_cred_t      connect_creds;
    pxd_connect_t   connect;
    pxd_error_t     error;
    mtwist_t        mt;
    //int             lookup_result;
    int             tries;
    //int             lookup_tries;
    int             connect_tries;
    uint32_t        seed;

    LOGInit("pxd_triangle", null);

    pxd_host = (char *) getenv("pxd_host");
    ans_host = (char *) getenv("ans_host");

    if (pxd_host == null || ans_host == null || region == null) {
        printf("pxd_host, ans_host, and region must be set.\n");
        exit(1);
    }

    if (client_user == null || client_device == null) {
        printf("client_user and client_device must be set.\n");
        exit(1);
    }

    if (server_user == null || server_device == null || server_instance == null) {
        printf("server_user, server_device, and server_instance must be set.\n");
        exit(1);
    }

    if (server_ans_blob == null || server_ans_key == null) {
        printf("ans_blob and ans_key must be set.\n");
        exit(1);
    }

    seed = VPLTime_GetTime() ^ getpid();

    mtwist_init(&mt, seed);

    /*
     *  Set up the structures for opening a client connection.
     */
    memset(&open_client,  0, sizeof(open_client ));
    memset(&client_creds, 0, sizeof(client_creds));
    memset(&client_id,    0, sizeof(client_id   ));

    open_client.cluster_name                  = pxd_host;
    open_client.credentials                   = &client_creds;
    open_client.credentials->id               = &client_id;
    open_client.credentials->key              = client_key;
    open_client.credentials->key_length       = sizeof(client_key);
    open_client.credentials->id->region       = region;
    open_client.credentials->id->instance_id  = (char *) "CCD-client";
    open_client.credentials->key              = client_key;
    open_client.credentials->key_length       = sizeof(client_key);

    /*
     *  Now open the client CCD connection.
     */
    client = do_open(&open_client, client_user, client_device, false);
    free(open_client.credentials->opaque);
    open_client.credentials->opaque = null;

    /*
     *  Okay, open the server CCD connection.
     */
    server_info = &open_server;

    memset(&open_server,  0, sizeof(open_server ));
    memset(&server_creds, 0, sizeof(server_creds));
    memset(&server_id,    0, sizeof(server_id   ));

    open_server.cluster_name                  = pxd_host;
    open_server.credentials                   = &server_creds;
    open_server.credentials->id               = &server_id;
    open_server.credentials->key              = server_key;
    open_server.credentials->key_length       = sizeof(server_key);
    open_server.credentials->id->region       = region;
    open_server.credentials->id->instance_id  = server_instance;
    open_server.credentials->key              = server_key;
    open_server.credentials->key_length       = sizeof(server_key);

    server = do_open(&open_server, server_user, server_device, true );
    free(open_server.credentials->opaque);

    open_server.credentials->opaque = null;

    if (client == null || server == null) {
        error("A pxd_open operation failed.\n");
        exit(1);
    }

    ans_client = open_ans(open_server.credentials, ans_host, server_ans_blob, server_ans_key);

    VPLThread_Sleep(VPLTime_FromMillisec(1000));

    /*
     *  Declare the server CCD to the PXD demon.
     */
    /*memset(&declare,    0, sizeof(declare   ));
    memset(&ip_address, 0, sizeof(ip_address));

    declare.ans_dns                  = ans_host;
    declare.pxd_dns                  = pxd_host;
    declare.address_count            = 1;
    declare.addresses[0].ip_address  = ip_address;  // not used
    declare.addresses[0].ip_length   = sizeof(ip_address);
    declare.addresses[0].port        = 8;

    pxd_declare(server, &declare, &error);

    if (error.error != 0) {
        error("pxd_declare failed:  %s.\n", error.message);
        exit(1);
    }*/

    /*
     *  Now try a lookup of the server CCD on the CCD client side.
     *  The lookup should cause PXD to send a server wakeup message
     *  to the server side.
     */
    /*lookup_tries = 4;

    log("Starting the pxd_lookup attempts.\n");

    do {
        lookup_result = -1;

        pxd_lookup(client, &server_id, &lookup_result, &error);

        if (error.error != 0) {
            error("pxd_lookup failed:  %s.\n", error.message);
            exit(1);
        }

        tries = 40;

        while (lookup_result < 0 && tries-- > 0) {
            VPLThread_Sleep(VPLTime_FromMillisec(100));
        }

        if (lookup_result != pxd_op_successful) {
            sleep(1);
        }
    } while (lookup_tries-- > 0 && lookup_result != pxd_op_successful);

    if (lookup_result != pxd_op_successful) {
        error("pxd_lookup failed:  %s (%d).\n",
            pxd_string(lookup_result), (int) lookup_result);
        exit(1);
    }*/

    /*
     *  Start the connection attempt.
     */
    memset(&connect,       0, sizeof(connect      ));
    memset(&connect_creds, 0, sizeof(connect_creds));

    connect.target                  = server_info->credentials->id;
    connect.creds                   = &connect_creds;
    connect.pxd_dns                 = lookup_host;
    connect.creds->id               = &client_id;
    connect.creds->key              = session_key;
    connect.creds->key_length       = sizeof(session_key);

    make_ccd_creds(connect.target, connect.creds);

    /*
     *  Now add the address.  It's not used yet, so its content is irrelevant,
     *  and I might not even need to set it.
     */
    connect.address_count           = 1;
    connect.addresses[0].ip_address = saved_address;
    connect.addresses[0].ip_length  = saved_length;
    connect.addresses[0].port       = 7000;

    connect_tries = 3;

    do {
        connect_finished = false;
        log("calling pxd_connect\n");

        pxd_connect(client, &connect, &error);

        if (error.error != 0) {
            error("pxd_connect failed:  %s.\n", error.message);
            exit(1);
        }

        /*
         *  The connection setup might be done on the server, with
         *  some look. So start trying receive operations.  We don't
         *  have ANS providing synchronization, so we need to give
         *  it a few shots.
         */
        tries = 10;

        while ((!connect_finished || incoming_logins == 0) && tries-- > 0) {
            sleep(1);
        }

        if (!connect_finished) {
            error("The proxy connection operation didn't complete.\n");
            exit(1);
        }

        log(" === A connect operation completed.\n");
    } while (!connect_passed && connect_tries-- > 0);

    tries = 5;

    free(connect.creds->opaque);
    connect.creds->opaque = null;

    while (incoming_logins == 0 && tries-- > 0) {
        sleep(1);
    }

    /*
     *  At this point, we should have received the callback for the
     *  connection attempt and an incoming login.
     */
    if (!connect_passed || incoming_logins == 0) {
        error("The proxy connection operation didn't complete or didn't pass.\n");
        error("connect_finished:  %d, connect_passed %d, incoming_logins %d\n",
              (int) connect_finished, (int) connect_passed, (int) incoming_logins);
        exit(1);
    }

    log(" === The connect operation succeeded.\n");

    pxd_close(&client, true, &error);

    if (error.error != 0) {
        error("The client close failed:  %s.\n", error.message);
        exit(1);
    }

    pxd_close(&server, true, &error);

    if (error.error != 0) {
        error("The server close failed:  %s.\n", error.message);
        exit(1);
    }

    ans_close(ans_client, true);
    free(lookup_host);
    pxd_free_address(&server_address);

    sleep(1);   // Wait for the threads to exit (we hope)
    printf("The pxd triangle test passed.\n");
    return 0;
}
Beispiel #11
0
//------------------------------------------------------------------------
void _cdecl FP_FILELog(LPCSTR msg,...)
{
	FILE   *f;
	BOOL    first;
	va_list argptr;
	char    str[3000],*m;
	DWORD   err = GetLastError();

	if(!msg) return;

	first = LOGInit();
	EnterCriticalSection(&PLOG_cs);
	m = (char*)FP_GetLogFullFileName();
	f = (m && *m) ? fopen(m,first?"w":"a") : NULL;

	if(f)
	{
		//Time
		static SYSTEMTIME stOld = { 0 };
		SYSTEMTIME st;
		GetLocalTime(&st);
		fprintf(f,"%4d.%02d.%02d %02d:%02d:%02d:%04d ",
		        st.wYear, st.wMonth,  st.wDay,
		        st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);

		if(!stOld.wYear)
			fprintf(f,"---- ");
		else
			fprintf(f,"%04d ",
			        (st.wSecond-stOld.wSecond)*1000 + (st.wMilliseconds-stOld.wMilliseconds));

		stOld = st;

		//Error
		if(FP_LogErrorStringLength)
		{
			SetLastError(err);
			StrCpy(str,__WINError(),FP_LogErrorStringLength);

			if((m=strchr(str,'\n')) != NULL) *m = 0;

			if((m=strchr(str,'\r')) != NULL) *m = 0;

			fprintf(f,"%-*s->",FP_LogErrorStringLength,str);
		}
		else
			fprintf(f,"->");

		//Message
		StrCpy(str,msg,sizeof(str));

		if((m=strchr(str,'\n')) != NULL) *m = 0;

		if((m=strchr(str,'\r')) != NULL) *m = 0;

		va_start(argptr, msg);
		vfprintf(f,str,argptr);
		va_end(argptr);
		//EOL
		fprintf(f,"\n");
		fclose(f);
	}

	LeaveCriticalSection(&PLOG_cs);
	SetLastError(err);
}
Beispiel #12
0
int
main(int argc, char **argv)
{
    bool retVal;

    gboolean debug = FALSE;
    gboolean fake_battery = FALSE;
    gboolean visual_leds_suspend = FALSE;
    gboolean verbose = FALSE;
    gboolean err_on_crit = FALSE;
    gboolean fasthalt = FALSE;
    gint maxtemp = 0;
    gint temprate = 0;


    GOptionEntry entries[] = {
        {"debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "turn debug logging on", NULL},
        {"use-fake-battery", 'b', 0, G_OPTION_ARG_NONE, &fake_battery, "Use fake battery", NULL},
        {"visual-leds-suspend", 'l', 0, G_OPTION_ARG_NONE, &visual_leds_suspend, "Use LEDs to show wake/suspend state", NULL},
        {"verbose-syslog", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Use Verbose syslog output", NULL},
        {"error-on-critical", 'e', 0, G_OPTION_ARG_NONE, &err_on_crit, "Crash on critical error", NULL},
        {"maxtemp", 'M', 0, G_OPTION_ARG_INT, &maxtemp, "Set maximum temperature before shutdown (default 60)", NULL},
        {"temprate", 'T', 0, G_OPTION_ARG_INT, &temprate, "Expected maxiumum temperature slew rate (default 12)", NULL},
        {"fasthalt", 'F', 0, G_OPTION_ARG_NONE, &fasthalt, "On overtemp, shut down quickly not cleanly", NULL},
        { NULL }
    };

    GError *error = NULL;
    GOptionContext *ctx;
    ctx = g_option_context_new(" - power daemon");
    g_option_context_add_main_entries(ctx, entries, NULL);
    if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
        g_critical("option parsing failed: %s", error->message);
        exit(1);
    }

    // FIXME integrate this into TheOneInit()
    LOGInit();
    LOGSetHandler(LOGSyslog);

    if (debug) {
        powerd_debug = true;

        LOGSetLevel(G_LOG_LEVEL_DEBUG);
        LOGSetHandler(LOGGlibLog);
    }
   
    signal(SIGTERM, term_handler);
    signal(SIGINT, term_handler);

    if (!g_thread_supported ()) g_thread_init (NULL);

    mainloop = g_main_loop_new(NULL, FALSE);

    /**
     *  initialize the lunaservice and we want it before all the init
     *  stuff happening.
     */
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSRegisterPalmService("com.palm.power", &psh, &lserror);
    if (!retVal)
    {
        goto ls_error;
    }

    retVal = LSGmainAttachPalmService(psh, mainloop, &lserror);
    if (!retVal)
    {
        goto ls_error;
    }

    private_sh = LSPalmServiceGetPrivateConnection(psh);

    /**
     * Calls the init functions of all the modules in priority order.
     */
    TheOneInit();

    g_main_loop_run(mainloop);

end:
    g_main_loop_unref(mainloop);

    // save time before quitting...
    timesaver_save();

    return 0;
ls_error:
    g_critical("Fatal - Could not initialize powerd.  Is LunaService Down?. %s",
        lserror.message);
    LSErrorFree(&lserror);
    goto end;
}
Beispiel #13
0
int
main(int argc, char **argv)
{
    bool retVal;

    // FIXME integrate this into TheOneInit()
    LOGInit();
    LOGSetHandler(LOGSyslog);

    signal(SIGTERM, term_handler);
    signal(SIGINT, term_handler);

    if (!g_thread_supported ()) g_thread_init (NULL);

    mainloop = g_main_loop_new(NULL, FALSE);

    /**
     *  initialize the lunaservice and we want it before all the init
     *  stuff happening.
     */
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSRegisterPalmService("com.palm.sleep", &psh, &lserror);
    if (!retVal)
    {
        goto ls_error;
    }

    retVal = LSGmainAttachPalmService(psh, mainloop, &lserror);
    if (!retVal)
    {
        goto ls_error;
    }

    private_sh = LSPalmServiceGetPrivateConnection(psh);

    retVal = LSCall(private_sh,"luna://com.palm.lunabus/signal/addmatch","{\"category\":\"/com/palm/power\","
              "\"method\":\"USBDockStatus\"}", ChargerStatus, NULL, NULL, &lserror);
    if (!retVal) {
		SLEEPDLOG(LOG_CRIT,"Error in registering for luna-signal \"chargerStatus\"");
		goto ls_error;
	}

 	int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem);
 	if(ret != NYX_ERROR_NONE)
 	{
 		SLEEPDLOG(LOG_CRIT,"Sleepd: Unable to open the nyx device system");
 		abort();
 	}


    TheOneInit();

 	LSCall(private_sh,"luna://com.palm.power/com/palm/power/chargerStatusQuery","{}",ChargerStatus,NULL,NULL,&lserror);

    SLEEPDLOG(LOG_INFO,"Sleepd daemon started\n");

    g_main_loop_run(mainloop);

end:
    g_main_loop_unref(mainloop);

     return 0;
ls_error:
	SLEEPDLOG(LOG_CRIT,"Fatal - Could not initialize sleepd.  Is LunaService Down?. %s",
        lserror.message);
    LSErrorFree(&lserror);
    goto end;
}
int _tmain(int argc, _TCHAR* argv[])
{
    LOGInit("ccdi_client_sanity_test", "C:\\temp\\igware");
    LOGSetMax(0); // no limit
    //LOGSetWriteToStdout(VPL_FALSE);
    LOG_INFO("START"); 

    VPL_RegisterDebugCallback(debugCallback);

    int rv;

    {
        ccd::GetInfraHttpInfoInput request;
        request.set_service(ccd::INFRA_HTTP_SERVICE_OPS);
        request.set_secure(true);
        ccd::GetInfraHttpInfoOutput response;
        rv = CCDIGetInfraHttpInfo(request, response);
        printf("CCDIGetInfraHttpInfo returned %d\n", rv);
        if (rv < 0) {
            goto end;
        }
        printf("  prefix: %s\n", response.url_prefix().c_str());
    }
    u64 userId = 0;
    {
        ccd::LoginInput request;
        request.set_user_name(USERNAME);
        request.set_password(PASSWORD);
        ccd::LoginOutput response;
        rv = CCDILogin(request, response);
        printf("CCDILogin returned %d\n", rv);
        if (rv < 0) {
            goto end;
        }
        userId = response.user_id();
        printf("  userId: "FMT_VPLUser_Id_t"\n", userId);
    }
    {
        ccd::GetInfraHttpInfoInput request;
        request.set_service(ccd::INFRA_HTTP_SERVICE_OPS);
        request.set_secure(true);
        request.set_user_id(userId);
        ccd::GetInfraHttpInfoOutput response;
        rv = CCDIGetInfraHttpInfo(request, response);
        printf("CCDIGetInfraHttpInfo returned %d\n", rv);
        if (rv < 0) {
            goto end;
        }
        printf("  prefix: %s\n", response.url_prefix().c_str());
    }
    rv = CallGetSyncState(userId);
    if (rv < 0) {
        goto end;
    }
    {
        ccd::LinkDeviceInput request;
        request.set_user_id(userId);
        request.set_is_acer_device(true);
        request.set_device_name("My test PC");
        rv = CCDILinkDevice(request);
        printf("CCDILinkDevice returned %d\n", rv);
        if (rv < 0) {
            goto end;
        }
    }
    {
        ccd::ListLinkedDevicesInput request;
        request.set_user_id(userId);
        ccd::ListLinkedDevicesOutput response;
        rv = CCDIListLinkedDevices(request, response);
        printf("CCDIListLinkedDevices returned %d\n", rv);
        if (rv < 0){
            goto end;
        }
        printf("response (%d):\n----\n%s----\n", response.devices_size(), response.DebugString().c_str());
    }
    VPLThread_Sleep(VPLTime_FromSec(3));
    {
        ccd::ListLinkedDevicesInput request;
        request.set_user_id(userId);
        ccd::ListLinkedDevicesOutput response;
        rv = CCDIListLinkedDevices(request, response);
        printf("CCDIListLinkedDevices returned %d\n", rv);
        if (rv < 0){
            goto end;
        }
        printf("response (%d):\n----\n%s----\n", response.devices_size(), response.DebugString().c_str());
    }
    {
        ccd::ListOwnedDatasetsInput request;
        request.set_user_id(userId);
        ccd::ListOwnedDatasetsOutput response;
        rv = CCDIListOwnedDatasets(request, response);
        printf("CCDIListOwnedDatasets returned %d\n", rv);
        if (rv < 0){
            goto end;
        }
        for (int i = 0; i < response.dataset_details_size(); i++) {
            ccd::GetDatasetDirectoryEntriesInput request2;
            u64 datasetId = response.dataset_details(i).datasetid();
            if (i == 0) {
                ccd::AddSyncSubscriptionInput request3;
                request3.set_user_id(userId);
                request3.set_dataset_id(datasetId);
                request3.set_subscription_type(ccd::SUBSCRIPTION_TYPE_NORMAL);
                rv = CCDIAddSyncSubscription(request3);
                printf("CCDIAddSyncSubscription returned %d\n", rv);
            }
            request2.set_dataset_id(datasetId);
            request2.set_user_id(userId);
            request2.set_directory_name("/");
            ccd::GetDatasetDirectoryEntriesOutput response2;
            rv = CCDIGetDatasetDirectoryEntries(request2, response2);
            printf("CCDIGetDatasetDirectoryEntries returned %d\n", rv);
            if (rv < 0){
                goto end;
            }
            for (int j = 0; j < response2.entries_size(); j++) {
                printf("  dataset[%d]("FMTx64")[%d] = %s%s\n",
                    i, datasetId, j,
                    response2.entries(j).name().c_str(),
                    (response2.entries(j).is_dir() ? "/" : ""));
            }
        }
    }

end:
    {
        ccd::LogoutInput request;
        int logoutErr = CCDILogout(request);
        printf("CCDILogout returned %d\n", logoutErr);
    }
    return (rv != 0);
}