server.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef NET_GRPC_NODE_SERVER_H_
  19. #define NET_GRPC_NODE_SERVER_H_
  20. #include <nan.h>
  21. #include <node.h>
  22. #include "grpc/grpc.h"
  23. namespace grpc {
  24. namespace node {
  25. /* Wraps grpc_server as a JavaScript object. Provides a constructor
  26. and wrapper methods for grpc_server_create, grpc_server_request_call,
  27. grpc_server_add_http2_port, and grpc_server_start. */
  28. class Server : public Nan::ObjectWrap {
  29. public:
  30. /* Initializes the Server class and exposes the constructor and
  31. wrapper methods to JavaScript */
  32. static void Init(v8::Local<v8::Object> exports);
  33. /* Tests whether the given value was constructed by this class's
  34. JavaScript constructor */
  35. static bool HasInstance(v8::Local<v8::Value> val);
  36. void DestroyWrappedServer();
  37. private:
  38. explicit Server(grpc_server *server);
  39. ~Server();
  40. // Prevent copying
  41. Server(const Server &);
  42. Server &operator=(const Server &);
  43. void ShutdownServer();
  44. static NAN_METHOD(New);
  45. static NAN_METHOD(RequestCall);
  46. static NAN_METHOD(AddHttp2Port);
  47. static NAN_METHOD(Start);
  48. static NAN_METHOD(TryShutdown);
  49. static NAN_METHOD(ForceShutdown);
  50. static Nan::Callback *constructor;
  51. static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
  52. grpc_server *wrapped_server;
  53. grpc_completion_queue *shutdown_queue;
  54. };
  55. } // namespace node
  56. } // namespace grpc
  57. #endif // NET_GRPC_NODE_SERVER_H_