// File: tdv[P]boss/boss/src/service_registry/service_registry.cpp
// Function: Boss::ServiceRegistry::AddService(Boss::IServiceInfo*)
RetCode BOSS_CALL ServiceRegistry::AddService(IServiceInfo *service)
  {
    try
    {
      std::lock_guard<std::recursive_mutex> Lock(Mtx);
      if (!service)
        return Status::InvalidArgument;
      IServiceInfoPtr Info(service);
      ServiceId SrvId = 0;
      RetCode Res = Info->GetServiceId(&SrvId);
      if (Res != Status::Ok)
        return Res;
      RefObjPtr<IEnum> ClassIdsEnum;
      Res = Info->GetClassIds(ClassIdsEnum.GetPPtr());
      if (Res != Status::Ok)
        return Res;
      EnumHelper<IEntityId> ClassIdsEnumHelper(ClassIdsEnum);
      typedef std::vector<ClassId> ClassIdPool;
      ClassIdPool ClassIds;
      if (ClassIdsEnum->Reset() != Status::Ok)
        return Status::Fail;
      for (auto i = ClassIdsEnumHelper.First() ; i.Get() ; i = ClassIdsEnumHelper.Next())
      {
        ClassId ClsId = 0;
        Res = i->GetId(&ClsId);
        if (Res != Status::Ok)
          return Res;
        if (Services.find(ClsId) != std::end(Services))
          return Status::Fail;
        ClassIds.push_back(ClsId);
      }
      auto Pred = [&] (decltype(*ServicePool::const_iterator()) &info)
        {
          ServiceId Id = 0;
          return info.second->GetServiceId(&Id) == Status::Ok && Id == SrvId;
        };
      bool Exists = false;
      for (auto Iter : Services)
      {
        if (Pred(Iter))
        {
          Exists = true;
          break;
        }
      }
      if (Exists)
        return Status::AlreadyExists;
      for (auto const &i : ClassIds)
        Services[i] = Info;
    }
    catch (...)
    {
      return Status::Fail;
    }
    return Status::Ok;
  }

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x158(%rsp)
movq %rsi, 0x150(%rsp)
movq 0x158(%rsp), %rsi
movq %rsi, 0x70(%rsp)
addq $0x28, %rsi
leaq 0x148(%rsp), %rdi
callq 0x22340
jmp 0x1f5c7
cmpq $0x0, 0x150(%rsp)
jne 0x1f606
movl $0x5, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1fc5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x1fcbc
movq 0x150(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x22480
jmp 0x1f61d
movl $0x0, 0x12c(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x224c0
movq %rax, 0x68(%rsp)
jmp 0x1f63c
movq 0x68(%rsp), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
leaq 0x12c(%rsp), %rsi
callq *%rax
movl %eax, 0x64(%rsp)
jmp 0x1f658
movl 0x64(%rsp), %eax
movl %eax, 0x128(%rsp)
cmpl $0x0, 0x128(%rsp)
je 0x1f6bd
movl 0x128(%rsp), %eax
movl %eax, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1fc50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x1fcaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x1fca2
xorl %eax, %eax
movl %eax, %esi
leaq 0x120(%rsp), %rdi
callq 0x224d0
jmp 0x1f6d0
leaq 0x130(%rsp), %rdi
callq 0x224c0
movq %rax, 0x58(%rsp)
jmp 0x1f6e4
leaq 0x120(%rsp), %rdi
callq 0x22510
movq %rax, 0x50(%rsp)
jmp 0x1f6f8
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movl %eax, 0x4c(%rsp)
jmp 0x1f711
movl 0x4c(%rsp), %eax
movl %eax, 0x128(%rsp)
cmpl $0x0, 0x128(%rsp)
je 0x1f75d
movl 0x128(%rsp), %eax
movl %eax, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1fc43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x1fc95
leaq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x22520
jmp 0x1f774
leaq 0x118(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x22560
jmp 0x1f78b
leaq 0x110(%rsp), %rdi
callq 0x22610
leaq 0xf8(%rsp), %rdi
callq 0x22630
leaq 0x120(%rsp), %rdi
callq 0x22640
movq %rax, 0x40(%rsp)
jmp 0x1f7b9
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movl %eax, 0x3c(%rsp)
jmp 0x1f7cd
movl 0x3c(%rsp), %eax
cmpl $0x0, %eax
je 0x1f830
movl $0x2, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1fc29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x22610
jmp 0x1fc95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x1fc7b
leaq 0xf0(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x22650
jmp 0x1f847
jmp 0x1f849
leaq 0xf0(%rsp), %rdi
callq 0x226e0
movq %rax, 0x30(%rsp)
jmp 0x1f85d
movq 0x30(%rsp), %rax
cmpq $0x0, %rax
jne 0x1f891
movl $0x2, 0x138(%rsp)
jmp 0x1f9fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x1fa18
movl $0x0, 0xec(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x226f0
movq %rax, 0x28(%rsp)
jmp 0x1f8b0
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
movq 0x28(%rax), %rax
leaq 0xec(%rsp), %rsi
callq *%rax
movl %eax, 0x24(%rsp)
jmp 0x1f8cc
movl 0x24(%rsp), %eax
movl %eax, 0x128(%rsp)
cmpl $0x0, 0x128(%rsp)
je 0x1f8ff
movl 0x128(%rsp), %eax
movl %eax, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1f9fa
movq 0x70(%rsp), %rdi
addq $0x50, %rdi
leaq 0xec(%rsp), %rsi
callq 0x22370
movq %rax, 0x18(%rsp)
jmp 0x1f91c
movq 0x70(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, 0xe0(%rsp)
addq $0x50, %rdi
callq 0x223c0
movq %rax, 0x10(%rsp)
jmp 0x1f93e
movq 0x10(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x223a0
testb $0x1, %al
jne 0x1f966
jmp 0x1f97e
movl $0x2, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1f9fa
leaq 0xf8(%rsp), %rdi
leaq 0xec(%rsp), %rsi
callq 0x22700
jmp 0x1f995
jmp 0x1f997
leaq 0xd0(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x22770
jmp 0x1f9ae
leaq 0xf0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x228e0
jmp 0x1f9c5
leaq 0xd0(%rsp), %rdi
callq 0x22920
jmp 0x1f849
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x22920
jmp 0x1fa18
leaq 0xf0(%rsp), %rdi
callq 0x22920
movl 0x138(%rsp), %eax
subl $0x2, %eax
je 0x1fa2a
jmp 0x1fc29
leaq 0xf0(%rsp), %rdi
callq 0x22920
jmp 0x1fc7b
movq 0x70(%rsp), %rax
leaq 0x12c(%rsp), %rcx
movq %rcx, 0xc8(%rsp)
movb $0x0, 0xc7(%rsp)
addq $0x50, %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x22940
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x22970
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x223a0
testb $0x1, %al
jne 0x1fa9b
jmp 0x1fb55
leaq 0xb0(%rsp), %rdi
callq 0x229a0
movq %rax, %rsi
leaq 0x98(%rsp), %rdi
callq 0x229c0
jmp 0x1faba
leaq 0xc8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x1fd00
movb %al, 0xf(%rsp)
jmp 0x1fad5
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x1fadf
jmp 0x1fb1a
movb $0x1, 0xc7(%rsp)
movl $0x5, 0x138(%rsp)
jmp 0x1fb25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x22a00
jmp 0x1fc7b
movl $0x0, 0x138(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x22a00
movl 0x138(%rsp), %eax
testl %eax, %eax
je 0x1fb41
jmp 0x1fb3f
jmp 0x1fb55
jmp 0x1fb43
leaq 0xb0(%rsp), %rdi
callq 0x22a20
jmp 0x1fa7d
testb $0x1, 0xc7(%rsp)
je 0x1fb7a
movl $0x4, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
jmp 0x1fc29
leaq 0xf8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
callq 0x22a50
movq %rax, 0x88(%rsp)
movq 0x90(%rsp), %rdi
callq 0x22a80
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x22ab0
testb $0x1, %al
jne 0x1fbcf
jmp 0x1fc1e
leaq 0x88(%rsp), %rdi
callq 0x22af0
movq 0x70(%rsp), %rdi
movq %rax, 0x78(%rsp)
addq $0x50, %rdi
movq 0x78(%rsp), %rsi
callq 0x22b00
movq %rax, (%rsp)
jmp 0x1fbfa
movq (%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x22b30
jmp 0x1fc0d
jmp 0x1fc0f
leaq 0x88(%rsp), %rdi
callq 0x22ba0
jmp 0x1fbb4
movl $0x0, 0x138(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x22bc0
leaq 0x118(%rsp), %rdi
callq 0x22c20
leaq 0x120(%rsp), %rdi
callq 0x22c30
leaq 0x130(%rsp), %rdi
callq 0x22c50
leaq 0x148(%rsp), %rdi
callq 0x22460
movl 0x138(%rsp), %eax
testl %eax, %eax
je 0x1fc79
jmp 0x1fc77
jmp 0x1fcf1
jmp 0x1fce6
leaq 0xf8(%rsp), %rdi
callq 0x22bc0
leaq 0x118(%rsp), %rdi
callq 0x22c20
leaq 0x120(%rsp), %rdi
callq 0x22c30
leaq 0x130(%rsp), %rdi
callq 0x22c50
leaq 0x148(%rsp), %rdi
callq 0x22460
movq 0x140(%rsp), %rdi
callq 0x480e0
movl $0x2, 0x164(%rsp)
movl $0x1, 0x138(%rsp)
callq 0x48150
jmp 0x1fcf1
movl $0x0, 0x164(%rsp)
movl 0x164(%rsp), %eax
addq $0x168, %rsp            # imm = 0x168
retq