Commit cf18786fd952424c71ca61d5ca60635d490dc3ca

Authored by Perry Werneck
1 parent b27ded84
Exists in master and in 1 other branch develop

Implementing get/set string methods.

Showing 2 changed files with 164 additions and 10 deletions   Show diff stats
src/linux/gobject.c
... ... @@ -143,16 +143,51 @@ void ipc3270_set_session(GObject *object, H3270 *hSession, const char *name, GEr
143 143 // Introspection data for the service we are exporting
144 144 GString * introspection = g_string_new(
145 145 "<node>\n"
146   - " <interface name='br.com.bb.tn3270'>"
147   - " <method name='connect'>"
148   - " <arg type='s' name='url' direction='in'/>"
149   - " </method>"
150   - " <method name='pfkey'>" \
151   - " <arg type='i' name='keycode' direction='in'/>" \
152   - " </method>"
153   - " <method name='pakey'>" \
154   - " <arg type='i' name='keycode' direction='in'/>" \
155   - " </method>"
  146 + " <interface name='br.com.bb.tn3270'>"
  147 + " <method name='connect'>"
  148 + " <arg type='s' name='url' direction='in'/>"
  149 + " <arg type='i' name='result' direction='out' />" \
  150 + " </method>"
  151 + " <method name='pfkey'>" \
  152 + " <arg type='i' name='keycode' direction='in'/>" \
  153 + " <arg type='i' name='result' direction='out' />" \
  154 + " </method>"
  155 + " <method name='pakey'>" \
  156 + " <arg type='i' name='keycode' direction='in'/>" \
  157 + " <arg type='i' name='result' direction='out' />" \
  158 + " </method>"
  159 + " <method name='getString'>" \
  160 + " <arg type='s' name='text' direction='out' />" \
  161 + " </method>" \
  162 + " <method name='setString'>" \
  163 + " <arg type='s' name='text' direction='in' />" \
  164 + " <arg type='i' name='result' direction='out' />" \
  165 + " </method>" \
  166 + " <method name='setStringAt'>" \
  167 + " <arg type='i' name='row' direction='in' />" \
  168 + " <arg type='i' name='col' direction='in' />" \
  169 + " <arg type='s' name='text' direction='in' />" \
  170 + " <arg type='i' name='result' direction='out' />" \
  171 + " </method>" \
  172 + " <method name= 'getStringAt'>" \
  173 + " <arg type='i' name='row' direction='in' />" \
  174 + " <arg type='i' name='col' direction='in' />" \
  175 + " <arg type='i' name='len' direction='in' />" \
  176 + " <arg type='y' name='lf' direction='in' />" \
  177 + " <arg type='s' name='text' direction='out' />" \
  178 + " </method>" \
  179 + " <method name='setStringAtAddress'>" \
  180 + " <arg type='i' name='addr' direction='in' />" \
  181 + " <arg type='s' name='text' direction='in' />" \
  182 + " <arg type='i' name='result' direction='out' />" \
  183 + " </method>" \
  184 + " <method name= 'getStringAtAddress'>" \
  185 + " <arg type='i' name='addr' direction='in' />" \
  186 + " <arg type='i' name='len' direction='in' />" \
  187 + " <arg type='y' name='lf' direction='in' />" \
  188 + " <arg type='s' name='text' direction='out' />" \
  189 + " </method>"
  190 +
156 191 );
157 192  
158 193 // Constrói métodos usando a tabela de controle
... ...
src/linux/methods.c
... ... @@ -54,6 +54,125 @@ ipc3270_method_call (GDBusConnection *connection,
54 54 size_t ix;
55 55 g_autoptr (GError) error = NULL;
56 56  
  57 + if(!g_ascii_strcasecmp(method_name,"getString"))
  58 + {
  59 + char * text = lib3270_get_string_at_address(IPC3270(user_data)->hSession,0,-1,'\n');
  60 +
  61 + if(!text)
  62 + {
  63 + g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  64 + g_dbus_method_invocation_return_gerror(invocation, error);
  65 + }
  66 + else
  67 + {
  68 + g_dbus_method_invocation_return_value (invocation, g_variant_new_string(text));
  69 + lib3270_free(text);
  70 + }
  71 +
  72 + return;
  73 + }
  74 + else if(!g_ascii_strcasecmp(method_name,"setString"))
  75 + {
  76 + gchar *text = NULL;
  77 + g_variant_get(parameters, "(&s)", &text);
  78 +
  79 + if(lib3270_input_string(IPC3270(user_data)->hSession,(const unsigned char *) text) < 0)
  80 + {
  81 + // Failed!
  82 + g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  83 + g_dbus_method_invocation_return_gerror(invocation, error);
  84 + }
  85 + else
  86 + {
  87 + // Suceeded
  88 + g_dbus_method_invocation_return_value (invocation, g_variant_new_int16((gint16) 0));
  89 + }
  90 +
  91 + return;
  92 + }
  93 + else if(!g_ascii_strcasecmp(method_name,"setStringAt"))
  94 + {
  95 + gint row,col;
  96 + gchar *text = NULL;
  97 + g_variant_get(parameters, "(ii&s)", &row, &col, &text);
  98 +
  99 + if(lib3270_set_string_at(IPC3270(user_data)->hSession,row,col,(const unsigned char *) text) < 0)
  100 + {
  101 + // Failed!
  102 + g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  103 + g_dbus_method_invocation_return_gerror(invocation, error);
  104 + }
  105 + else
  106 + {
  107 + // Suceeded
  108 + g_dbus_method_invocation_return_value (invocation, g_variant_new_int16((gint16) 0));
  109 + }
  110 +
  111 + return;
  112 + }
  113 + else if(!g_ascii_strcasecmp(method_name,"getStringAt"))
  114 + {
  115 + gint row,col,len;
  116 + guchar lf;
  117 + g_variant_get(parameters, "(iiy)", &row, &col, &len,&lf);
  118 +
  119 + char * text = lib3270_get_string_at(IPC3270(user_data)->hSession, row, col, len, lf);
  120 +
  121 + if(!text)
  122 + {
  123 + g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  124 + g_dbus_method_invocation_return_gerror(invocation, error);
  125 + }
  126 + else
  127 + {
  128 + g_dbus_method_invocation_return_value (invocation, g_variant_new_string(text));
  129 + lib3270_free(text);
  130 + }
  131 +
  132 + return;
  133 + }
  134 + else if(!g_ascii_strcasecmp(method_name,"setStringAtAddress"))
  135 + {
  136 + gint addr;
  137 + gchar *text = NULL;
  138 + g_variant_get(parameters, "(i&s)", &addr, &text);
  139 +
  140 + if(lib3270_set_string_at_address(IPC3270(user_data)->hSession,addr,(unsigned char *) text) < 0)
  141 + {
  142 + // Failed!
  143 + g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  144 + g_dbus_method_invocation_return_gerror(invocation, error);
  145 + }
  146 + else
  147 + {
  148 + // Suceeded
  149 + g_dbus_method_invocation_return_value (invocation, g_variant_new_int16((gint16) 0));
  150 + }
  151 +
  152 + return;
  153 + }
  154 + else if(!g_ascii_strcasecmp(method_name,"getStringAtAddress"))
  155 + {
  156 + gint addr,len;
  157 + guchar lf;
  158 + g_variant_get(parameters, "(iiy)", &addr, &len, &lf);
  159 +
  160 + char * text = lib3270_get_string_at_address(IPC3270(user_data)->hSession, addr, len, lf);
  161 +
  162 + if(!text)
  163 + {
  164 + g_set_error(&error,IPC3270(user_data)->error_domain,errno,"%s: %s",method_name,strerror(errno));
  165 + g_dbus_method_invocation_return_gerror(invocation, error);
  166 + }
  167 + else
  168 + {
  169 + g_dbus_method_invocation_return_value (invocation, g_variant_new_string(text));
  170 + lib3270_free(text);
  171 + }
  172 +
  173 + return;
  174 +
  175 + }
57 176 // Check action table.
58 177 const LIB3270_ACTION_ENTRY * actions = lib3270_get_action_table();
59 178 for(ix = 0; actions[ix].name; ix++)
... ...