Exemple #1
0
static cairo_pattern_t* gvloadimage_gs_load(GVJ_t * job, usershape_t *us)
{
    gs_t *gs = NULL;
    gsapi_revision_t gsapi_revision_info;
    void *instance;
    int rc;

    assert(job);
    assert(us);
    assert(us->name);

    if (us->data) {
        if (us->datafree == gvloadimage_gs_free
	&& ((gs_t*)(us->data))->cr == (cairo_t *)job->context)
	    gs = (gs_t*)(us->data); /* use cached data */
	else {
	    us->datafree(us);        /* free incompatible cache data */
	    us->data = NULL;
	}
    }
    if (!gs) {
	gs = (gs_t *)malloc(sizeof(gs_t));
	if (!gs) {
	    job->common->errorfn("malloc() failure\n");
	    return NULL;
	}
	gs->cr = (cairo_t *)job->context;
	gs->surface = NULL;
	gs->pattern = NULL;

	/* cache this - even if things go bad below - avoids repeats */
	us->data = (void*)gs;
	us->datafree = gvloadimage_gs_free;

#define GSAPI_REVISION_REQUIRED 863
	rc = gsapi_revision(&gsapi_revision_info, sizeof(gsapi_revision_t));
        if (rc && rc < sizeof(gsapi_revision_t)) {
    	    job->common->errorfn("gs revision - struct too short %d\n", rc);
	    return NULL;
        }
	if (gsapi_revision_info.revision < GSAPI_REVISION_REQUIRED) {
    	    job->common->errorfn("gs revision - too old %d\n",
		gsapi_revision_info.revision);
	    return NULL;
	}

	rc = gsapi_new_instance(&instance, (void*)job);
	if (rc)
	    gs_error(job, us->name, "gsapi_new_instance", rc);
	else {
	    rc = gsapi_set_stdio(instance, NULL, gs_writer, gs_writer);
	    if (rc)
	        gs_error(job, us->name, "gsapi_set_stdio", rc);
	    else
                rc = gvloadimage_process_surface(job, us, gs, instance);
	    gsapi_delete_instance(instance);
	}
    }
    return gs->pattern;
}
Exemple #2
0
/*
 * Compact G-Line store: dump active glines to a new file and remove the
 * current journal.
 * Returns 1 on success, 0 on failure.
 */
int
glinestore_compact(void)
{
    char buf1[512];
    int newfile;

    /* userban.c */
    extern void gs_dumpglines(int);

    if (forked)
        sendto_ops_lev(DEBUG_LEV, "Compacting G-Line store...");
    journalcount = 0;

    /* open a compaction file to dump all active glines to */
    ircsnprintf(buf1, sizeof(buf1), "%s/.glines_c", runpath);
    newfile = open(buf1, O_WRONLY|O_CREAT|O_TRUNC, 0700);
    if (newfile < 0)
    {
        ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to create G-Line"
                    " compaction file .glines_c: %s",
                    strerror(errno));
        gs_error(buf1);
        return 0;
    }

    /* do the dump */
    gs_dumpglines(newfile);
    close(newfile);

    /* close active storage file, rename compaction file, and reopen */
    if (journal >= 0)
    {
        close(journal);
        journal = -1;
    }
    if (rename(buf1, journalfilename) < 0)
    {
        ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to rename G-Line"
                    " compaction file .glines_c to .glines: %s",
                    strerror(errno));
        gs_error(buf1);
        return 0;
    }
    journal = open(journalfilename, O_WRONLY|O_APPEND, 0700);
    if (journal < 0)
    {
        ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to reopen G-Line"
                    " storage file .glines: %s", strerror(errno));
        gs_error(buf1);
        return 0;
    }

    return 1;
}
Exemple #3
0
static int gvloadimage_process_surface(GVJ_t *job, usershape_t *us, gs_t *gs, void *instance)
{
    cairo_t *cr; /* temp cr for gs */
    int rc, rc2;
    char width_height[20], dpi[10], cairo_context[30];
    char *gs_args[] = {
	"dot",      /* actual value of argv[0] doesn't matter */
	"-dQUIET",
	"-dNOPAUSE",
	"-sDEVICE=cairo",
	cairo_context,
	width_height,
	dpi,
    };
#define GS_ARGC sizeof(gs_args)/sizeof(gs_args[0])

    gs->surface = cairo_surface_create_similar( 
	cairo_get_target(gs->cr),
	CAIRO_CONTENT_COLOR_ALPHA,
	us->x + us->w,
	us->y + us->h);

    cr = cairo_create(gs->surface);  /* temp context for gs */

    sprintf(width_height, "-g%dx%d", us->x + us->w, us->y + us->h);
    sprintf(dpi, "-r%d", us->dpi);
    sprintf(cairo_context, "-sCairoContext=%p", cr);

    rc = gsapi_init_with_args(instance, GS_ARGC, gs_args);

    cairo_destroy(cr); /* finished with temp context */

    if (rc)
	gs_error(job, us->name, "gsapi_init_with_args", rc);
    else
	rc = gvloadimage_process_file(job, us, instance);

    if (rc) {
	cairo_surface_destroy(gs->surface);
	gs->surface = NULL;
    }

    rc2 = gsapi_exit(instance);
    if (rc2) {
	gs_error(job, us->name, "gsapi_exit", rc2);
	return rc2;
    }

    if (!rc) 
        gs->pattern = cairo_pattern_create_for_surface (gs->surface);

    return rc;
}
Exemple #4
0
static int gvloadimage_process_file(GVJ_t *job, usershape_t *us, void *instance)
{
    int rc = 0, exit_code;

    if (! gvusershape_file_access(us)) {
	job->common->errorfn("Failure to read shape file\n");
	return -1;
    }
    rc = gsapi_run_file(instance, us->name, -1, &exit_code);
    if (rc) {
	gs_error(job, us->name, "gsapi_run_file", rc);
    }
    gvusershape_file_release(us);
    return rc;
}
Exemple #5
0
/*
 * Initialize G-Line storage.  Pass 1 when glines don't need to be reloaded.
 * Returns 0 on failure, 1 otherwise.
 */
