Пример #1
0
static const gchar*
language_support_get_signal_parameter (const gchar* type_name, GList** names)
{
    const gchar* c;
    const gchar* param_name = NULL;
    GString* param_string;
    gchar* real_name;
    /* Search for the second upper character */
    for (c = type_name + 1; *c != '\0'; c++)
    {
        if (g_ascii_isupper (*c))
        {
            param_name = c;
            break;
        }
    }
    if (param_name && strlen (param_name))
    {
        param_string = g_string_new (param_name);
        g_string_ascii_down (param_string);
    }
    else
    {
        param_string = g_string_new ("arg");
    }
    real_name = language_support_check_param_name (g_string_free (param_string, FALSE), names);

    return real_name;
}
int main (int argc, char **argv)
{
	RsvgDimensionData dimensions;
	RsvgHandle *logo_handle;
	cairo_surface_t *surface;
	GError *error = NULL;
	cairo_t *cr;
	cairo_status_t status;
	char *input, *size, *output;
	GString *layer;
	char *layer_name;
	int h, w;

	g_type_init ();

	input = argv[1];
	size = argv[2];
	layer = g_string_new (argv[3]);
	g_string_ascii_down (layer);
	g_string_prepend_c (layer, '#');
	output = argv[4];

	if (sscanf (size, "%dx%d", &w, &h) != 2) {
		g_warning ("Couldn't parse size '%s'", size);
		return 1;
	}

	logo_handle = rsvg_handle_new_from_file (input, &error);
	if (!logo_handle) {
		g_warning ("Couldn't open '%s': %s", input, error->message);
		g_error_free (error);
		return 1;
	}

	surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, w, h);
	cr = cairo_create (surface);

	rsvg_handle_get_dimensions (logo_handle, &dimensions);
	cairo_scale (cr,
		     (double) w / dimensions.width,
		     (double) h / dimensions.height);

	layer_name = g_string_free (layer, FALSE);
	rsvg_handle_render_cairo_sub (logo_handle, cr, "#background");
//	rsvg_handle_render_cairo_sub (logo_handle, cr, "#base");
	rsvg_handle_render_cairo_sub (logo_handle, cr, layer_name);

	status = cairo_surface_write_to_png (surface, output);
	if (status != CAIRO_STATUS_SUCCESS) {
		g_warning ("Couldn't write output '%s': %s", output, cairo_status_to_string (status));
		return 1;
	}

	g_free (layer_name);
	cairo_destroy (cr);

	return 0;
}
Пример #3
0
gchar*
codeslayer_utils_to_lowercase (gchar *string)
{
  GString *gstring;
  
  gstring = g_string_new (string);
  
  gstring = g_string_ascii_down (gstring);
  
  return g_string_free (gstring, FALSE);
}
Пример #4
0
Файл: hex.c Проект: LubkaB/mc
void
mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * lc_mc_search,
                                     mc_search_cond_t * mc_search_cond)
{
    GString *tmp;

    g_string_ascii_down (mc_search_cond->str);
    tmp = mc_search__hex_translate_to_regex (mc_search_cond->str);
    g_string_free (mc_search_cond->str, TRUE);
    mc_search_cond->str = tmp;

    mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
}
Пример #5
0
/*
Inserts a given word into the given hash table or increments the value if the word already exists.
@param {char *} key - string to insert into table
@param {GHashTable *} table - GHashTable object in which to store the string->count pairs
*/
void insert_word(char* key, GHashTable* table) {
  int* val;
  char* low_key = g_string_ascii_down(g_string_new(key))->str;
  val = (int*)g_hash_table_lookup(table, low_key);
  if (val == NULL) {
    val = malloc(sizeof(int));
    *val = 1;
    g_hash_table_insert(table, g_strdup(low_key), val);
  } else {
    *val += 1;
    g_hash_table_insert(table, g_strdup(low_key), val);
  }
}
Пример #6
0
GString *
sql_filter_sql_rewrite(GPtrArray *tokens)
{
    GString *sql_rewrite = NULL;
    int i = 0;

    if (tokens == NULL) return NULL;

    sql_rewrite = g_string_new(NULL);

    for (i = 0; i < tokens->len; i++)
    {
        sql_token *tk = (sql_token *)tokens->pdata[i];
        switch (tk->token_id)
        {
            case TK_UNKNOWN:
            case TK_COMMENT:
                break;
            case TK_SEMICOLON:
            {
                if (i == tokens->len - 1) { g_string_truncate(sql_rewrite, sql_rewrite->len - 1); }
                break;
            }
            case TK_INTEGER:
            case TK_FLOAT:
            case TK_STRING:
            {
                g_string_append_printf(sql_rewrite, "?%s", (i == tokens->len - 1) ? "" : " ");
                break;
            }
            case TK_LITERAL:
            {
                /* The ID like table name must keep the original type. */
                g_string_append_printf(sql_rewrite, "%s%s", tk->text->str,
                                            (i == tokens->len - 1) ? "" : " ");
                break;
            }
            default:
            {
                GString *lower = g_string_ascii_down(g_string_new(tk->text->str));
                g_string_append_printf(sql_rewrite, "%s%s", lower->str,
                                    (i == tokens->len - 1) ? "" : " ");
                g_string_free(lower, TRUE);
            }
        }
    }

    return sql_rewrite;
}
/** Convert string to compression type set an error if failed.
 * @param type_str      String with compression type (e.g. "gz")
 * @param type          Pointer to cr_CompressionType variable
 * @param err           Err that will be set in case of error
 */
