sp_def.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef __SP_DEF_H__
  2. #define __SP_DEF_H__
  3. #pragma once
  4. #include "precompile.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #include "ErrorCode.h"
  9. #define SP_LOG_MAX_LEN 1023
  10. #define SP_PKT_TSX 0x00000000 // for sp_tsx
  11. #define SP_PKT_RPC 0x10000000 // for sp_rpc
  12. #define SP_PKT_LOG 0x20000000 // for sp_log
  13. #define SP_PKT_VAR 0x30000000 // for sp_var
  14. #define SP_PKT_MOD 0x40000000 // for sp_mod
  15. #define SP_PKT_SES 0x50000000 // for sp_ses
  16. #define SP_PKT_BCM 0x60000000 // for sp_bcm
  17. #define SP_PKT_NUM 7
  18. #define SP_PKT_MAX_NUM 15
  19. #define SP_GET_TYPE(x) ((x) & 0x0fffffff)
  20. #define SP_GET_PKT_TYPE(x) ((x) & 0xf0000000)
  21. #define SP_TYPE_SHIFT 28
  22. #define SP_INVALID_MOD_ID -1
  23. #define SP_INVALID_SVC_ID -1
  24. #define SP_INVALID_PKT_ID -1
  25. #define SP_SHELL_MOD_ID 0
  26. #define SP_SHELL_SVC_ID 0
  27. #define SP_MAX_MODULE 127
  28. #define SP_MAX_ENTITY 127
  29. #define SP_MAX_SYSEVT 127
  30. typedef struct sp_version_t {
  31. int major;
  32. int minor;
  33. int revision;
  34. int build;
  35. }sp_version_t;
  36. static __inline void sp_version_fulfill(sp_version_t* v, int major, int minor, int revision, int build)
  37. {
  38. v->major = major;
  39. v->minor = minor;
  40. v->revision = revision;
  41. v->build = build;
  42. }
  43. static __inline void sp_version_init(sp_version_t* v)
  44. {
  45. sp_version_fulfill(v, 0, 0, 0, 0);
  46. }
  47. static __inline void sp_version_copy(sp_version_t *dst, const sp_version_t *src)
  48. {
  49. dst->major = src->major;
  50. dst->minor = src->minor;
  51. dst->revision = src->revision;
  52. dst->build = src->build;
  53. }
  54. static __inline int sp_version_cmp(const sp_version_t *x, const sp_version_t *y)
  55. {
  56. if (x->major == y->major) {
  57. if (x->minor == y->minor) {
  58. if (x->revision == y->revision) {
  59. return x->build - y->build;
  60. } else {
  61. return x->revision - y->revision;
  62. }
  63. } else {
  64. return x->minor - y->minor;
  65. }
  66. } else {
  67. return x->major - y->major;
  68. }
  69. }
  70. static __inline int sp_version_equal(const sp_version_t *x, const sp_version_t *y)
  71. {
  72. return x->major == y->major && x->minor == y->minor && x->revision == y->revision && x->build == y->build;
  73. }
  74. static __inline int sp_version_equal_1(const sp_version_t *x, const sp_version_t *y)
  75. {
  76. return x->major == y->major;
  77. }
  78. static __inline int sp_version_equal_2(const sp_version_t *x, const sp_version_t *y)
  79. {
  80. return x->major == y->major && x->minor == y->minor;
  81. }
  82. static __inline int sp_version_equal_3(const sp_version_t *x, const sp_version_t *y)
  83. {
  84. return x->major == y->major && x->minor == y->minor && x->revision == y->revision;
  85. }
  86. static __inline int sp_version_is_valid(const sp_version_t *v)
  87. {
  88. return v->major + v->minor + v->revision + v->build;
  89. }
  90. /** prefer to using: void sp_dir_get_cur_drive(char* path) */
  91. //static __inline void sp_get_current_drive(char* drivePath)
  92. //{
  93. // char drive[_MAX_DRIVE] = "", dir[_MAX_DIR] = "", fname[_MAX_FNAME] = "", ext[_MAX_EXT] = "", chpath[MAX_PATH] = "";
  94. // GetModuleFileNameA(NULL, (LPSTR)chpath, sizeof(chpath));
  95. // _splitpath(chpath, drive, dir, fname, ext);
  96. // memcpy(drivePath, drive, sizeof(drive));
  97. //}
  98. #define sp_version_equal_4 sp_version_equal
  99. SPBASE_API const char* sp_strerror(int err);
  100. #ifdef __cplusplus
  101. } // extern "C" {
  102. #endif
  103. #endif //__SP_DEF_H__