Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.26 KB | None | 0 0
  1. diff -Naur SDL2-2.0.10/src/haptic/DSDL_Log.h SDL2-2.0.10.x/src/haptic/DSDL_Log.h
  2. --- SDL2-2.0.10/src/haptic/DSDL_Log.h 1969-12-31 16:00:00.000000000 -0800
  3. +++ SDL2-2.0.10.x/src/haptic/DSDL_Log.h 2019-09-04 10:06:57.000000000 -0700
  4. @@ -0,0 +1,62 @@
  5. +#ifndef DSDL_LOG_H
  6. +#define DSDL_LOG_H
  7. +
  8. +#include <stdarg.h>
  9. +
  10. +#define DSDL_LOG_ENABLED 1
  11. +#define DSDL_LOG_ENABLE_BACKTRACE 0
  12. +#define DSDL_LOG_MAX_BACKTRACE 6
  13. +
  14. +#define DSDL_LOG_PATH "/tmp/sdl.log"
  15. +
  16. +/*
  17. + * All log operations are wrapped in macros. This serves two functions:
  18. + *
  19. + * 1. It makes it very quick and easy to convert the log calls into no-ops.
  20. + * 2. This allows us to transparently include function and line information.
  21. + */
  22. +#if DSDL_LOG_ENABLED
  23. +
  24. +#define DSDL_LOG(...) \
  25. + DSDL_Log__log(__func__, __LINE__, __VA_ARGS__)
  26. +
  27. +#if DSDL_LOG_ENABLE_BACKTRACE
  28. +#define DSDL_BACKTRACE(...) \
  29. + DSDL_Log__logBacktrace(__func__, __LINE__, 2, DSDL_LOG_MAX_BACKTRACE, __VA_ARGS__)
  30. +#else
  31. +#define DSDL_BACKTRACE(...) \
  32. + DSDL_LOG(__VA_ARGS__)
  33. +#endif
  34. +
  35. +#define DSDL_TRACE() \
  36. +do { \
  37. + DSDL_Log__printHeader(__func__, __LINE__); \
  38. + DSDL_Log__print("\n"); \
  39. +} while(0)
  40. +
  41. +#else
  42. +
  43. +#define DSDL_LOG(...) (void)0
  44. +#define DSDL_BACKTRACE(...) (void)0
  45. +#define DSDL_TRACE() (void)0
  46. +
  47. +#endif /* DSDL_LOG_ENABLED */
  48. +
  49. +/* Must be called before log functions will print anything */
  50. +void DSDL__init(void);
  51. +
  52. +/* Raw log operations */
  53. +int DSDL_Log__print(char const *format, ...)
  54. +__attribute__ ((format (printf, 1, 2)));
  55. +int DSDL_Log__vaPrint(const char * format, va_list ap);
  56. +int DSDL_Log__printHeader(const char *func, int line);
  57. +int DSDL_Log__printBacktrace(int skip, int max);
  58. +
  59. +/* These are just wrappers for the above */
  60. +int DSDL_Log__log(const char *func, int line, const char *format, ...)
  61. +__attribute__ ((format (printf, 3, 4)));
  62. +int DSDL_Log__logBacktrace(const char *func, int line, int skip, int max,
  63. + const char *format, ...)
  64. +__attribute__ ((format (printf, 5, 6)));
  65. +
  66. +#endif /* DSDL_LOG_H */
  67. diff -Naur SDL2-2.0.10/src/haptic/linux/SDL_syshaptic.c SDL2-2.0.10.x/src/haptic/linux/SDL_syshaptic.c
  68. --- SDL2-2.0.10/src/haptic/linux/SDL_syshaptic.c 2019-07-24 21:32:36.000000000 -0700
  69. +++ SDL2-2.0.10.x/src/haptic/linux/SDL_syshaptic.c 2019-09-04 10:06:12.000000000 -0700
  70. @@ -90,6 +90,53 @@
  71. (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0)
  72. #define EV_TEST(ev,f) \
  73. if (test_bit((ev), features)) ret |= (f);
  74. +
  75. +/* DSDL Sys Defs */
  76. +#include "../DSDL_Log.h"
  77. +
  78. +static const char *DSDL_FFName(int type) {
  79. + switch(type) {
  80. + case FF_RUMBLE:
  81. + return "FF_RUMBLE";
  82. + case FF_CONSTANT:
  83. + return "FF_CONSTANT";
  84. + case FF_PERIODIC:
  85. + return "FF_PERIODIC";
  86. + default:
  87. + return "FF_OTHER";
  88. + }
  89. +}
  90. +
  91. +static void DSDL_FFPrefix(struct ff_effect *e)
  92. +{
  93. + DSDL_Log__print("type=0x%x %s, id=%d, dir=%u, len=%u, del=%u",
  94. + (int)e->type,
  95. + DSDL_FFName(e->type),
  96. + (int)e->id,
  97. + (unsigned)e->direction,
  98. + (unsigned)e->replay.length,
  99. + (unsigned)e->replay.delay);
  100. +}
  101. +
  102. +static void DSDL_DumpEffect(struct ff_effect *e) {
  103. + DSDL_FFPrefix(e);
  104. +
  105. + switch (e->type) {
  106. + case FF_CONSTANT:
  107. + DSDL_Log__print("str=%d, alen%u, alev=%u, flen=%u, flev=%u\n",
  108. + (int)e->u.constant.level,
  109. + (unsigned)e->u.constant.envelope.attack_length,
  110. + (unsigned)e->u.constant.envelope.attack_level,
  111. + (unsigned)e->u.constant.envelope.fade_length,
  112. + (unsigned)e->u.constant.envelope.fade_level);
  113. + break;
  114. + default:
  115. + DSDL_Log__print("\n");
  116. + break;
  117. + };
  118. +}
  119. +/* End DSDL Sys Defs */
  120. +
  121. /*
  122. * Test whether a device has haptic properties.
  123. * Returns available properties or 0 if there are none.
  124. @@ -186,6 +233,7 @@
  125. SDL_UDEV_Scan();
  126. #endif /* SDL_USE_LIBUDEV */
  127.  
  128. +
  129. return numhaptics;
  130. }
  131.  
  132. @@ -389,6 +437,7 @@
  133. close(fd);
  134. }
  135.  
  136. + DSDL_LOG("name=%s\n", name);
  137. return name;
  138. }
  139.  
  140. @@ -399,6 +448,7 @@
  141. static int
  142. SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
  143. {
  144. + DSDL_TRACE();
  145. /* Allocate the hwdata */
  146. haptic->hwdata = (struct haptic_hwdata *)
  147. SDL_malloc(sizeof(*haptic->hwdata));
  148. @@ -454,6 +504,9 @@
  149. SDL_hapticlist_item *item;
  150.  
  151. item = HapticByDevIndex(haptic->index);
  152. +
  153. + DSDL_LOG("Open %s\n", item->fname);
  154. +
  155. /* Open the character device */
  156. fd = open(item->fname, O_RDWR, 0);
  157. if (fd < 0) {
  158. @@ -542,6 +595,8 @@
  159. int ret;
  160. SDL_hapticlist_item *item;
  161.  
  162. + DSDL_TRACE();
  163. +
  164. /* Find the joystick in the haptic list. */
  165. for (item = SDL_hapticlist; item; item = item->next) {
  166. if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
  167. @@ -922,7 +977,6 @@
  168. return 0;
  169. }
  170.  
  171. -
  172. /*
  173. * Creates a new haptic effect.
  174. */
  175. @@ -932,6 +986,8 @@
  176. {
  177. struct ff_effect *linux_effect;
  178.  
  179. + DSDL_TRACE();
  180. +
  181. /* Allocate the hardware effect */
  182. effect->hweffect = (struct haptic_hweffect *)
  183. SDL_malloc(sizeof(struct haptic_hweffect));
  184. @@ -942,17 +998,29 @@
  185. /* Prepare the ff_effect */
  186. linux_effect = &effect->hweffect->effect;
  187. if (SDL_SYS_ToFFEffect(linux_effect, base) != 0) {
  188. + DSDL_BACKTRACE("SDL_SYS_ToFFEffect failed\n");
  189. goto new_effect_err;
  190. }
  191. linux_effect->id = -1; /* Have the kernel give it an id */
  192. -
  193. +
  194. /* Upload the effect */
  195. if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
  196. + int err = errno;
  197. + char const * err_str = strerror(err);
  198. +
  199. + DSDL_BACKTRACE("New failed %s\n", err_str);
  200. SDL_SetError("Haptic: Error uploading effect to the device: %s",
  201. - strerror(errno));
  202. + err_str);
  203. goto new_effect_err;
  204. }
  205.  
  206. + /*
  207. + * Dump the effect after we call into the kernel, as the kernel assigns the
  208. + * effect index.
  209. + */
  210. + DSDL_LOG("New haptic=%p, effect=%p, ", haptic, effect);
  211. + DSDL_DumpEffect(linux_effect);
  212. +
  213. return 0;
  214.  
  215. new_effect_err:
  216. @@ -961,7 +1029,6 @@
  217. return -1;
  218. }
  219.  
  220. -
  221. /*
  222. * Updates an effect.
  223. *
  224. @@ -974,6 +1041,7 @@
  225. SDL_HapticEffect * data)
  226. {
  227. struct ff_effect linux_effect;
  228. + int retry_count = 0;
  229.  
  230. /* Create the new effect */
  231. if (SDL_SYS_ToFFEffect(&linux_effect, data) != 0) {
  232. @@ -981,10 +1049,44 @@
  233. }
  234. linux_effect.id = effect->hweffect->effect.id;
  235.  
  236. + DSDL_LOG("Update, haptic=%p, effect=%p, ", haptic, effect);
  237. + DSDL_DumpEffect(&linux_effect);
  238. +
  239. +retry:
  240. /* See if it can be uploaded. */
  241. if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
  242. - return SDL_SetError("Haptic: Error updating the effect: %s",
  243. - strerror(errno));
  244. + int err = errno;
  245. + char const * err_str = strerror(err);
  246. +
  247. + DSDL_BACKTRACE("Update failed %s\n", err_str);
  248. +
  249. + /*
  250. + * For some strange and inexplicable reason, the kernel driver appears
  251. + * to "forget" about our effect for... "reasons."
  252. + *
  253. + * The only difference between creating a "new" effect and "updating" an
  254. + * effect, in the kernel API, is the use of the effect id of "-1" to
  255. + * request a new id.
  256. + *
  257. + * If we get EINVAL, try to reinitialize the effect by setting the index
  258. + * back to -1, but don't retry more than once. EINVAL is pretty vague
  259. + * and there could be other causes.
  260. + */
  261. + if ((err == EINVAL) && (retry_count++ == 0)) {
  262. + DSDL_LOG("Retry as id -1\n");
  263. + linux_effect.id = -1;
  264. + goto retry;
  265. + }
  266. + return SDL_SetError("Haptic: Error updating the effect: %s", err_str);
  267. + }
  268. +
  269. + /*
  270. + * If this is non-zero, we have reinitialized the effect and we need to
  271. + * update the local copy of the index with whatever the kernel has assigned.
  272. + */
  273. + if (retry_count) {
  274. + DSDL_LOG("retry success, new id = %d\n", linux_effect.id);
  275. + effect->hweffect->effect.id = linux_effect.id;
  276. }
  277.  
  278. /* Copy the new effect into memory. */
  279. @@ -1010,8 +1112,13 @@
  280. /* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
  281. run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
  282.  
  283. + DSDL_LOG("Run: id=%d, itr=%d\n", (int)run.code, (int)run.value);
  284. if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) {
  285. - return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
  286. + int err = errno;
  287. + char const * err_str = strerror(err);
  288. +
  289. + DSDL_BACKTRACE("Run failed %s\n", err_str);
  290. + return SDL_SetError("Haptic: Unable to run the effect: %s", err_str);
  291. }
  292.  
  293. return 0;
  294. @@ -1030,7 +1137,10 @@
  295. stop.code = effect->hweffect->effect.id;
  296. stop.value = 0;
  297.  
  298. + DSDL_LOG("Stop: %d\n", (int)stop.code);
  299. +
  300. if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) {
  301. + DSDL_BACKTRACE("Stop failed!\n");
  302. return SDL_SetError("Haptic: Unable to stop the effect: %s",
  303. strerror(errno));
  304. }
  305. @@ -1045,9 +1155,13 @@
  306. void
  307. SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
  308. {
  309. + DSDL_LOG("Destroy: %d\n", (int)effect->hweffect->effect.id);
  310. if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
  311. + int rc = errno;
  312. +
  313. + DSDL_BACKTRACE("Destory failed! %d %s\n", rc, strerror(rc));
  314. SDL_SetError("Haptic: Error removing the effect from the device: %s",
  315. - strerror(errno));
  316. + strerror(rc));
  317. }
  318. SDL_free(effect->hweffect);
  319. effect->hweffect = NULL;
  320. @@ -1061,6 +1175,7 @@
  321. SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
  322. struct haptic_effect *effect)
  323. {
  324. + DSDL_LOG("Get status %d\n", (int)effect->hweffect->effect.id);
  325. #if 0 /* Not supported atm. */
  326. struct input_event ie;
  327.  
  328. @@ -1087,11 +1202,13 @@
  329. {
  330. struct input_event ie;
  331.  
  332. + DSDL_LOG("Set gain %d\n", (int)gain);
  333. ie.type = EV_FF;
  334. ie.code = FF_GAIN;
  335. ie.value = (0xFFFFUL * gain) / 100;
  336.  
  337. if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
  338. + DSDL_BACKTRACE("Set gain failed!\n");
  339. return SDL_SetError("Haptic: Error setting gain: %s", strerror(errno));
  340. }
  341.  
  342. @@ -1107,11 +1224,16 @@
  343. {
  344. struct input_event ie;
  345.  
  346. +
  347. ie.type = EV_FF;
  348. ie.code = FF_AUTOCENTER;
  349. ie.value = (0xFFFFUL * autocenter) / 100;
  350.  
  351. + DSDL_LOG("Set autocenter %d, %d\n", (int)autocenter, (int)ie.value);
  352. +
  353. if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
  354. + DSDL_BACKTRACE("Set autocenter failed!\n");
  355. +
  356. return SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno));
  357. }
  358.  
  359. @@ -1147,6 +1269,8 @@
  360. {
  361. int i, ret;
  362.  
  363. + DSDL_TRACE();
  364. +
  365. /* Linux does not support this natively so we have to loop. */
  366. for (i = 0; i < haptic->neffects; i++) {
  367. if (haptic->effects[i].hweffect != NULL) {
  368. diff -Naur SDL2-2.0.10/src/haptic/SDL_haptic.c SDL2-2.0.10.x/src/haptic/SDL_haptic.c
  369. --- SDL2-2.0.10/src/haptic/SDL_haptic.c 2019-07-24 21:32:36.000000000 -0700
  370. +++ SDL2-2.0.10.x/src/haptic/SDL_haptic.c 2019-09-04 09:53:09.000000000 -0700
  371. @@ -32,6 +32,173 @@
  372. static SDL_Haptic *SDL_haptics = NULL;
  373. #endif
  374.  
  375. +/* DSDL_Log */
  376. +#include "DSDL_Log.h"
  377. +#include <stdint.h>
  378. +#include <unistd.h>
  379. +#include <stdio.h>
  380. +#include <inttypes.h>
  381. +#include <time.h>
  382. +#include <execinfo.h>
  383. +
  384. +
  385. +struct DSDL_Log_ {
  386. + FILE *file;
  387. + uint64_t start_time;
  388. +};
  389. +
  390. +struct DSDL_Log_ DSDL_Log__static;
  391. +
  392. +static uint64_t DSDL__useconds(void)
  393. +{
  394. + struct timespec now;
  395. +
  396. + if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == 0) {
  397. + return ((uint64_t)now.tv_nsec / 1000UL) +
  398. + ((uint64_t)now.tv_sec * 1000UL * 1000UL);
  399. + }
  400. +
  401. + return 0;
  402. +}
  403. +
  404. +void
  405. +DSDL__init(void)
  406. +{
  407. + static const char *pathname = DSDL_LOG_PATH;
  408. +
  409. + if (DSDL_Log__static.file != NULL) {
  410. + return;
  411. + }
  412. +
  413. + DSDL_Log__static.start_time = DSDL__useconds();
  414. + DSDL_Log__static.file = fopen(pathname, "a");
  415. + DSDL_LOG("Log initialized\n");
  416. +}
  417. +
  418. +
  419. +int
  420. +DSDL_Log__vaPrint(const char * format, va_list ap)
  421. +{
  422. + int count = 0;
  423. +
  424. + if (DSDL_Log__static.file == NULL) {
  425. + return 0;
  426. + }
  427. +
  428. + count += vfprintf(DSDL_Log__static.file, format, ap);
  429. +
  430. + return count;
  431. +}
  432. +
  433. +int
  434. +DSDL_Log__print(char const *format, ...)
  435. +{
  436. + va_list ap;
  437. + int count;
  438. +
  439. + va_start (ap, format);
  440. + count = DSDL_Log__vaPrint(format, ap);
  441. + va_end (ap);
  442. +
  443. + return count;
  444. +}
  445. +
  446. +int
  447. +DSDL_Log__printHeader(const char *func, int line)
  448. +{
  449. + int count = 0;
  450. + uint64_t ts;
  451. + pid_t pid;
  452. +
  453. + ts = DSDL__useconds() - DSDL_Log__static.start_time;
  454. + pid = getpid();
  455. + count += DSDL_Log__print("%d %" PRIu64 " %s:%d: ", (int)pid, ts, func, line);
  456. +
  457. + return count;
  458. +}
  459. +
  460. +int
  461. +DSDL_Log__printBacktrace(int skip, int max)
  462. +{
  463. + static const int kMaxTrace = 32;
  464. +
  465. + void *trace_buf[kMaxTrace];
  466. + char **symbols;
  467. + size_t trace_size;
  468. + int size;
  469. + char **symbol;
  470. + char **end;
  471. + int count = 0;
  472. +
  473. +
  474. + size = kMaxTrace - skip;
  475. + size = max > size ? size : max;
  476. +
  477. + if (size <= 0) {
  478. + return 0;
  479. + }
  480. + trace_size = backtrace(trace_buf, size);
  481. + if (trace_size == 0) {
  482. + return 0;
  483. + }
  484. + size = trace_size - skip;
  485. +
  486. + symbols = backtrace_symbols(trace_buf + skip, size);
  487. + if (symbols == NULL) {
  488. + return 0;
  489. + }
  490. +
  491. + for (symbol = symbols, end = symbol + size; symbol != end; ++symbol) {
  492. + count += DSDL_Log__print(" %s\n", *symbol);
  493. + }
  494. + free(symbols);
  495. + return count;
  496. +}
  497. +
  498. +int
  499. +DSDL_Log__log(const char *func, int line, const char *format, ...)
  500. +{
  501. + va_list ap;
  502. + int count = 0;
  503. +
  504. + if (!DSDL_Log__static.file) {
  505. + return 0;
  506. + }
  507. + count = DSDL_Log__printHeader(func, line);
  508. +
  509. + va_start(ap, format);
  510. + count += DSDL_Log__vaPrint(format, ap);
  511. + va_end(ap);
  512. + fflush(DSDL_Log__static.file);
  513. +
  514. + return count;
  515. +}
  516. +
  517. +int
  518. +DSDL_Log__logBacktrace(const char *func, int line, int skip, int max,
  519. + const char *format, ...)
  520. +{
  521. + va_list ap;
  522. + int count = 0;
  523. +
  524. + if (!DSDL_Log__static.file) {
  525. + return 0;
  526. + }
  527. + count = DSDL_Log__printHeader(func, line);
  528. +
  529. + va_start(ap, format);
  530. + count += DSDL_Log__vaPrint(format, ap);
  531. + va_end(ap);
  532. +
  533. + count += DSDL_Log__printBacktrace(skip, max);
  534. + fflush(DSDL_Log__static.file);
  535. +
  536. + return count;
  537. +}
  538. +
  539. +
  540. +/* End DSDL_Log */
  541. +
  542. /*
  543. * Initializes the Haptic devices.
  544. */
  545. @@ -40,6 +207,10 @@
  546. {
  547. int status;
  548.  
  549. +#if DSDL_LOG_ENABLED
  550. + DSDL__init();
  551. +#endif
  552. +
  553. status = SDL_SYS_HapticInit();
  554. if (status >= 0) {
  555. status = 0;
  556. @@ -156,6 +327,8 @@
  557. haptic->next = SDL_haptics;
  558. SDL_haptics = haptic;
  559.  
  560. + DSDL_LOG("Opened device %d=%p\n", device_index, haptic);
  561. +
  562. /* Disable autocenter and set gain to max. */
  563. if (haptic->supported & SDL_HAPTIC_GAIN)
  564. SDL_HapticSetGain(haptic, 100);
  565. @@ -275,6 +448,8 @@
  566. SDL_Haptic *haptic;
  567. SDL_Haptic *hapticlist;
  568.  
  569. + DSDL_TRACE();
  570. +
  571. /* Make sure there is room. */
  572. if (SDL_NumHaptics() <= 0) {
  573. SDL_SetError("Haptic: There are %d haptic devices available",
  574. @@ -342,6 +517,8 @@
  575. SDL_Haptic *hapticlist;
  576. SDL_Haptic *hapticlistprev;
  577.  
  578. + DSDL_TRACE();
  579. +
  580. /* Must be valid */
  581. if (!ValidHaptic(haptic)) {
  582. return;
  583. @@ -393,6 +570,7 @@
  584. void
  585. SDL_HapticQuit(void)
  586. {
  587. + DSDL_TRACE();
  588. while (SDL_haptics) {
  589. SDL_HapticClose(SDL_haptics);
  590. }
  591. @@ -406,6 +584,7 @@
  592. int
  593. SDL_HapticNumEffects(SDL_Haptic * haptic)
  594. {
  595. + DSDL_TRACE();
  596. if (!ValidHaptic(haptic)) {
  597. return -1;
  598. }
  599. @@ -420,6 +599,7 @@
  600. int
  601. SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
  602. {
  603. + DSDL_TRACE();
  604. if (!ValidHaptic(haptic)) {
  605. return -1;
  606. }
  607. @@ -434,10 +614,12 @@
  608. unsigned int
  609. SDL_HapticQuery(SDL_Haptic * haptic)
  610. {
  611. + DSDL_TRACE();
  612. if (!ValidHaptic(haptic)) {
  613. return 0; /* same as if no effects were supported */
  614. }
  615.  
  616. + DSDL_LOG("Supported=0x%lx\n", (long)haptic->supported);
  617. return haptic->supported;
  618. }
  619.  
  620. @@ -448,6 +630,7 @@
  621. int
  622. SDL_HapticNumAxes(SDL_Haptic * haptic)
  623. {
  624. + DSDL_TRACE();
  625. if (!ValidHaptic(haptic)) {
  626. return -1;
  627. }
  628. @@ -483,8 +666,17 @@
  629. return -1;
  630. }
  631.  
  632. + if (effect == NULL) {
  633. + DSDL_BACKTRACE("NULL effect pointer\n");
  634. + SDL_SetError("Haptic: NULL effect.");
  635. +
  636. + return -1;
  637. + }
  638. +
  639. /* Check to see if effect is supported */
  640. if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
  641. + DSDL_BACKTRACE("Request for unsupported effect 0x%lx & 0x%lx == 0\n",
  642. + (unsigned long)haptic->supported, (unsigned long)effect->type);
  643. return SDL_SetError("Haptic: Effect not supported by haptic device.");
  644. }
  645.  
  646. @@ -495,15 +687,18 @@
  647. /* Now let the backend create the real effect */
  648. if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)
  649. != 0) {
  650. + DSDL_BACKTRACE("Backend failed to create effect\n");
  651. return -1; /* Backend failed to create effect */
  652. }
  653.  
  654. SDL_memcpy(&haptic->effects[i].effect, effect,
  655. sizeof(SDL_HapticEffect));
  656. + DSDL_LOG("effect index=%d\n", i);
  657. return i;
  658. }
  659. }
  660.  
  661. + DSDL_BACKTRACE("Haptic: Device has no free space left.\n");
  662. return SDL_SetError("Haptic: Device has no free space left.");
  663. }
  664.  
  665. @@ -533,6 +728,7 @@
  666.  
  667. /* Can't change type dynamically. */
  668. if (data->type != haptic->effects[effect].effect.type) {
  669. + DSDL_BACKTRACE("Updating effect type is illegal\n");
  670. return SDL_SetError("Haptic: Updating effect type is illegal.");
  671. }
  672.  
  673. @@ -555,6 +751,7 @@
  674. SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
  675. {
  676. if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
  677. + DSDL_BACKTRACE("Invalid effect %d\n", effect);
  678. return -1;
  679. }
  680.  
  681. @@ -573,7 +770,9 @@
  682. int
  683. SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
  684. {
  685. + DSDL_TRACE();
  686. if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
  687. + DSDL_BACKTRACE("Invalid effect %d\n", effect);
  688. return -1;
  689. }
  690.  
  691. @@ -591,6 +790,7 @@
  692. void
  693. SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
  694. {
  695. + DSDL_TRACE();
  696. if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
  697. return;
  698. }
  699. @@ -609,6 +809,7 @@
  700. int
  701. SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
  702. {
  703. + DSDL_TRACE();
  704. if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
  705. return -1;
  706. }
  707. @@ -629,15 +830,19 @@
  708. const char *env;
  709. int real_gain, max_gain;
  710.  
  711. + DSDL_LOG("Set gain=%d\n", gain);
  712. +
  713. if (!ValidHaptic(haptic)) {
  714. return -1;
  715. }
  716.  
  717. if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
  718. + DSDL_BACKTRACE("Device does not support setting gain\n");
  719. return SDL_SetError("Haptic: Device does not support setting gain.");
  720. }
  721.  
  722. if ((gain < 0) || (gain > 100)) {
  723. + DSDL_BACKTRACE("Gain must be between 0 and 100\n");
  724. return SDL_SetError("Haptic: Gain must be between 0 and 100.");
  725. }
  726.  
  727. @@ -671,6 +876,8 @@
  728. int
  729. SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
  730. {
  731. + DSDL_LOG("autocenter=%d\n", autocenter);
  732. +
  733. if (!ValidHaptic(haptic)) {
  734. return -1;
  735. }
  736. @@ -696,6 +903,7 @@
  737. int
  738. SDL_HapticPause(SDL_Haptic * haptic)
  739. {
  740. + DSDL_TRACE();
  741. if (!ValidHaptic(haptic)) {
  742. return -1;
  743. }
  744. @@ -713,6 +921,7 @@
  745. int
  746. SDL_HapticUnpause(SDL_Haptic * haptic)
  747. {
  748. + DSDL_TRACE();
  749. if (!ValidHaptic(haptic)) {
  750. return -1;
  751. }
  752. @@ -730,6 +939,7 @@
  753. int
  754. SDL_HapticStopAll(SDL_Haptic * haptic)
  755. {
  756. + DSDL_TRACE();
  757. if (!ValidHaptic(haptic)) {
  758. return -1;
  759. }
  760. @@ -743,6 +953,7 @@
  761. int
  762. SDL_HapticRumbleSupported(SDL_Haptic * haptic)
  763. {
  764. + DSDL_TRACE();
  765. if (!ValidHaptic(haptic)) {
  766. return -1;
  767. }
  768. @@ -759,6 +970,7 @@
  769. {
  770. SDL_HapticEffect *efx = &haptic->rumble_effect;
  771.  
  772. + DSDL_TRACE();
  773. if (!ValidHaptic(haptic)) {
  774. return -1;
  775. }
  776. @@ -802,6 +1014,7 @@
  777. SDL_HapticEffect *efx;
  778. Sint16 magnitude;
  779.  
  780. + DSDL_TRACE();
  781. if (!ValidHaptic(haptic)) {
  782. return -1;
  783. }
  784. @@ -842,6 +1055,7 @@
  785. int
  786. SDL_HapticRumbleStop(SDL_Haptic * haptic)
  787. {
  788. + DSDL_TRACE();
  789. if (!ValidHaptic(haptic)) {
  790. return -1;
  791. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement