summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-19 21:06:42 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-19 21:06:42 +0000
commit762cbfb2daba6a8ad62c70ebefd3420850e7ff81 (patch)
treebe26562b967290cd93f9ae1c27d2cd04e4fd7551
parent24dea738c62ea9a1060fe7ae86d2a1241e14c5d4 (diff)
some stuff to dispatch strings instead of JsonNode, but nothing uses it yet.
-rw-r--r--src/json.c6
-rw-r--r--src/session-get.c7
-rw-r--r--src/session-get.h1
-rw-r--r--src/trg-client.c64
-rw-r--r--src/trg-client.h6
-rw-r--r--src/trg-main-window.c4
-rw-r--r--src/trg-stats-dialog.c2
7 files changed, 70 insertions, 20 deletions
diff --git a/src/json.c b/src/json.c
index ce166f2..aad4606 100644
--- a/src/json.c
+++ b/src/json.c
@@ -42,7 +42,7 @@ gchar *trg_serialize(JsonNode * req)
return response;
}
-JsonObject *trg_deserialize(trg_response * reqrsp,
+JsonObject *trg_deserialize(trg_response * response,
GError ** error)
{
JsonParser *parser;
@@ -50,13 +50,13 @@ JsonObject *trg_deserialize(trg_response * reqrsp,
JsonObject *ret = NULL;
parser = json_parser_new();
- json_parser_load_from_data(parser, reqrsp->raw, reqrsp->size,
+ json_parser_load_from_data(parser, response->raw, response->size,
error);
if (*error == NULL) {
root = json_parser_get_root(parser);
#ifdef DEBUG
if (g_getenv("TRG_SHOW_INCOMING") != NULL) {
- g_debug("<=(INcoming)<=: %s", reqrsp->raw);
+ g_debug("<=(INcoming)<=: %s", response->raw);
} else if (g_getenv("TRG_SHOW_INCOMING_PRETTY") != NULL) {
JsonGenerator *pg;
gsize len;
diff --git a/src/session-get.c b/src/session-get.c
index f9c94c6..25461d6 100644
--- a/src/session-get.c
+++ b/src/session-get.c
@@ -24,9 +24,14 @@
#include "protocol-constants.h"
#include "session-get.h"
+const gchar *session_get_version_string(JsonObject *s)
+{
+ return json_object_get_string_member(s, SGET_VERSION);
+}
+
int session_get_version(JsonObject *s, float *version)
{
- return sscanf(json_object_get_string_member(s, SGET_VERSION), "%g", version);
+ return sscanf(session_get_version_string(s), "%g", version);
}
gint64 session_get_download_dir_free_space(JsonObject *s)
diff --git a/src/session-get.h b/src/session-get.h
index 7b2d558..38ab6e9 100644
--- a/src/session-get.h
+++ b/src/session-get.h
@@ -73,6 +73,7 @@
const gchar *session_get_torrent_done_filename(JsonObject * s);
gboolean session_get_torrent_done_enabled(JsonObject * s);
gint64 session_get_cache_size_mb(JsonObject * s);
+const gchar *session_get_version_string(JsonObject *s);
int session_get_version(JsonObject *s, float *version);
gboolean session_get_pex_enabled(JsonObject * s);
gboolean session_get_lpd_enabled(JsonObject * s);
diff --git a/src/trg-client.c b/src/trg-client.c
index 3cedeff..7fcb40b 100644
--- a/src/trg-client.c
+++ b/src/trg-client.c
@@ -150,6 +150,12 @@ trg_client_new (void)
return tc;
}
+const gchar *trg_client_get_version_string(TrgClient *tc)
+{
+ TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
+ return session_get_version_string(priv->session);
+}
+
float trg_client_get_version(TrgClient *tc)
{
TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
@@ -595,19 +601,23 @@ int trg_http_perform(TrgClient * tc, gchar * reqstr, trg_response *reqrsp)
trg_response *dispatch(TrgClient * client, JsonNode * req)
{
- trg_response *response = g_new0(trg_response, 1);
- GError *decode_error = NULL;
- gchar *serialized;
- JsonNode *result;
-
- serialized = trg_serialize(req);
+ gchar *serialized = trg_serialize(req);
json_node_free(req);
#ifdef DEBUG
if (g_getenv("TRG_SHOW_OUTGOING"))
g_debug("=>(OUTgoing)=>: %s", serialized);
#endif
- trg_http_perform(client, serialized, response);
- g_free(serialized);
+ return dispatch_str(client, serialized);
+}
+
+trg_response *dispatch_str(TrgClient * client, gchar *req)
+{
+ trg_response *response = g_new0(trg_response, 1);
+ GError *decode_error = NULL;
+ JsonNode *result;
+
+ trg_http_perform(client, req, response);
+ g_free(req);
if (response->status != CURLE_OK)
return response;
@@ -633,31 +643,59 @@ trg_response *dispatch(TrgClient * client, JsonNode * req)
static void dispatch_async_threadfunc(trg_request *req,
TrgClient * client)
{
- trg_response *rsp = dispatch(client, req->node);
+ trg_response *rsp;
+
+ if (req->str)
+ rsp = dispatch_str(client, req->str);
+ else
+ rsp = dispatch(client, req->node);
+
rsp->cb_data = req->cb_data;
+
if (req->callback)
g_idle_add(req->callback, rsp);
+ else
+ trg_response_free(rsp);
+
g_free(req);
}
-gboolean dispatch_async(TrgClient * client, JsonNode * req,
+static gboolean dispatch_async_common(TrgClient * client, trg_request *trg_req,
GSourceFunc callback,
gpointer data)
{
GError *error = NULL;
- trg_request *trg_req = g_new(trg_request, 1);
trg_req->callback = callback;
trg_req->cb_data = data;
- trg_req->node = req;
trg_client_thread_pool_push(client, trg_req, &error);
if (error) {
g_error("thread creation error: %s\n", error->message);
g_error_free(error);
- g_free(req);
+ g_free(trg_req);
return FALSE;
} else {
return TRUE;
}
}
+
+gboolean dispatch_async(TrgClient * client, JsonNode *req,
+ GSourceFunc callback,
+ gpointer data)
+{
+ trg_request *trg_req = g_new0(trg_request, 1);
+ trg_req->node = req;
+
+ return dispatch_async_common(client, trg_req, callback, data);
+}
+
+gboolean dispatch_async_str(TrgClient * client, gchar *req,
+ GSourceFunc callback,
+ gpointer data)
+{
+ trg_request *trg_req = g_new0(trg_request, 1);
+ trg_req->str = req;
+
+ return dispatch_async_common(client, trg_req, callback, data);
+}
diff --git a/src/trg-client.h b/src/trg-client.h
index d6aa679..69424bd 100644
--- a/src/trg-client.h
+++ b/src/trg-client.h
@@ -31,6 +31,9 @@
#define TORRENT_GET_MODE_INTERACTION 2
#define TORRENT_GET_MODE_UPDATE 3
+#define TORRENT_GET_TAG_MODE_FULL -1
+#define TORRENT_GET_TAG_MODE_UPDATE -2
+
#define TRG_NO_HOSTNAME_SET -2
#define SESSION_UPDATE_DIVISOR 10
@@ -68,6 +71,7 @@ typedef struct {
typedef struct
{
JsonNode *node;
+ gchar *str;
GSourceFunc callback;
gpointer cb_data;
} trg_request;
@@ -121,6 +125,7 @@ int trg_http_perform(TrgClient * client, gchar * reqstr, trg_response *reqrsp);
/* stuff that used to be in dispatch.c */
trg_response *dispatch(TrgClient * client, JsonNode * req);
+trg_response *dispatch_str(TrgClient * client, gchar *req);
gboolean dispatch_async(TrgClient * client, JsonNode * req,
GSourceFunc callback,
gpointer data);
@@ -133,6 +138,7 @@ TrgPrefs* trg_client_get_prefs(TrgClient *tc);
int trg_client_populate_with_settings(TrgClient * tc);
void trg_client_set_session(TrgClient * tc, JsonObject * session);
float trg_client_get_version(TrgClient *tc);
+const gchar *trg_client_get_version_string(TrgClient *tc);
gint64 trg_client_get_rpc_version(TrgClient *tc);
gchar *trg_client_get_password(TrgClient *tc);
gchar *trg_client_get_username(TrgClient *tc);
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index 710ed4b..6c73b03 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -936,7 +936,7 @@ static gboolean trg_update_torrents_timerfunc(gpointer data) {
% trg_prefs_get_int(prefs,
TRG_PREFS_ACTIVEONLY_FULLSYNC_EVERY,
TRG_PREFS_PROFILE) != 0));
- dispatch_async(tc, torrent_get(activeOnly ? -2 : -1),
+ dispatch_async(tc, torrent_get(activeOnly ? TORRENT_GET_TAG_MODE_UPDATE : TORRENT_GET_TAG_MODE_FULL),
activeOnly ? on_torrent_get_active : on_torrent_get_update,
data);
@@ -1302,7 +1302,7 @@ static void status_icon_activated(GtkStatusIcon * icon G_GNUC_UNUSED, gpointer d
if (priv->timerId > 0)
{
g_source_remove(priv->timerId);
- dispatch_async(priv->client, torrent_get(-1),
+ dispatch_async(priv->client, torrent_get(TORRENT_GET_TAG_MODE_FULL),
on_torrent_get_first, data);
}
}
diff --git a/src/trg-stats-dialog.c b/src/trg-stats-dialog.c
index 87e04a7..98c8606 100644
--- a/src/trg-stats-dialog.c
+++ b/src/trg-stats-dialog.c
@@ -204,7 +204,7 @@ static gboolean on_stats_reply(gpointer data)
args = get_arguments(response->obj);
char versionStr[32];
- g_snprintf(versionStr, sizeof(versionStr), "Transmission %g", trg_client_get_version(priv->client));
+ g_snprintf(versionStr, sizeof(versionStr), "Transmission %s", trg_client_get_version_string(priv->client));
update_statistic(priv->rr_version, versionStr, "");
update_size_stat(args, priv->rr_up, "uploadedBytes");