Esempio n. 1
0
void* collabclient_new( char* address, int port )
{
#ifdef BUILD_COLLAB

    printf("collabclient_new() address:%s port:%d\n", address, port );
    
    cloneclient_t *cc = 0;
    cc = (cloneclient_t *) zmalloc (sizeof (cloneclient_t));
    cc->magic_number = MAGIC_VALUE;
    cc->ctx   = obtainMainZMQContext();
    cc->loop  = 0;
    cc->address = copy( address );
    cc->port  = port;
    cc->kvmap = zhash_new();
    cc->publisher_sendseq = 1;
    cc->sequence = 0;
    cc->preserveUndo = 0;
    cc->roundTripTimerWaitingSeq = 0;
    collabclient_remakeSockets( cc );

    int32 roundTripTimerMS = pref_collab_roundTripTimerMS;
    cc->roundTripTimer = BackgroundTimer_new( roundTripTimerMS, 
					      collabclient_roundTripTimer,
					      cc );
    
    return cc;

#endif

    return 0;
}
Esempio n. 2
0
void
collabclient_ensureClientBeacon(void)
{
    if( client_beacon )
	return;
    
    peers = g_hash_table_new_full( g_str_hash, g_str_equal, 0, free );
    client_beacon_timerID = 0;
    
    
    client_beacon = zbeacon_new (5670);
    zbeacon_subscribe (client_beacon, NULL, 0);
    int fd = 0;
    size_t fdsz = sizeof(fd);
    int rc = zmq_getsockopt( zbeacon_socket(client_beacon), ZMQ_FD, &fd, &fdsz );
    printf("beacon rc:%d fd:%d\n", rc, fd );
//    GDrawAddReadFD( 0, fd, cc, zeromq_beacon_fd_callback );
    client_beacon_timerID = BackgroundTimer_new( 1000, zeromq_beacon_timer_callback, 0 );
}
Esempio n. 3
0
void
collabclient_sniffForLocalServer( void )
{
#ifdef BUILD_COLLAB

    memset( &collabclient_sniffForLocalServer_singleton, 0,
	    sizeof(collabclient_sniffForLocalServer_t));
    collabclient_sniffForLocalServer_t* cc = &collabclient_sniffForLocalServer_singleton;

    zctx_t* ctx = obtainMainZMQContext();
    int port_default = collabclient_getDefaultBasePort();

    cc->socket = zsocket_new ( ctx, ZMQ_REQ );
    zsocket_connect (cc->socket,
        "tcp://localhost:%d", port_default+socket_offset_ping);
    cc->timer = BackgroundTimer_new( 1000, collabclient_sniffForLocalServer_timer, cc );
    zstr_send  (cc->socket, "ping");

#endif
}
Esempio n. 4
0
void
collabclient_ensureClientBeacon(void)
{
    if( client_beacon )
	return;
    
    peers = g_hash_table_new_full( g_str_hash, g_str_equal, 0, g_free );
    client_beacon_timerID = 0;
    
    
    client_beacon = zbeacon_new( obtainMainZMQContext(), 5670 );
    DEBUG("client beacon address: %s\n", zbeacon_hostname(client_beacon));
    zbeacon_subscribe (client_beacon, NULL, 0);
    zsocket_set_rcvtimeo (zbeacon_socket (client_beacon), 100);
    int fd = 0;
    size_t fdsz = sizeof(fd);
    int rc = zmq_getsockopt( zbeacon_socket(client_beacon), ZMQ_FD, &fd, &fdsz );
//    printf("beacon rc:%d fd:%d\n", rc, fd );
//    GDrawAddReadFD( 0, fd, cc, zeromq_beacon_fd_callback );
    client_beacon_timerID = BackgroundTimer_new( 1000, zeromq_beacon_timer_callback, 0 );
}
Esempio n. 5
0
void collabclient_sessionStart( void* ccvp, FontView *fv )
{
#ifdef BUILD_COLLAB

    cloneclient_t* cc = (cloneclient_t*)ccvp;
    
    //
    // Fire up the fontforge-internal-collab-server process...
    //
    {
	char command_line[PATH_MAX+1];
	
#if defined(__MINGW32__)

	sprintf(command_line, "'%s/ffcollab.bat' %d", getGResourceProgramDir(), cc->port );
	
#else	
	sprintf(command_line,
		"%s/bin/FontForgeInternal/fontforge-internal-collab-server %d",
		getLibexecDir_NonWindows(), cc->port );
#endif	
	printf("command_line:%s\n", command_line );
	GError * error = 0;
	if(!getenv("FONTFORGE_USE_EXISTING_SERVER"))
	{
	    int rc = g_spawn_command_line_async( command_line, &error );
	    if( !rc )
	    {
		fprintf(stderr, "Error starting collab server\n");
		if( error )
		    fprintf(stderr, "code:%d message:%s\n", error->code, error->message );
	    }
	}
    }
    
    printf("Starting a session, sending it the current SFD as a baseline...\n");
    if( !ff_uuid_isValid( fv->b.sf->collab_uuid))
	ff_uuid_generate( fv->b.sf->collab_uuid );
    strcpy( cc->unacknowledged_beacon_uuid, fv->b.sf->collab_uuid );
    time( &cc->unacknowledged_beacon_sendTime );

    
    int s2d = 0;
    char filename[PATH_MAX];
    snprintf(filename, PATH_MAX, "%s/fontforge-collab-start-%d.sfd", getTempDir(), getpid());
    int ok = SFDWrite(filename,fv->b.sf,fv->b.map,fv->b.normal,s2d);
    printf("connecting to server...3 ok:%d\n",ok);
    if ( ok )
    {
	char* sfd = GFileReadAll( filename );
	printf("connecting to server...4 sfd:%p\n", sfd );
	collabclient_sendSFD( cc, sfd, fv->b.sf->collab_uuid, fv->b.sf->fontname );
    }
    GFileUnlink(filename);
    printf("connecting to server...sent the sfd for session start.\n");
    fv->b.collabState = cs_server;
    FVTitleUpdate( &fv->b );

    collabclient_setHaveLocalServer( 1 );

    beacon_moon_bounce_timerID = BackgroundTimer_new( 3000, beacon_moon_bounce_timer_callback, cc );

    collabclient_notifySessionJoining( cc, (FontViewBase*)fv );
#endif
}