/xnee-3.13/libxnee/src/xnee_callback.c

# · C · 124 lines · 74 code · 14 blank · 36 comment · 6 complexity · fd0c2da0d322273cde896ed44499c094 MD5 · raw file

  1. /*****
  2. * Xnee's Not an Event Emulator
  3. *
  4. * Xnee enables recording and replaying of X protocol data
  5. *
  6. * Copyright (C) 1999, 2000, 2001, 2002, 2003
  7. * 2009 Henrik Sandklef
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 3
  12. * of the License, or any later version.
  13. *
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Boston,
  23. * MA 02110-1301, USA.
  24. ****/
  25. #include "libxnee/xnee.h"
  26. #include "libxnee/print.h"
  27. #include "libxnee/xnee_record.h"
  28. #include "libxnee/xnee_replay.h"
  29. #include "libxnee/xnee_sem.h"
  30. #include "libxnee/xnee_buffer.h"
  31. #include "libxnee/xnee_resolution.h"
  32. #include "libxnee/xnee_dl.h"
  33. #include "libxnee/xnee_callback.h"
  34. /**************************************************************
  35. * *
  36. * xnee_set_callback *
  37. * *
  38. * *
  39. **************************************************************/
  40. int
  41. xnee_set_callback (xnee_data *xd,
  42. callback_ptrptr dest,
  43. const char *sym_name)
  44. {
  45. const char *error;
  46. callback_ptr saved;
  47. xnee_verbose ((xd, "\nTrying to set \"%s\" as callback\n", sym_name));
  48. if (xd==NULL)
  49. {
  50. return XNEE_NO_MAIN_DATA;
  51. }
  52. else
  53. {
  54. saved = *dest;
  55. *(void**)(dest) = xnee_dlsym(xd,
  56. xd->plugin_handle,
  57. sym_name);
  58. error = xnee_dlerror(xd) ;
  59. if ( error != NULL)
  60. {
  61. xnee_verbose ((xd, "Failed to set \"%s\" from plugin\n", sym_name));
  62. *dest = saved ;
  63. fputs(error, stderr);
  64. return (XNEE_PLUGIN_FILE_ERROR);
  65. }
  66. else
  67. {
  68. xnee_verbose ((xd, "Function set \"%s\" OK \n", sym_name));
  69. }
  70. }
  71. return XNEE_OK;
  72. }
  73. /**************************************************************
  74. * *
  75. * xnee_set_synchronize *
  76. * *
  77. * *
  78. **************************************************************/
  79. int
  80. xnee_set_synchronize (xnee_data *xd,
  81. synch_ptrptr dest,
  82. const char *sym_name)
  83. {
  84. const char *error;
  85. synch_ptr saved;
  86. xnee_verbose ((xd, "\nTrying to set \"%s\" as callback\n", sym_name));
  87. saved = *dest;
  88. if (xd==NULL)
  89. {
  90. return XNEE_NO_MAIN_DATA;
  91. }
  92. else
  93. {
  94. dest = (synch_ptrptr) xnee_dlsym(xd,
  95. xd->plugin_handle,
  96. (const char*)sym_name);
  97. if ((error = xnee_dlerror(xd)) != NULL)
  98. {
  99. xnee_verbose ((xd, "Failed to set \"%s\" from plugin\n", sym_name));
  100. *dest = saved ;
  101. fputs(error, stderr);
  102. return (XNEE_PLUGIN_FILE_ERROR);
  103. }
  104. else
  105. {
  106. xnee_verbose ((xd, "Function set \"%s\" OK \n", sym_name));
  107. }
  108. }
  109. return XNEE_OK;
  110. }