BaseNotify.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "servant/BaseNotify.h"
  17. #include "servant/NotifyObserver.h"
  18. namespace tars
  19. {
  20. BaseNotify::BaseNotify()
  21. {
  22. }
  23. BaseNotify::~BaseNotify()
  24. {
  25. }
  26. void BaseNotify::addAdminCommandPrefix(const string& command, TAdminFunc func)
  27. {
  28. TC_LockT<TC_ThreadRecMutex> lock(*this);
  29. _procFunctors.insert(std::make_pair(command, func));
  30. _observer->registerPrefix(command, this);
  31. }
  32. void BaseNotify::addAdminCommandNormal(const string& command, TAdminFunc func)
  33. {
  34. TC_LockT<TC_ThreadRecMutex> lock(*this);
  35. _procFunctors.insert(std::make_pair(command, func));
  36. _observer->registerNotify(command, this);
  37. }
  38. bool BaseNotify::notify(const string& cmd, const string& params, CurrentPtr current, string& result)
  39. {
  40. TC_LockT<TC_ThreadRecMutex> lock(*this);
  41. map<string, TAdminFunc>::iterator it;
  42. it = _procFunctors.find(cmd);
  43. if (it != _procFunctors.end())
  44. {
  45. return (it->second)(cmd, params, result);
  46. }
  47. return false;
  48. }
  49. //////////////////////////////////////////////////////////////////
  50. }