spir.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include "spir.hpp"
  3. #include "spir_ffi.h"
  4. void SPIR::init(uint32_t num_threads)
  5. {
  6. spir_init(num_threads);
  7. }
  8. SPIR_Client::SPIR_Client(uint8_t r, string &pub_params)
  9. {
  10. ClientNewRet ret = spir_client_new(r);
  11. pub_params.assign(ret.pub_params.data, ret.pub_params.len);
  12. spir_vecdata_free(ret.pub_params);
  13. this->client = ret.client;
  14. }
  15. SPIR_Client::~SPIR_Client()
  16. {
  17. spir_client_free(this->client);
  18. }
  19. string SPIR_Client::preproc(uint32_t num_preproc)
  20. {
  21. VecData msg = spir_client_preproc(this->client, num_preproc);
  22. string ret(msg.data, msg.len);
  23. spir_vecdata_free(msg);
  24. return ret;
  25. }
  26. void SPIR_Client::preproc_finish(const string &server_preproc)
  27. {
  28. spir_client_preproc_finish(this->client, server_preproc.data(),
  29. server_preproc.length());
  30. }
  31. string SPIR_Client::query(size_t idx)
  32. {
  33. VecData msg = spir_client_query(this->client, idx);
  34. string ret(msg.data, msg.len);
  35. spir_vecdata_free(msg);
  36. return ret;
  37. }
  38. SPIR_Server::SPIR_Server(uint8_t r, const string &pub_params)
  39. {
  40. this->server = spir_server_new(r, pub_params.data(),
  41. pub_params.length());
  42. }
  43. SPIR_Server::~SPIR_Server()
  44. {
  45. spir_server_free(this->server);
  46. }
  47. string SPIR_Server::preproc_process(const string &msg)
  48. {
  49. VecData retmsg = spir_server_preproc_process(this->server, msg.data(),
  50. msg.length());
  51. string ret(retmsg.data, retmsg.len);
  52. spir_vecdata_free(retmsg);
  53. return ret;
  54. }