sp_rsn.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "precompile.h"
  2. #include "memutil.h"
  3. #include "sp_rsn.h"
  4. void sp_rsn_context_init_original(sp_uid_t rsn, int original_type, sp_rsn_context_t *ctx)
  5. {
  6. ctx->depth = 0;
  7. ctx->original_type = original_type;
  8. ctx->previous_rsn = SP_RSN_UNKNOWN;
  9. ctx->current_rsn = rsn;
  10. }
  11. void sp_rsn_context_init_downstream(sp_uid_t rsn, const sp_rsn_context_t *upstream, sp_rsn_context_t *ctx)
  12. {
  13. ctx->depth = upstream->depth + 1;
  14. ctx->original_type = upstream->original_type;
  15. ctx->previous_rsn = upstream->current_rsn;
  16. ctx->current_rsn = rsn;
  17. }
  18. sp_rsn_context_t *sp_rsn_context_create_original(sp_uid_t rsn, int original_type)
  19. {
  20. sp_rsn_context_t *ctx = MALLOC_T(sp_rsn_context_t);
  21. if (ctx) {
  22. sp_rsn_context_init_original(rsn, original_type, ctx);
  23. }
  24. return ctx;
  25. }
  26. sp_rsn_context_t *sp_rsn_context_create_downstream(sp_uid_t rsn, const sp_rsn_context_t *upstream)
  27. {
  28. sp_rsn_context_t *ctx = MALLOC_T(sp_rsn_context_t);
  29. if (ctx) {
  30. sp_rsn_context_init_downstream(rsn, upstream, ctx);
  31. }
  32. return ctx;
  33. }
  34. void sp_rsn_context_destroy(sp_rsn_context_t *ctx)
  35. {
  36. free(ctx);
  37. }
  38. void sp_rsn_context_copy(sp_rsn_context_t *dst_ctx, const sp_rsn_context_t *src_ctx)
  39. {
  40. dst_ctx->previous_rsn = src_ctx->previous_rsn;
  41. dst_ctx->current_rsn = src_ctx->current_rsn;
  42. dst_ctx->original_type = src_ctx->original_type;
  43. dst_ctx->depth = src_ctx->depth;
  44. }
  45. sp_rsn_context_t *sp_rsn_context_clone(const sp_rsn_context_t *src_ctx)
  46. {
  47. sp_rsn_context_t *dst_ctx = MALLOC_T(sp_rsn_context_t);
  48. if (dst_ctx) {
  49. sp_rsn_context_copy(dst_ctx, src_ctx);
  50. }
  51. return dst_ctx;
  52. }