static gboolean
check_and_set_compression_type(const char *type_str,
                               cr_CompressionType *type,
                               GError **err)
{
    assert(!err || *err == NULL);

    _cleanup_string_free_ GString *compress_str = NULL;
    compress_str = g_string_ascii_down(g_string_new(type_str));

    if (!strcmp(compress_str->str, "gz")) {
        *type = CR_CW_GZ_COMPRESSION;
    } else if (!strcmp(compress_str->str, "bz2")) {
        *type = CR_CW_BZ2_COMPRESSION;
    } else if (!strcmp(compress_str->str, "xz")) {
        *type = CR_CW_XZ_COMPRESSION;
    } else {
        g_set_error(err, ERR_DOMAIN, CRE_BADARG,
                    "Unknown/Unsupported compression type \"%s\"", type_str);
        return FALSE;
    }

    return TRUE;
}
Пример #8
0
static gboolean
spawn_mount (MountThreadInfo *info, gchar **envp, gchar **standard_error, 
	     gint *exit_status, GError **error)
{
	gint tty_fd, in_fd, out_fd, err_fd;
	fd_set rfds, wfds;
	GPid pid;
	gint ret, status;
	GString *outstr = NULL;
	GString *errstr = NULL;
	gboolean failed = FALSE;
	gboolean with_password = FALSE;
	gboolean need_password = FALSE;
	gchar* password = NULL;
	
	tty_fd = in_fd = out_fd = err_fd = -1;

#ifdef USE_PTY
	with_password = info->should_mount;
	
	if (with_password) {
		tty_fd = gnome_vfs_pty_open ((pid_t *) &pid, GNOME_VFS_PTY_LOGIN_TTY, envp, 
					     info->argv[0], info->argv, 
					     NULL, 300, 300, &in_fd, &out_fd, 
					     standard_error ? &err_fd : NULL);
		if (tty_fd == -1) {
			g_warning (_("Couldn't run mount process in a pty"));
			with_password = FALSE;
		}
	} 
#endif
	
	if (!with_password) {
		if (!g_spawn_async_with_pipes (NULL, info->argv, envp, 
					       G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL, 
					       NULL, NULL, &pid, NULL, NULL, 
					       standard_error ? &err_fd : NULL, error)) {
			g_critical ("Could not launch mount command: %s", (*error)->message);
			return FALSE;
		}
	}
	
	outstr = g_string_new (NULL);
	if (standard_error)
		errstr = g_string_new (NULL);

	/* Read data until we get EOF on both pipes. */
	while (!failed && (err_fd >= 0 || tty_fd >= 0)) {
		ret = 0;

		FD_ZERO (&rfds);
		FD_ZERO (&wfds);
		
		if (out_fd >= 0)
			FD_SET (out_fd, &rfds);
		if (tty_fd >= 0)
			FD_SET (tty_fd, &rfds);
		if (err_fd >= 0)
			FD_SET (err_fd, &rfds);
		
		if (need_password) {
			if (in_fd >= 0)
				FD_SET (in_fd, &wfds);
			if (tty_fd >= 0)
				FD_SET (tty_fd, &wfds);
		}
          
		ret = select (FD_SETSIZE, &rfds, &wfds, NULL, NULL /* no timeout */);
		if (ret < 0 && errno != EINTR) {
			failed = TRUE;
			g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_READ, 
				     _("Unexpected error in select() reading data from a child process (%s)"),
				     g_strerror (errno));
			break;
		}
		
		/* Read possible password prompt */
		if (tty_fd >= 0 && FD_ISSET (tty_fd, &rfds)) {
			if (read_data (outstr, &tty_fd, error) == -1) {
				failed = TRUE;
				break;
			}
		}
		
		/* Read possible password prompt */
		if (out_fd >= 0 && FD_ISSET (out_fd, &rfds)) {
			if (read_data(outstr, &out_fd, error) == -1) {
				failed = TRUE;
				break;
			}
		}

		/* Look for a password prompt */
		g_string_ascii_down (outstr);
		if (g_strstr_len (outstr->str, outstr->len, "password")) {
			DEBUG_MOUNT (("mount needs a password\n"));
			g_string_erase (outstr, 0, -1);
			need_password = TRUE;
		}
		
		if (need_password && ((tty_fd >= 0 && FD_ISSET (tty_fd, &wfds)) ||
				      (in_fd >= 0 && FD_ISSET (in_fd, &wfds)))) {

			g_free (password);
			password = NULL;

			/* Prompt for a password */
			if (!invoke_full_auth (info, &password) || password == NULL) {
				
				DEBUG_MOUNT (("user cancelled mount password prompt\n"));
				
				/* User cancelled, empty string returned */
				g_string_erase (errstr, 0, -1);
				kill (pid, SIGTERM);
				break;
				
			/* Got a password */
			} else {
				
				DEBUG_MOUNT (("got password: %s\n", password));
				
				if (write(tty_fd, password, strlen(password)) == -1 || 
				    write(tty_fd, "\n", 1) == -1) {
					g_warning ("couldn't send password to child mount process: %s\n", g_strerror (errno));
					g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_READ, 
						     _("Couldn't send password to mount process."));
					failed = TRUE;
				}
				
			} 

			need_password = FALSE;
		}
	
		if (err_fd >= 0 && FD_ISSET (err_fd, &rfds)) {
			if (read_data (errstr, &err_fd, error) == -1) {
				failed = TRUE;
				break;
			}
		}
	}

	if (in_fd >= 0)
		close (in_fd);
	if (out_fd >= 0)
		close (out_fd);
	if (err_fd >= 0)
		close (err_fd);
	if (tty_fd >= 0)
		close (tty_fd);

	/* Wait for child to exit, even if we have
	 * an error pending.
	 */
