Guest User

Untitled

a guest
Oct 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. int zero_arg_variable_return_dbus_call(DBusGProxy * proxy, char * remoteMethod)
  2. {
  3.  
  4.  
  5. char *string;
  6. gint integer;
  7. gboolean booleanRet;
  8. GError *error = NULL;
  9. int pushCount =0 ;
  10.  
  11.  
  12. while (1)
  13. {
  14.  
  15. // try string
  16.  
  17. if (!dbus_g_proxy_call (proxy, remoteMethod, &error, G_TYPE_INVALID,
  18. G_TYPE_STRING, &string, G_TYPE_INVALID))
  19. {
  20. //ignore error and move on
  21. g_error_free (error);
  22. error=NULL;
  23. }
  24. else
  25. {
  26.  
  27. lua_pushstring(luaState,string);
  28. g_free (string);
  29. pushCount++;
  30. break;
  31.  
  32. }
  33. // try int
  34.  
  35. if (!dbus_g_proxy_call (proxy, remoteMethod, &error, G_TYPE_INVALID,
  36. G_TYPE_INT, &integer, G_TYPE_INVALID))
  37. {
  38. //ignore error and move on
  39. g_error_free (error);
  40. error=NULL;
  41. }
  42. else
  43. {
  44. lua_pushnumber(luaState,integer);
  45. pushCount++;
  46. break;
  47.  
  48. }
  49.  
  50. //try boolean
  51.  
  52. if (!dbus_g_proxy_call (proxy, remoteMethod, &error, G_TYPE_INVALID,
  53. G_TYPE_BOOLEAN, &booleanRet, G_TYPE_INVALID))
  54. {
  55. // last type to try -clear error outside
  56. }
  57. else
  58. {
  59.  
  60. lua_pushboolean(luaState,booleanRet);
  61. pushCount++;
  62. break;
  63.  
  64. }
  65.  
  66.  
  67. //give up
  68.  
  69. // remote method failed:
  70. // push error message to top of stack
  71. //PUSH_ERROR_MESSAGE(FUNCTION_CALL_ERROR,error->message);
  72. // free resources
  73. g_error_free (error);
  74. // better free the proxy before we exit
  75. closeProxy(proxy);
  76. // signal error
  77. //lua_error(luaState);
  78. //return prematurely - shouldn't reach here as we push the error to lua
  79.  
  80.  
  81. //lets just return nothing if we dont find the right type
  82. return 0;
  83.  
  84. }
  85.  
  86. /* Cleanup */
  87.  
  88. closeProxy(proxy);
  89.  
  90. //indicate one object was returned
  91. return pushCount;
  92.  
  93. }
Add Comment
Please, Sign In to add comment