main.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include <iostream>
  17. #include "servant/Communicator.h"
  18. #include "Hello.h"
  19. #include "Push.h"
  20. #include "util/tc_option.h"
  21. using namespace std;
  22. using namespace tars;
  23. using namespace TestApp;
  24. Communicator* _comm;
  25. static string helloObj = "TestApp.PushCallbackServer.PushObj@tcp -h 127.0.0.1 -p 9316";
  26. int g_count = 0;
  27. class PushCallbackImp : public PushPrxCallback
  28. {
  29. public:
  30. virtual void callback_pushMsg(tars::Int32 ret, const std::string& sRsp)
  31. {
  32. LOG_CONSOLE_DEBUG << ret << ", " << sRsp << endl;
  33. ++g_count;
  34. }
  35. };
  36. int main(int argc, char *argv[])
  37. {
  38. try
  39. {
  40. if (argc < 1)
  41. {
  42. cout << "Usage:" << argv[0] << "--config=conf " << endl;
  43. return 0;
  44. }
  45. TC_Option option;
  46. option.decode(argc, argv);
  47. _comm = new Communicator();
  48. TC_Config conf;
  49. conf.parseFile(option.getValue("config"));
  50. _comm->setProperty(conf);
  51. HelloPrx pPrx = _comm->stringToProxy<HelloPrx>(helloObj);
  52. pPrx->tars_set_push_callback(new PushCallbackImp());
  53. pPrx->registerPush();
  54. while(g_count < 10)
  55. {
  56. TC_Common::sleep(1);
  57. }
  58. }
  59. catch(exception &ex)
  60. {
  61. cout << ex.what() << endl;
  62. }
  63. cout << "main return." << endl;
  64. return 0;
  65. }