again:

	ret = waitpid (pid, &status, 0);

	if (ret < 0) {
		if (errno == EINTR)
			goto again;
		else if (!failed) {
			failed = TRUE;
			g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_READ,
				     _("Unexpected error in waitpid() (%s)"), g_strerror (errno));
		}
	}

	g_free (password);
	
	if (failed) {
		if (errstr)
			g_string_free (errstr, TRUE);
		g_string_free (outstr, TRUE);
		return FALSE;
	} else {
		if (exit_status)
			*exit_status = status;
		if (standard_error) {
			/* Sad as it may be, certain mount helpers (like mount.cifs)
			 * on Linux and perhaps other OSs return their error 
			 * output on stdout. */
			if (outstr->len && !errstr->len) {
				*standard_error = g_string_free (outstr, FALSE);
				g_string_free (errstr, TRUE);
			} else {
				*standard_error = g_string_free (errstr, FALSE);
				g_string_free (outstr, TRUE);
			}
		}
		return TRUE;
	}
}
Пример #9
0
int
moloch_hp_cb_on_headers_complete (http_parser *parser)
{
    HTTPInfo_t            *http = parser->data;
    MolochSession_t       *session = http->session;
    char                   tag[200];
    char                   version[20];


#ifdef HTTPDEBUG
    LOG("HTTPDEBUG: which: %d code: %d method: %d", http->which, parser->status_code, parser->method);
#endif

    int len = snprintf(version, sizeof(version), "%d.%d", parser->http_major, parser->http_minor);

    if (parser->status_code == 0) {
#ifndef REMOVEOLD
        snprintf(tag, sizeof(tag), "http:method:%s", http_method_str(parser->method));
        moloch_nids_add_tag(session, tag);
#endif
        moloch_field_string_add(methodField, session, http_method_str(parser->method), -1, TRUE);
        moloch_field_string_add(verReqField, session, version, len, TRUE);
    } else {
#ifndef REMOVEOLD
        snprintf(tag, sizeof(tag), "http:statuscode:%d", parser->status_code);
        moloch_nids_add_tag(session, tag);
#endif
        moloch_field_int_add(statuscodeField, session, parser->status_code);
        moloch_field_string_add(verResField, session, version, len, TRUE);
    }

    if (http->inValue & (1 << http->which) && http->pos[http->which]) {
        http_add_value(session, http);
    }

    http->header[0][0] = http->header[1][0] = 0;

    if (http->urlString) {
        char *ch = http->urlString->str;
        while (*ch) {
            if (*ch < 32) {
                moloch_nids_add_tag(session, "http:control-char");
                break;
            }
            ch++;
        }
    }

    if (http->cookieString && http->cookieString->str[0]) {
        char *start = http->cookieString->str;
        while (1) {
            while (isspace(*start)) start++;
            char *equal = strchr(start, '=');
            if (!equal)
                break;
            moloch_field_string_add(cookieKeyField, session, start, equal-start, TRUE);
            start = strchr(equal+1, ';');
            if(!start)
                break;
            start++;
        }
        g_string_truncate(http->cookieString, 0);
    }

    if (http->authString && http->authString->str[0]) {
        moloch_http_parse_authorization(session, http->authString->str);
        g_string_truncate(http->authString, 0);
    }

    if (http->hostString) {
        g_string_ascii_down(http->hostString);
    }

    if (http->urlString && http->hostString) {
        char *colon = strchr(http->hostString->str+2, ':');
        if (colon) {
            moloch_field_string_add(hostField, session, http->hostString->str+2, colon - http->hostString->str-2, TRUE);
        } else {
            moloch_field_string_add(hostField, session, http->hostString->str+2, http->hostString->len-2, TRUE);
        }

        char *question = strchr(http->urlString->str, '?');
        if (question) {
            moloch_field_string_add(pathField, session, http->urlString->str, question - http->urlString->str, TRUE);
            char *start = question+1;
            char *ch;
            int   field = keyField;
            for (ch = start; *ch; ch++) {
                if (*ch == '&') {
                    if (ch != start && (config.parseQSValue || field == keyField)) {
                        char *str = g_uri_unescape_segment(start, ch, NULL);
                        if (!str) {
                            moloch_field_string_add(field, session, start, ch-start, TRUE);
                        } else if (!moloch_field_string_add(field, session, str, strlen(str), FALSE)) {
                            g_free(str);
                        }
                    }
                    start = ch+1;
                    field = keyField;
                    continue;
                } else if (*ch == '=') {
                    if (ch != start && (config.parseQSValue || field == keyField)) {
                        char *str = g_uri_unescape_segment(start, ch, NULL);
                        if (!str) {
                            moloch_field_string_add(field, session, start, ch-start, TRUE);
                        } else if (!moloch_field_string_add(field, session, str, strlen(str), FALSE)) {
                            g_free(str);
                        }
                    }
                    start = ch+1;
                    field = valueField;
                }
            }
            if (config.parseQSValue && field == valueField && ch > start) {
                char *str = g_uri_unescape_segment(start, ch, NULL);
                if (!str) {
                    moloch_field_string_add(field, session, start, ch-start, TRUE);
                } else if (!moloch_field_string_add(field, session, str, strlen(str), FALSE)) {
                    g_free(str);
                }
            }
        } else {
            moloch_field_string_add(pathField, session, http->urlString->str, http->urlString->len, TRUE);
        }

        if (http->urlString->str[0] != '/') {
            char *result = strstr(http->urlString->str, http->hostString->str+2);

            /* If the host header is in the first 8 bytes of url then just use the url */
            if (result && result - http->urlString->str <= 8) {
                moloch_field_string_add(urlsField, session, http->urlString->str, http->urlString->len, FALSE);
                g_string_free(http->urlString, FALSE);
                g_string_free(http->hostString, TRUE);
            } else {
                /* Host header doesn't match the url */
                g_string_append(http->hostString, ";");
                g_string_append(http->hostString, http->urlString->str);
                moloch_field_string_add(urlsField, session, http->hostString->str, http->hostString->len, FALSE);
                g_string_free(http->urlString, TRUE);
                g_string_free(http->hostString, FALSE);
            }
        } else {
            /* Normal case, url starts with /, so no extra host in url */
            g_string_append(http->hostString, http->urlString->str);
            moloch_field_string_add(urlsField, session, http->hostString->str, http->hostString->len, FALSE);
            g_string_free(http->urlString, TRUE);
            g_string_free(http->hostString, FALSE);
        }

        http->urlString = NULL;
        http->hostString = NULL;
    } else if (http->urlString) {
        moloch_field_string_add(urlsField, session, http->urlString->str, http->urlString->len, FALSE);
        g_string_free(http->urlString, FALSE);


        http->urlString = NULL;
    } else if (http->hostString) {
        char *colon = strchr(http->hostString->str+2, ':');
        if (colon) {
            moloch_field_string_add(hostField, session, http->hostString->str+2, colon - http->hostString->str-2, TRUE);
        } else {
            moloch_field_string_add(hostField, session, http->hostString->str+2, http->hostString->len-2, TRUE);
        }

        g_string_free(http->hostString, TRUE);
        http->hostString = NULL;
    }

    moloch_nids_add_tag(session, "protocol:http");
    moloch_nids_add_protocol(session, "http");

    if (pluginsCbs & MOLOCH_PLUGIN_HP_OHC)
        moloch_plugins_cb_hp_ohc(session, parser);

    return 0;
}
Пример #10
0
int
moloch_hp_cb_on_message_complete (http_parser *parser)
{
    HTTPInfo_t            *http = parser->data;
    MolochSession_t       *session = http->session;

#ifdef HTTPDEBUG
    LOG("HTTPDEBUG: which: %d", session->which);
#endif

    if (pluginsCbs & MOLOCH_PLUGIN_HP_OMC)
        moloch_plugins_cb_hp_omc(session, parser);

    http->header[0][0] = http->header[1][0] = 0;

    if (http->urlString) {
        char *ch = http->urlString->str;
        while (*ch) {
            if (*ch < 32) {
                moloch_nids_add_tag(session, "http:control-char");
                break;
            }
            ch++;
        }
    }

    if (http->hostString) {
        g_string_ascii_down(http->hostString);
    }

    if (http->urlString && http->hostString) {
        char *colon = strchr(http->hostString->str+2, ':');
        if (colon) {
            moloch_field_string_add(hostField, session, http->hostString->str+2, colon - http->hostString->str-2, TRUE);
        } else {
            moloch_field_string_add(hostField, session, http->hostString->str+2, http->hostString->len-2, TRUE);
        }

        char *question = strchr(http->urlString->str, '?');
        if (question) {
            moloch_field_string_add(pathField, session, http->urlString->str, question - http->urlString->str, TRUE);
            char *start = question+1;
            char *ch;
            int   field = keyField;
            for (ch = start; *ch; ch++) {
                if (*ch == '&') {
                    if (ch != start && (config.parseQSValue || field == keyField)) {
                        char *str = g_uri_unescape_segment(start, ch, NULL);
                        if (!str) {
                            moloch_field_string_add(field, session, start, ch-start, TRUE);
                        } else if (!moloch_field_string_add(field, session, str, strlen(str), FALSE)) {
                            g_free(str);
                        }
                    }
                    start = ch+1;
                    field = keyField;
                    continue;
                } else if (*ch == '=') {
                    if (ch != start && (config.parseQSValue || field == keyField)) {
                        char *str = g_uri_unescape_segment(start, ch, NULL);
                        if (!str) {
                            moloch_field_string_add(field, session, start, ch-start, TRUE);
                        } else if (!moloch_field_string_add(field, session, str, strlen(str), FALSE)) {
                            g_free(str);
                        }
                    }
                    start = ch+1;
                    field = valueField;
                }
            }
            if (config.parseQSValue && field == valueField && ch > start) {
                char *str = g_uri_unescape_segment(start, ch, NULL);
                if (!str) {
                    moloch_field_string_add(field, session, start, ch-start, TRUE);
                } else if (!moloch_field_string_add(field, session, str, strlen(str), FALSE)) {
                    g_free(str);
                }
            }
        } else {
            moloch_field_string_add(pathField, session, http->urlString->str, http->urlString->len, TRUE);
        }

        if (http->urlString->str[0] != '/') {
            char *result = strstr(http->urlString->str, http->hostString->str+2);

            /* If the host header is in the first 8 bytes of url then just use the url */
            if (result && result - http->urlString->str <= 8) {
                moloch_field_string_add(urlsField, session, http->urlString->str, http->urlString->len, FALSE);
                g_string_free(http->urlString, FALSE);
                g_string_free(http->hostString, TRUE);
            } else {
                /* Host header doesn't match the url */
                g_string_append(http->hostString, ";");
                g_string_append(http->hostString, http->urlString->str);
                moloch_field_string_add(urlsField, session, http->hostString->str, http->hostString->len, FALSE);
                g_string_free(http->urlString, TRUE);
                g_string_free(http->hostString, FALSE);
            }
        } else {
            /* Normal case, url starts with /, so no extra host in url */
            g_string_append(http->hostString, http->urlString->str);
            moloch_field_string_add(urlsField, session, http->hostString->str, http->hostString->len, FALSE);
            g_string_free(http->urlString, TRUE);
            g_string_free(http->hostString, FALSE);
        }

        moloch_nids_add_tag(session, "protocol:http");
        moloch_nids_add_protocol(session, "http");

        http->urlString = NULL;
        http->hostString = NULL;
    } else if (http->urlString) {
        moloch_field_string_add(urlsField, session, http->urlString->str, http->urlString->len, FALSE);
        g_string_free(http->urlString, FALSE);

        moloch_nids_add_tag(session, "protocol:http");
        moloch_nids_add_protocol(session, "http");

        http->urlString = NULL;
    } else if (http->hostString) {
        char *colon = strchr(http->hostString->str+2, ':');
        if (colon) {
            moloch_field_string_add(hostField, session, http->hostString->str+2, colon - http->hostString->str-2, TRUE);
        } else {
            moloch_field_string_add(hostField, session, http->hostString->str+2, http->hostString->len-2, TRUE);
        }

        g_string_free(http->hostString, TRUE);
        http->hostString = NULL;
    }

    if (http->inBody & (1 << session->which)) {
        const char *md5 = g_checksum_get_string(http->checksum[session->which]);
        moloch_field_string_add(md5Field, session, (char*)md5, 32, TRUE);
    }

    return 0;
}
Пример #11
0
int main(int argc, char** argv) 
{
    char   		*pszGuid = NULL;
    char    	 szGuid[512];
    int			 nInterfaces = 0;
    int			 nDevices = 0;
    int 		 i = 0;
	const char	*pkeyAcquisitionFrameRate[2] = {"AcquisitionFrameRate", "AcquisitionFrameRateAbs"};
    ArvGcNode	*pGcNode;
	GError		*error=NULL;

    global.bCancel = FALSE;
    global.config = global.config.__getDefault__();
    global.idSoftwareTriggerTimer = 0;

    ros::init(argc, argv, "camera");
    global.phNode = new ros::NodeHandle();


    // Service callback for firing nuc's. 
	// Needed since we cannot open another connection to cameras while streaming.
	ros::NodeHandle nh;
	ros::ServiceServer NUCservice = nh.advertiseService("FireNUC", NUCService_callback);

    //g_type_init ();

    // Print out some useful info.
    ROS_INFO ("Attached cameras:");
    arv_update_device_list();
    nInterfaces = arv_get_n_interfaces();
    ROS_INFO ("# Interfaces: %d", nInterfaces);

    nDevices = arv_get_n_devices();
    ROS_INFO ("# Devices: %d", nDevices);
    for (i=0; i<nDevices; i++)
    	ROS_INFO ("Device%d: %s", i, arv_get_device_id(i));
    
    if (nDevices>0)
    {
		// Get the camera guid from either the command-line or as a parameter.
    	if (argc==2)
    	{
    		strcpy(szGuid, argv[1]);
    		pszGuid = szGuid;
    	}
    	else
    	{
    		if (global.phNode->hasParam(ros::this_node::getName()+"/guid"))
    		{
    			std::string		stGuid;
    			
    			global.phNode->getParam(ros::this_node::getName()+"/guid", stGuid);
    			strcpy (szGuid, stGuid.c_str());
        		pszGuid = szGuid;
    		}
    		else
    			pszGuid = NULL;
    	}
    	
    	// Open the camera, and set it up.
    	ROS_INFO("Opening: %s", pszGuid ? pszGuid : "(any)");
		while (TRUE)
		{
			global.pCamera = arv_camera_new(pszGuid);
			if (global.pCamera)
				break;
			else
			{
				ROS_WARN ("Could not open camera %s.  Retrying...", pszGuid);
				ros::Duration(1.0).sleep();
			    ros::spinOnce();
			}
		}

		global.pDevice = arv_camera_get_device(global.pCamera);
		ROS_INFO("Opened: %s-%s", arv_device_get_string_feature_value (global.pDevice, "DeviceVendorName"), arv_device_get_string_feature_value (global.pDevice, "DeviceID"));


		// See if some basic camera features exist.
		pGcNode = arv_device_get_feature (global.pDevice, "AcquisitionMode");
		global.isImplementedAcquisitionMode = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "GainRaw");
		global.isImplementedGain = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;
		pGcNode = arv_device_get_feature (global.pDevice, "Gain");
		global.isImplementedGain |= ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "ExposureTimeAbs");
		global.isImplementedExposureTimeAbs = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "ExposureAuto");
		global.isImplementedExposureAuto = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "GainAuto");
		global.isImplementedGainAuto = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "TriggerSelector");
		global.isImplementedTriggerSelector = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "TriggerSource");
		global.isImplementedTriggerSource = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "TriggerMode");
		global.isImplementedTriggerMode = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "FocusPos");
		global.isImplementedFocusPos = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "GevSCPSPacketSize");
		global.isImplementedMtu = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "AcquisitionFrameRateEnable");
		global.isImplementedAcquisitionFrameRateEnable = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		// Find the key name for framerate.
		global.keyAcquisitionFrameRate = NULL;
		for (i=0; i<2; i++)
		{
			pGcNode = arv_device_get_feature (global.pDevice, pkeyAcquisitionFrameRate[i]);
			global.isImplementedAcquisitionFrameRate = pGcNode ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;
			if (global.isImplementedAcquisitionFrameRate)
			{
				global.keyAcquisitionFrameRate = pkeyAcquisitionFrameRate[i];
				break;
			}
		}


		// Get parameter bounds.
		arv_camera_get_exposure_time_bounds	(global.pCamera, &global.configMin.ExposureTimeAbs, &global.configMax.ExposureTimeAbs);
		arv_camera_get_gain_bounds			(global.pCamera, &global.configMin.Gain, &global.configMax.Gain);
		arv_camera_get_sensor_size			(global.pCamera, &global.widthSensor, &global.heightSensor);
		arv_camera_get_width_bounds			(global.pCamera, &global.widthRoiMin, &global.widthRoiMax);
		arv_camera_get_height_bounds		(global.pCamera, &global.heightRoiMin, &global.heightRoiMax);

		if (global.isImplementedFocusPos)
		{
			gint64 focusMin64, focusMax64;
			arv_device_get_integer_feature_bounds (global.pDevice, "FocusPos", &focusMin64, &focusMax64);
			global.configMin.FocusPos = focusMin64;
			global.configMax.FocusPos = focusMax64;
		}
		else
		{
			global.configMin.FocusPos = 0;
			global.configMax.FocusPos = 0;
		}

		global.configMin.AcquisitionFrameRate =    0.0;
		global.configMax.AcquisitionFrameRate = 1000.0;


		// Initial camera settings.
		if (global.isImplementedExposureTimeAbs)
			arv_device_set_float_feature_value(global.pDevice, "ExposureTimeAbs", global.config.ExposureTimeAbs);
		if (global.isImplementedGain)
			arv_camera_set_gain(global.pCamera, global.config.Gain);
			//arv_device_set_integer_feature_value(global.pDevice, "GainRaw", global.config.GainRaw);
		if (global.isImplementedAcquisitionFrameRateEnable)
			arv_device_set_integer_feature_value(global.pDevice, "AcquisitionFrameRateEnable", 1);
		if (global.isImplementedAcquisitionFrameRate)
			arv_device_set_float_feature_value(global.pDevice, global.keyAcquisitionFrameRate, global.config.AcquisitionFrameRate);


		// Set up the triggering.
		if (global.isImplementedTriggerMode)
		{
			if (global.isImplementedTriggerSelector && global.isImplementedTriggerMode)
			{
				arv_device_set_string_feature_value(global.pDevice, "TriggerSelector", "AcquisitionStart");
				arv_device_set_string_feature_value(global.pDevice, "TriggerMode", "Off");
				arv_device_set_string_feature_value(global.pDevice, "TriggerSelector", "FrameStart");
				arv_device_set_string_feature_value(global.pDevice, "TriggerMode", "Off");
			}
		}


		WriteCameraFeaturesFromRosparam ();


