CachedMat& MatCache::prepare_image(const std::string &name) { CachedMat &item = images[name]; if (item.mat.cols != width || item.mat.rows != height) item.mat = cv::Mat(height, width, type_from_name(name)); return item; }
int main (int argc, char *argv[]) { DBusConnection *connection; DBusError error; DBusMessage *message; dbus_bool_t print_reply; dbus_bool_t print_reply_literal; int reply_timeout; DBusMessageIter iter; int i; DBusBusType type = DBUS_BUS_SESSION; const char *dest = NULL; const char *name = NULL; const char *path = NULL; int message_type = DBUS_MESSAGE_TYPE_SIGNAL; const char *type_str = NULL; const char *address = NULL; int is_bus = FALSE; int session_or_system = FALSE; appname = argv[0]; if (argc < 3) usage (1); print_reply = FALSE; print_reply_literal = FALSE; reply_timeout = -1; for (i = 1; i < argc && name == NULL; i++) { char *arg = argv[i]; if (strcmp (arg, "--system") == 0) { type = DBUS_BUS_SYSTEM; session_or_system = TRUE; } else if (strcmp (arg, "--session") == 0) { type = DBUS_BUS_SESSION; session_or_system = TRUE; } else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg)) { if (arg[2] == 'b') /* bus */ { is_bus = TRUE; } else if (arg[2] == 'p') /* peer */ { is_bus = FALSE; } else /* address; keeping backwards compatibility */ { is_bus = FALSE; } address = strchr (arg, '=') + 1; if (address[0] == '\0') { fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n"); usage (1); } } else if (strncmp (arg, "--print-reply", 13) == 0) { print_reply = TRUE; message_type = DBUS_MESSAGE_TYPE_METHOD_CALL; if (strcmp (arg + 13, "=literal") == 0) print_reply_literal = TRUE; else if (*(arg + 13) != '\0') { fprintf (stderr, "invalid value (%s) of \"--print-reply\"\n", arg + 13); usage (1); } } else if (strstr (arg, "--reply-timeout=") == arg) { if (*(strchr (arg, '=') + 1) == '\0') { fprintf (stderr, "\"--reply-timeout=\" requires an MSEC\n"); usage (1); } reply_timeout = strtol (strchr (arg, '=') + 1, NULL, 10); if (reply_timeout <= 0) { fprintf (stderr, "invalid value (%s) of \"--reply-timeout\"\n", strchr (arg, '=') + 1); usage (1); } } else if (strstr (arg, "--dest=") == arg) { if (*(strchr (arg, '=') + 1) == '\0') { fprintf (stderr, "\"--dest=\" requires an NAME\n"); usage (1); } dest = strchr (arg, '=') + 1; } else if (strstr (arg, "--type=") == arg) type_str = strchr (arg, '=') + 1; else if (!strcmp(arg, "--help")) usage (0); else if (arg[0] == '-') usage (1); else if (path == NULL) path = arg; else /* name == NULL guaranteed by the 'while' loop */ name = arg; } if (name == NULL) usage (1); if (session_or_system && (address != NULL)) { fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n"); usage (1); } if (type_str != NULL) { message_type = dbus_message_type_from_string (type_str); if (!(message_type == DBUS_MESSAGE_TYPE_METHOD_CALL || message_type == DBUS_MESSAGE_TYPE_SIGNAL)) { fprintf (stderr, "Message type \"%s\" is not supported\n", type_str); exit (1); } } dbus_error_init (&error); if (dest && !dbus_validate_bus_name (dest, &error)) { fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest); usage (1); } if (address != NULL) { connection = dbus_connection_open (address, &error); } else { connection = dbus_bus_get (type, &error); } if (connection == NULL) { fprintf (stderr, "Failed to open connection to \"%s\" message bus: %s\n", (address != NULL) ? address : ((type == DBUS_BUS_SYSTEM) ? "system" : "session"), error.message); dbus_error_free (&error); exit (1); } else if ((address != NULL) && is_bus) { if (!dbus_bus_register (connection, &error)) { fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n", address, error.message); dbus_error_free (&error); exit (1); } } if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) { char *last_dot; last_dot = strrchr (name, '.'); if (last_dot == NULL) { fprintf (stderr, "Must use org.mydomain.Interface.Method notation, no dot in \"%s\"\n", name); exit (1); } *last_dot = '\0'; message = dbus_message_new_method_call (NULL, path, name, last_dot + 1); dbus_message_set_auto_start (message, TRUE); } else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL) { char *last_dot; last_dot = strrchr (name, '.'); if (last_dot == NULL) { fprintf (stderr, "Must use org.mydomain.Interface.Signal notation, no dot in \"%s\"\n", name); exit (1); } *last_dot = '\0'; message = dbus_message_new_signal (path, name, last_dot + 1); } else { fprintf (stderr, "Internal error, unknown message type\n"); exit (1); } if (message == NULL) { fprintf (stderr, "Couldn't allocate D-Bus message\n"); exit (1); } if (dest && !dbus_message_set_destination (message, dest)) { fprintf (stderr, "Not enough memory\n"); exit (1); } dbus_message_iter_init_append (message, &iter); while (i < argc) { char *arg; char *c; int type; int secondary_type; int container_type; DBusMessageIter *target_iter; DBusMessageIter container_iter; type = DBUS_TYPE_INVALID; arg = argv[i++]; c = strchr (arg, ':'); if (c == NULL) { fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg); exit (1); } *(c++) = 0; container_type = DBUS_TYPE_INVALID; if (strcmp (arg, "variant") == 0) container_type = DBUS_TYPE_VARIANT; else if (strcmp (arg, "array") == 0) container_type = DBUS_TYPE_ARRAY; else if (strcmp (arg, "dict") == 0) container_type = DBUS_TYPE_DICT_ENTRY; if (container_type != DBUS_TYPE_INVALID) { arg = c; c = strchr (arg, ':'); if (c == NULL) { fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg); exit (1); } *(c++) = 0; } if (arg[0] == 0) type = DBUS_TYPE_STRING; else type = type_from_name (arg); if (container_type == DBUS_TYPE_DICT_ENTRY) { char sig[5]; arg = c; c = strchr (c, ':'); if (c == NULL) { fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg); exit (1); } *(c++) = 0; secondary_type = type_from_name (arg); sig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR; sig[1] = type; sig[2] = secondary_type; sig[3] = DBUS_DICT_ENTRY_END_CHAR; sig[4] = '\0'; dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, sig, &container_iter); target_iter = &container_iter; } else if (container_type != DBUS_TYPE_INVALID) { char sig[2]; sig[0] = type; sig[1] = '\0'; dbus_message_iter_open_container (&iter, container_type, sig, &container_iter); target_iter = &container_iter; } else target_iter = &iter; if (container_type == DBUS_TYPE_ARRAY) { append_array (target_iter, type, c); } else if (container_type == DBUS_TYPE_DICT_ENTRY) { append_dict (target_iter, type, secondary_type, c); } else append_arg (target_iter, type, c); if (container_type != DBUS_TYPE_INVALID) { dbus_message_iter_close_container (&iter, &container_iter); } } if (print_reply) { DBusMessage *reply; dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (connection, message, reply_timeout, &error); if (dbus_error_is_set (&error)) { fprintf (stderr, "Error %s: %s\n", error.name, error.message); exit (1); } if (reply) { long sec, usec; _dbus_get_real_time (&sec, &usec); print_message (reply, print_reply_literal, sec, usec); dbus_message_unref (reply); } } else { dbus_connection_send (connection, message, NULL); dbus_connection_flush (connection); } dbus_message_unref (message); dbus_connection_unref (connection); exit (0); }