diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gmrequest.c | 21 | ||||
-rw-r--r-- | src/gmrequest.h | 1 | ||||
-rw-r--r-- | src/ui/command.c | 9 | ||||
-rw-r--r-- | src/ui/command.h | 21 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 18 |
5 files changed, 50 insertions, 20 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c index 8b87a638..8ab37c61 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c | |||
@@ -118,6 +118,8 @@ void deserialize_GmResponse(iGmResponse *d, iStream *ins) { | |||
118 | 118 | ||
119 | /*----------------------------------------------------------------------------------------------*/ | 119 | /*----------------------------------------------------------------------------------------------*/ |
120 | 120 | ||
121 | static iAtomicInt idGen_; | ||
122 | |||
121 | enum iGmRequestState { | 123 | enum iGmRequestState { |
122 | initialized_GmRequestState, | 124 | initialized_GmRequestState, |
123 | receivingHeader_GmRequestState, | 125 | receivingHeader_GmRequestState, |
@@ -128,6 +130,7 @@ enum iGmRequestState { | |||
128 | 130 | ||
129 | struct Impl_GmRequest { | 131 | struct Impl_GmRequest { |
130 | iObject object; | 132 | iObject object; |
133 | uint32_t id; | ||
131 | iMutex * mtx; | 134 | iMutex * mtx; |
132 | iGmCerts * certs; /* not owned */ | 135 | iGmCerts * certs; /* not owned */ |
133 | enum iGmRequestState state; | 136 | enum iGmRequestState state; |
@@ -477,7 +480,8 @@ static void beginGopherConnection_GmRequest_(iGmRequest *d, const iString *host, | |||
477 | /*----------------------------------------------------------------------------------------------*/ | 480 | /*----------------------------------------------------------------------------------------------*/ |
478 | 481 | ||
479 | void init_GmRequest(iGmRequest *d, iGmCerts *certs) { | 482 | void init_GmRequest(iGmRequest *d, iGmCerts *certs) { |
480 | d->mtx = new_Mutex(); | 483 | d->mtx = new_Mutex(); |
484 | d->id = add_Atomic(&idGen_, 1) + 1; | ||
481 | d->resp = new_GmResponse(); | 485 | d->resp = new_GmResponse(); |
482 | d->isFilterEnabled = iTrue; | 486 | d->isFilterEnabled = iTrue; |
483 | d->isRespLocked = iFalse; | 487 | d->isRespLocked = iFalse; |
@@ -868,11 +872,18 @@ void unlockResponse_GmRequest(iGmRequest *d) { | |||
868 | } | 872 | } |
869 | } | 873 | } |
870 | 874 | ||
875 | uint32_t id_GmRequest(const iGmRequest *d) { | ||
876 | return d ? d->id : 0; | ||
877 | } | ||
878 | |||
871 | iBool isFinished_GmRequest(const iGmRequest *d) { | 879 | iBool isFinished_GmRequest(const iGmRequest *d) { |
872 | iBool done; | 880 | if (d) { |
873 | iGuardMutex(d->mtx, | 881 | iBool done; |
874 | done = (d->state == finished_GmRequestState || d->state == failure_GmRequestState)); | 882 | iGuardMutex(d->mtx, |
875 | return done; | 883 | done = (d->state == finished_GmRequestState || d->state == failure_GmRequestState)); |
884 | return done; | ||
885 | } | ||
886 | return iTrue; | ||
876 | } | 887 | } |
877 | 888 | ||
878 | enum iGmStatusCode status_GmRequest(const iGmRequest *d) { | 889 | enum iGmStatusCode status_GmRequest(const iGmRequest *d) { |
diff --git a/src/gmrequest.h b/src/gmrequest.h index 9f20e0eb..2cf9e4ff 100644 --- a/src/gmrequest.h +++ b/src/gmrequest.h | |||
@@ -73,6 +73,7 @@ void cancel_GmRequest (iGmRequest *); | |||
73 | iGmResponse * lockResponse_GmRequest (iGmRequest *); | 73 | iGmResponse * lockResponse_GmRequest (iGmRequest *); |
74 | void unlockResponse_GmRequest (iGmRequest *); | 74 | void unlockResponse_GmRequest (iGmRequest *); |
75 | 75 | ||
76 | uint32_t id_GmRequest (const iGmRequest *); /* unique ID */ | ||
76 | iBool isFinished_GmRequest (const iGmRequest *); | 77 | iBool isFinished_GmRequest (const iGmRequest *); |
77 | enum iGmStatusCode status_GmRequest (const iGmRequest *); | 78 | enum iGmStatusCode status_GmRequest (const iGmRequest *); |
78 | const iString * meta_GmRequest (const iGmRequest *); | 79 | const iString * meta_GmRequest (const iGmRequest *); |
diff --git a/src/ui/command.c b/src/ui/command.c index c5ca164e..3ae0f0c9 100644 --- a/src/ui/command.c +++ b/src/ui/command.c | |||
@@ -50,6 +50,15 @@ int arg_Command(const char *cmd) { | |||
50 | return argLabel_Command(cmd, "arg"); | 50 | return argLabel_Command(cmd, "arg"); |
51 | } | 51 | } |
52 | 52 | ||
53 | uint32_t argU32Label_Command(const char *cmd, const char *label) { | ||
54 | const iString *tok = tokenString_(label); | ||
55 | const char *ptr = strstr(cmd, cstr_String(tok)); | ||
56 | if (ptr) { | ||
57 | return strtoul(ptr + size_String(tok), NULL, 10); | ||
58 | } | ||
59 | return 0; | ||
60 | } | ||
61 | |||
53 | float argfLabel_Command(const char *cmd, const char *label) { | 62 | float argfLabel_Command(const char *cmd, const char *label) { |
54 | const iString *tok = tokenString_(label); | 63 | const iString *tok = tokenString_(label); |
55 | const char *ptr = strstr(cmd, cstr_String(tok)); | 64 | const char *ptr = strstr(cmd, cstr_String(tok)); |
diff --git a/src/ui/command.h b/src/ui/command.h index 43992b8e..10a29101 100644 --- a/src/ui/command.h +++ b/src/ui/command.h | |||
@@ -25,16 +25,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
25 | #include <the_Foundation/range.h> | 25 | #include <the_Foundation/range.h> |
26 | #include <the_Foundation/vec2.h> | 26 | #include <the_Foundation/vec2.h> |
27 | 27 | ||
28 | iBool equal_Command (const char *commandWithArgs, const char *command); | 28 | iBool equal_Command (const char *commandWithArgs, const char *command); |
29 | 29 | ||
30 | int arg_Command (const char *); /* arg: */ | 30 | int arg_Command (const char *); /* arg: */ |
31 | float argf_Command (const char *); /* arg: */ | 31 | float argf_Command (const char *); /* arg: */ |
32 | int argLabel_Command (const char *, const char *label); | 32 | int argLabel_Command (const char *, const char *label); |
33 | float argfLabel_Command (const char *, const char *label); | 33 | uint32_t argU32Label_Command (const char *, const char *label); |
34 | void * pointer_Command (const char *); /* ptr: */ | 34 | float argfLabel_Command (const char *, const char *label); |
35 | void * pointerLabel_Command (const char *, const char *label); | 35 | void * pointer_Command (const char *); /* ptr: */ |
36 | iInt2 coord_Command (const char *); | 36 | void * pointerLabel_Command (const char *, const char *label); |
37 | iInt2 dir_Command (const char *); | 37 | iInt2 coord_Command (const char *); |
38 | iInt2 dir_Command (const char *); | ||
38 | 39 | ||
39 | const iString * string_Command (const char *, const char *label); /* space-delimited */ | 40 | const iString * string_Command (const char *, const char *label); /* space-delimited */ |
40 | iRangecc range_Command (const char *, const char *label); /* space-delimited */ | 41 | iRangecc range_Command (const char *, const char *label); /* space-delimited */ |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 11baf9ee..cdf3faa5 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -442,13 +442,21 @@ static void requestUpdated_DocumentWidget_(iAnyObject *obj) { | |||
442 | iDocumentWidget *d = obj; | 442 | iDocumentWidget *d = obj; |
443 | const int wasUpdated = exchange_Atomic(&d->isRequestUpdated, iTrue); | 443 | const int wasUpdated = exchange_Atomic(&d->isRequestUpdated, iTrue); |
444 | if (!wasUpdated) { | 444 | if (!wasUpdated) { |
445 | postCommand_Widget(obj, "document.request.updated doc:%p request:%p", d, d->request); | 445 | postCommand_Widget(obj, |
446 | "document.request.updated doc:%p reqid:%u request:%p", | ||
447 | d, | ||
448 | id_GmRequest(d->request), | ||
449 | d->request); | ||
446 | } | 450 | } |
447 | } | 451 | } |
448 | 452 | ||
449 | static void requestFinished_DocumentWidget_(iAnyObject *obj) { | 453 | static void requestFinished_DocumentWidget_(iAnyObject *obj) { |
450 | iDocumentWidget *d = obj; | 454 | iDocumentWidget *d = obj; |
451 | postCommand_Widget(obj, "document.request.finished doc:%p request:%p", d, d->request); | 455 | postCommand_Widget(obj, |
456 | "document.request.finished doc:%p reqid:%u request:%p", | ||
457 | d, | ||
458 | id_GmRequest(d->request), | ||
459 | d->request); | ||
452 | } | 460 | } |
453 | 461 | ||
454 | static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { | 462 | static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { |
@@ -1060,7 +1068,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse | |||
1060 | if (d->state == ready_RequestState) { | 1068 | if (d->state == ready_RequestState) { |
1061 | return; | 1069 | return; |
1062 | } | 1070 | } |
1063 | const iBool isRequestFinished = !d->request || isFinished_GmRequest(d->request); | 1071 | const iBool isRequestFinished = isFinished_GmRequest(d->request); |
1064 | /* TODO: Do document update in the background. However, that requires a text metrics calculator | 1072 | /* TODO: Do document update in the background. However, that requires a text metrics calculator |
1065 | that does not try to cache the glyph bitmaps. */ | 1073 | that does not try to cache the glyph bitmaps. */ |
1066 | const enum iGmStatusCode statusCode = response->statusCode; | 1074 | const enum iGmStatusCode statusCode = response->statusCode; |
@@ -2103,7 +2111,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2103 | return iTrue; | 2111 | return iTrue; |
2104 | } | 2112 | } |
2105 | else if (equalWidget_Command(cmd, w, "document.request.updated") && | 2113 | else if (equalWidget_Command(cmd, w, "document.request.updated") && |
2106 | d->request && pointerLabel_Command(cmd, "request") == d->request) { | 2114 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { |
2107 | set_Block(&d->sourceContent, &lockResponse_GmRequest(d->request)->body); | 2115 | set_Block(&d->sourceContent, &lockResponse_GmRequest(d->request)->body); |
2108 | unlockResponse_GmRequest(d->request); | 2116 | unlockResponse_GmRequest(d->request); |
2109 | if (document_App() == d) { | 2117 | if (document_App() == d) { |
@@ -2114,7 +2122,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2114 | return iFalse; | 2122 | return iFalse; |
2115 | } | 2123 | } |
2116 | else if (equalWidget_Command(cmd, w, "document.request.finished") && | 2124 | else if (equalWidget_Command(cmd, w, "document.request.finished") && |
2117 | d->request && pointerLabel_Command(cmd, "request") == d->request) { | 2125 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { |
2118 | set_Block(&d->sourceContent, body_GmRequest(d->request)); | 2126 | set_Block(&d->sourceContent, body_GmRequest(d->request)); |
2119 | if (!isSuccess_GmStatusCode(status_GmRequest(d->request))) { | 2127 | if (!isSuccess_GmStatusCode(status_GmRequest(d->request))) { |
2120 | format_String(&d->sourceHeader, | 2128 | format_String(&d->sourceHeader, |