ServantHelper.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/ServantHelper.h"
  17. namespace tars
  18. {
  19. ServantPtr ServantHelperManager::create(const string &sAdapter)
  20. {
  21. if(_adapter_servant.find(sAdapter) == _adapter_servant.end())
  22. {
  23. return NULL;
  24. }
  25. ServantPtr servant = NULL;
  26. //根据adapter查找servant名称
  27. string s = _adapter_servant[sAdapter];
  28. if(_servant_creator.find(s) != _servant_creator.end())
  29. {
  30. servant = _servant_creator[s]->create(s);
  31. }
  32. return servant;
  33. }
  34. void ServantHelperManager::setAdapterServant(const string &sAdapter, const string &sServant)
  35. {
  36. _adapter_servant[sAdapter] = sServant;
  37. _servant_adapter[sServant] = sAdapter;
  38. }
  39. bool ServantHelperManager::setDyeing(const string & sDyeingKey, const string & sDyeingServant,
  40. const string & sDyeingInterface)
  41. {
  42. TC_LockT<TC_SpinLock> lock(_mutex);
  43. _dyeingKey = sDyeingKey;
  44. _dyeingServant = sDyeingServant;
  45. _dyeingInterface = sDyeingInterface;
  46. _isDyeing = !sDyeingKey.empty();
  47. return true;
  48. }
  49. bool ServantHelperManager::isDyeingReq(const string & sKey, const string & sServant, const string & sInterface) const
  50. {
  51. TC_LockT<TC_SpinLock> lock(_mutex);
  52. return ((_dyeingKey == sKey) && (_dyeingServant == sServant) &&
  53. (_dyeingInterface == "" || _dyeingInterface == sInterface) );
  54. }
  55. }