#ifdef TUNING			
		ros::Publisher pubInt64 = global.phNode->advertise<std_msgs::Int64>(ros::this_node::getName()+"/dt", 100);
		global.ppubInt64 = &pubInt64;
#endif
    	
    // Grab the calibration file url from the param server if exists
    std::string calibrationURL = ""; // Default looks in .ros/camera_info
		if (!(ros::param::get(std::string("calibrationURL").append(arv_device_get_string_feature_value (global.pDevice, "DeviceID")), calibrationURL)))
		{
			ROS_ERROR("ERROR: Could not read calibrationURL from parameter server");
		}

		// Start the camerainfo manager.
		global.pCameraInfoManager = new camera_info_manager::CameraInfoManager(ros::NodeHandle(ros::this_node::getName()), arv_device_get_string_feature_value (global.pDevice, "DeviceID"), calibrationURL);

		// Start the dynamic_reconfigure server.
		dynamic_reconfigure::Server<Config> 				reconfigureServer;
		dynamic_reconfigure::Server<Config>::CallbackType 	reconfigureCallback;

		reconfigureCallback = boost::bind(&RosReconfigure_callback, _1, _2);
		reconfigureServer.setCallback(reconfigureCallback);
		ros::Duration(2.0).sleep();


		// Get parameter current values.
		global.xRoi=0; global.yRoi=0; global.widthRoi=0; global.heightRoi=0;
		arv_camera_get_region (global.pCamera, &global.xRoi, &global.yRoi, &global.widthRoi, &global.heightRoi);
		global.config.ExposureTimeAbs 	= global.isImplementedExposureTimeAbs ? arv_device_get_float_feature_value (global.pDevice, "ExposureTimeAbs") : 0;
		global.config.Gain      		= global.isImplementedGain ? arv_camera_get_gain (global.pCamera) : 0.0;
		global.pszPixelformat   		= g_string_ascii_down(g_string_new(arv_device_get_string_feature_value(global.pDevice, "PixelFormat")))->str;
		global.nBytesPixel      		= ARV_PIXEL_FORMAT_BYTE_PER_PIXEL(arv_device_get_integer_feature_value(global.pDevice, "PixelFormat"));
		global.config.FocusPos  		= global.isImplementedFocusPos ? arv_device_get_integer_feature_value (global.pDevice, "FocusPos") : 0;
		
		
		// Print information.
		ROS_INFO ("    Using Camera Configuration:");
		ROS_INFO ("    ---------------------------");
		ROS_INFO ("    Vendor name          = %s", arv_device_get_string_feature_value (global.pDevice, "DeviceVendorName"));
		ROS_INFO ("    Model name           = %s", arv_device_get_string_feature_value (global.pDevice, "DeviceModelName"));
		ROS_INFO ("    Device id            = %s", arv_device_get_string_feature_value (global.pDevice, "DeviceID"));
		ROS_INFO ("    Sensor width         = %d", global.widthSensor);
		ROS_INFO ("    Sensor height        = %d", global.heightSensor);
		ROS_INFO ("    ROI x,y,w,h          = %d, %d, %d, %d", global.xRoi, global.yRoi, global.widthRoi, global.heightRoi);
		ROS_INFO ("    Pixel format         = %s", global.pszPixelformat);
		ROS_INFO ("    BytesPerPixel        = %d", global.nBytesPixel);
		ROS_INFO ("    Acquisition Mode     = %s", global.isImplementedAcquisitionMode ? arv_device_get_string_feature_value (global.pDevice, "AcquisitionMode") : "(not implemented in camera)");
		ROS_INFO ("    Trigger Mode         = %s", global.isImplementedTriggerMode ? arv_device_get_string_feature_value (global.pDevice, "TriggerMode") : "(not implemented in camera)");
		ROS_INFO ("    Trigger Source       = %s", global.isImplementedTriggerSource ? arv_device_get_string_feature_value(global.pDevice, "TriggerSource") : "(not implemented in camera)");
		ROS_INFO ("    Can set FrameRate:     %s", global.isImplementedAcquisitionFrameRate ? "True" : "False");
		if (global.isImplementedAcquisitionFrameRate)
		{
			global.config.AcquisitionFrameRate = arv_device_get_float_feature_value (global.pDevice, global.keyAcquisitionFrameRate);
			ROS_INFO ("    AcquisitionFrameRate = %g hz", global.config.AcquisitionFrameRate);
		}

		ROS_INFO ("    Can set Exposure:      %s", global.isImplementedExposureTimeAbs ? "True" : "False");
		if (global.isImplementedExposureTimeAbs)
		{
			ROS_INFO ("    Can set ExposureAuto:  %s", global.isImplementedExposureAuto ? "True" : "False");
			ROS_INFO ("    Exposure             = %g us in range [%g,%g]", global.config.ExposureTimeAbs, global.configMin.ExposureTimeAbs, global.configMax.ExposureTimeAbs);
		}

		ROS_INFO ("    Can set Gain:          %s", global.isImplementedGain ? "True" : "False");
		if (global.isImplementedGain)
		{
			ROS_INFO ("    Can set GainAuto:      %s", global.isImplementedGainAuto ? "True" : "False");
			ROS_INFO ("    Gain                 = %f %% in range [%f,%f]", global.config.Gain, global.configMin.Gain, global.configMax.Gain);
		}

		ROS_INFO ("    Can set FocusPos:      %s", global.isImplementedFocusPos ? "True" : "False");

		if (global.isImplementedMtu)
			ROS_INFO ("    Network mtu          = %lu", arv_device_get_integer_feature_value(global.pDevice, "GevSCPSPacketSize"));

		ROS_INFO ("    ---------------------------");


