rpcdb.x 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. const RESPONSE_SIZE = 50;
  2. const USERNAME_SIZE = 15;
  3. enum status {
  4. VALID = 0,
  5. INVALID_USER = 1,
  6. EXISTING_USER = 2,
  7. INVALID_SESSION_KEY = 3,
  8. SESSION_KEY_NOT_FOUND = 4,
  9. INVALID_REQUEST = 5,
  10. INVALID_DATA = 6,
  11. EXISTING_RECORD = 7,
  12. NO_DATA_FOUND = 8,
  13. NO_DB_FOUND = 9
  14. };
  15. /*-----------------data structs begin-----------------*/
  16. struct sensor_data {
  17. int sensor_id;
  18. float values<>;
  19. };
  20. struct sensor_stat {
  21. int sensor_id;
  22. float min;
  23. float max;
  24. float avg;
  25. float med;
  26. };
  27. enum command_type {
  28. LOGIN_CMD,
  29. LOGOUT_CMD,
  30. LOAD_CMD,
  31. STORE_CMD,
  32. ADD_CMD,
  33. DELETE_CMD,
  34. UPDATE_CMD,
  35. READ_CMD,
  36. READ_ALL_CMD,
  37. GET_STAT_CMD,
  38. GET_STAT_ALL_CMD,
  39. BAD_CMD
  40. };
  41. /*------------------data structs end------------------*/
  42. /*---------------response structs begin---------------*/
  43. struct login_response {
  44. status response;
  45. unsigned hyper session_key;
  46. };
  47. struct basic_response {
  48. status response;
  49. };
  50. struct sensor_response {
  51. status response;
  52. float values<>;
  53. };
  54. struct sensors_response {
  55. status response;
  56. sensor_data data<>;
  57. };
  58. struct stat_response {
  59. status response;
  60. sensor_stat stat;
  61. };
  62. struct stats_response {
  63. status response;
  64. sensor_stat stats<>;
  65. };
  66. struct bad_response {
  67. status response;
  68. };
  69. /*----------------response structs end----------------*/
  70. /*----------------request structs begin---------------*/
  71. struct login_request {
  72. string username<USERNAME_SIZE>;
  73. };
  74. struct logout_request {
  75. unsigned hyper session_key;
  76. string username<>;
  77. };
  78. struct basic_request {
  79. unsigned hyper session_key;
  80. };
  81. struct add_update_request {
  82. unsigned hyper session_key;
  83. sensor_data data;
  84. };
  85. struct sensor_request {
  86. unsigned hyper session_key;
  87. int sensor_id;
  88. };
  89. struct sensors_request {
  90. unsigned hyper session_key;
  91. sensor_data sensors<>;
  92. };
  93. /*-----------------request structs end----------------*/
  94. union request switch(command_type type) {
  95. case LOGIN_CMD:
  96. login_request login;
  97. case LOGOUT_CMD:
  98. logout_request logout;
  99. case LOAD_CMD:
  100. sensors_request load;
  101. case ADD_CMD:
  102. case UPDATE_CMD:
  103. add_update_request empty;
  104. case DELETE_CMD:
  105. case READ_CMD:
  106. case GET_STAT_CMD:
  107. sensor_request existing;
  108. case STORE_CMD:
  109. case READ_ALL_CMD:
  110. case GET_STAT_ALL_CMD:
  111. basic_request everything;
  112. };
  113. union response switch(command_type type) {
  114. case LOGIN_CMD:
  115. login_response login;
  116. case ADD_CMD:
  117. case UPDATE_CMD:
  118. case DELETE_CMD:
  119. case LOAD_CMD:
  120. case LOGOUT_CMD:
  121. basic_response active;
  122. case GET_STAT_CMD:
  123. stat_response get_stat;
  124. case GET_STAT_ALL_CMD:
  125. stats_response get_stat_all;
  126. case READ_CMD:
  127. sensor_response read;
  128. case STORE_CMD:
  129. case READ_ALL_CMD:
  130. sensors_response read_all;
  131. case BAD_CMD:
  132. bad_response bad;
  133. };
  134. program RPC_PROG {
  135. version RPC_VERS {
  136. response rpc_call(request) = 1;
  137. } = 1;
  138. } = 1;