summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-04-25 08:57:59 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-25 08:57:59 +0300
commit7887ec31b59b40dcfa7eca225fbc788e2c961727 (patch)
tree865f94b57666fd9adf6699310377ded0a86b42c6 /src/ui
parentd57240fea98543eb5b0394a3e01268ee2e08b6ec (diff)
GmRequest: Use unique IDs to avoid confusion
It is conceivable that a newly created GmRequest gets the same memory location than the one just destroyed. IssueID #148
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/command.c9
-rw-r--r--src/ui/command.h21
-rw-r--r--src/ui/documentwidget.c18
3 files changed, 33 insertions, 15 deletions
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
53uint32_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
53float argfLabel_Command(const char *cmd, const char *label) { 62float 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
28iBool equal_Command (const char *commandWithArgs, const char *command); 28iBool equal_Command (const char *commandWithArgs, const char *command);
29 29
30int arg_Command (const char *); /* arg: */ 30int arg_Command (const char *); /* arg: */
31float argf_Command (const char *); /* arg: */ 31float argf_Command (const char *); /* arg: */
32int argLabel_Command (const char *, const char *label); 32int argLabel_Command (const char *, const char *label);
33float argfLabel_Command (const char *, const char *label); 33uint32_t argU32Label_Command (const char *, const char *label);
34void * pointer_Command (const char *); /* ptr: */ 34float argfLabel_Command (const char *, const char *label);
35void * pointerLabel_Command (const char *, const char *label); 35void * pointer_Command (const char *); /* ptr: */
36iInt2 coord_Command (const char *); 36void * pointerLabel_Command (const char *, const char *label);
37iInt2 dir_Command (const char *); 37iInt2 coord_Command (const char *);
38iInt2 dir_Command (const char *);
38 39
39const iString * string_Command (const char *, const char *label); /* space-delimited */ 40const iString * string_Command (const char *, const char *label); /* space-delimited */
40iRangecc range_Command (const char *, const char *label); /* space-delimited */ 41iRangecc 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
449static void requestFinished_DocumentWidget_(iAnyObject *obj) { 453static 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
454static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { 462static 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,