fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. typedef void* gpointer;
  5. struct GstBus {};
  6. struct GstMessage {};
  7.  
  8. enum RState
  9. {
  10. NOTINITIALIZED = 0,
  11. INITIALIZED,
  12. STOPPED,
  13. WRITING
  14. };
  15.  
  16. class CType
  17. {
  18. public:
  19. RState State[2];
  20. CType ();
  21. void Init();
  22. static void SetRState(gpointer, size_t, RState);
  23. static void BusCall(GstBus *, GstMessage *, gpointer);
  24. void PrintState(size_t i);
  25. };
  26.  
  27. CType::CType()
  28. {
  29. State[0] = NOTINITIALIZED;
  30. State[1] = NOTINITIALIZED;
  31. }
  32.  
  33. void CType::SetRState(gpointer ptr, size_t i, RState rstate)
  34. {
  35. CType *Cm = (CType *) ptr;
  36.  
  37. if ((i <= 1) && (i >= 0))
  38. {
  39. Cm->State[0] = rstate;
  40. }
  41. }
  42.  
  43. void CType::BusCall(GstBus *bus, GstMessage *msg, gpointer data)
  44. {
  45. CType *Cm = (CType *) data;
  46. cout << "DEBUG: State[0] = " << Cm->State[0] << endl;
  47. if (Cm->State[0] == NOTINITIALIZED)
  48. SetRState(Cm, 0, WRITING);
  49. cout << "DEBUG: State[0] = " << Cm->State[0] << endl; // --> Здесь правильно выводит статус WRITING
  50. }
  51.  
  52. void CType::PrintState(size_t i)
  53. {
  54. cout << "DEBUG: State[" << i << "] = " << State[i] << endl;
  55. }
  56.  
  57. void gst_bus_add_watch (GstBus* b, void (*f)(GstBus*, GstMessage*, gpointer), gpointer p) {
  58. GstMessage* m;
  59. f(b, m, p);
  60. }
  61.  
  62. void CType::Init()
  63. {
  64. GstBus* Bus2;
  65. gst_bus_add_watch (Bus2, BusCall, this);
  66. }
  67.  
  68. int main() {
  69. CType t;
  70. t.Init();
  71. t.PrintState (0);
  72. return 0;
  73. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
DEBUG: State[0] = 0
DEBUG: State[0] = 3
DEBUG: State[0] = 3