//		// Print the tree of camera features, with their values.
//		ROS_INFO ("    ----------------------------------------------------------------------------------");
//		NODEEX		 nodeex;
//		ArvGc	*pGenicam=0;
//		pGenicam = arv_device_get_genicam(global.pDevice);
//
//		nodeex.szName = "Root";
//		nodeex.pNode = (ArvDomNode	*)arv_gc_get_node(pGenicam, nodeex.szName);
//		nodeex.pNodeSibling = NULL;
//		PrintDOMTree(pGenicam, nodeex, 0);
//		ROS_INFO ("    ----------------------------------------------------------------------------------");
			

		ArvGvStream *pStream = NULL;
		while (TRUE)
		{
			pStream = CreateStream();
			if (pStream)
				break;
			else
			{
				ROS_WARN("Could not create image stream for %s.  Retrying...", pszGuid);
				ros::Duration(1.0).sleep();
			    ros::spinOnce();
			}
		}


		ApplicationData applicationdata;
		applicationdata.nBuffers=0;
		applicationdata.main_loop = 0;

		// Set up image_raw.
		image_transport::ImageTransport		*pTransport = new image_transport::ImageTransport(*global.phNode);
		global.publisher = pTransport->advertiseCamera(ros::this_node::getName()+"/image_raw", 1);

		// Connect signals with callbacks.
		g_signal_connect (pStream,        "new-buffer",   G_CALLBACK (NewBuffer_callback),   &applicationdata);
		g_signal_connect (global.pDevice, "control-lost", G_CALLBACK (ControlLost_callback), NULL);
		g_timeout_add_seconds (1, PeriodicTask_callback, &applicationdata);
		arv_stream_set_emit_signals ((ArvStream *)pStream, TRUE);


		void (*pSigintHandlerOld)(int);
		pSigintHandlerOld = signal (SIGINT, set_cancel);

		arv_device_execute_command (global.pDevice, "AcquisitionStart");

		applicationdata.main_loop = g_main_loop_new (NULL, FALSE);
		g_main_loop_run (applicationdata.main_loop);

		if (global.idSoftwareTriggerTimer)
		{
			g_source_remove(global.idSoftwareTriggerTimer);
			global.idSoftwareTriggerTimer = 0;
		}

		signal (SIGINT, pSigintHandlerOld);

		g_main_loop_unref (applicationdata.main_loop);

		guint64 n_completed_buffers;
		guint64 n_failures;
		guint64 n_underruns;
		guint64 n_resent;
		guint64 n_missing;
		arv_stream_get_statistics ((ArvStream *)pStream, &n_completed_buffers, &n_failures, &n_underruns);
		ROS_INFO ("Completed buffers = %Lu", (unsigned long long) n_completed_buffers);
		ROS_INFO ("Failures          = %Lu", (unsigned long long) n_failures);
		ROS_INFO ("Underruns         = %Lu", (unsigned long long) n_underruns);
		arv_gv_stream_get_statistics (pStream, &n_resent, &n_missing);
		ROS_INFO ("Resent buffers    = %Lu", (unsigned long long) n_resent);
		ROS_INFO ("Missing           = %Lu", (unsigned long long) n_missing);

		arv_device_execute_command (global.pDevice, "AcquisitionStop");

		g_object_unref (pStream);

    }
    else
    	ROS_ERROR ("No cameras detected.");
    
    delete global.phNode;
    
    return 0;
} // main()