int
glinestore_init(int noreload)
{
    char buf1[1024];
    FILE *jf;

    ircsnprintf(journalfilename, sizeof(journalfilename), "%s/.glines", runpath);

    if (journal >= 0)
    {
        if (noreload)
            return 1;

        close(journal);
        journal = -1;
    }

    /* "a+" to create if it doesn't exist */
    jf = fopen(journalfilename, "a+");
    if (!jf)
    {
        ircsnprintf(buf1, sizeof(buf1), "ERROR: Unable to open G-Line storage"
                    " file .glines: %s", strerror(errno));
        gs_error(buf1);
        return 0;
    }
    rewind(jf);

    /* replay journal */
    while (fgets(buf1, sizeof(buf1), jf))
    {
        char *s = strchr(buf1, '\n');

        /* no newline, consider it malformed and stop here */
        if (!s)
            break;

        *s = 0;

        if (!gs_read(buf1))
            break;
    }

    fclose(jf);

    /* this will reopen the journal for appending */
    return glinestore_compact();
}
/*******************************************************************************
  Module Register API
  */
static int __init fastlogo_driver_init(void)
{
    int res;

    gs_info("drv init\n");

    memset(&fastlogo_ctx, 0, sizeof(fastlogo_ctx));
#if LOGO_PROC_FS
    {
        struct proc_dir_entry *pstat = NULL;
        logo_driver_procdir = proc_mkdir(DEVICE_NAME, NULL);
        pstat = create_proc_entry("stat", 0, logo_driver_procdir);
        if (pstat)
            pstat->proc_fops = &logo_stat_file_ops;
    }
#endif //LOGO_PROC_FS

    fastlogo_ctx.vres = MV_THINVPP_IsCPCBActive(CPCB_1);

    if (!fastlogo_ctx.vres)
    {
        gs_trace("fastlogo is not enabled in bootloader\n");
        return 0; // do nothing if fastlogo is not enabled in bootloader
    }
    if (fastlogo_ctx.vres != 524)
    {
        gs_trace("fastlogo does not supprt vres=%d\n", fastlogo_ctx.vres);
        return 0; // do nothing if vres is not supported
    }

    //console_silent(); // don't want printk to interfere us
    save_console_loglevel = console_loglevel; // to restore console printk
    if (console_loglevel > LIMIT_CONSOLE_LOGLEVEL)
        console_loglevel = LIMIT_CONSOLE_LOGLEVEL;

    /* create PE device */
    res = fastlogo_device_init(CPUINDEX);
    if (res != 0) {
        gs_error("drv init failed !!! res = 0x%08X\n", res);
        return res;
    } else {
        gs_trace("drv init OK\n");
    }

    return 0;
}