// File: /workspace/github_cpp_makefile_star2_O2/tdv[P]boss/boss/src/regtool/main.cpp
// Function: main
int main(int argc, char const **argv)
{
  try
  {
    if (argc < 2)
    {
      ShowHelp();
      return -1;
    }
    
    if (argc == 2 && !std::strcmp(argv[1], "-help"))
    {
      ShowHelp();
      return 0;
    }
    
    if (argc != 4)
    {
      std::cout << "Bad params." << std::endl;
      return -1;
    }
    
    std::string RegistryFilePath = argv[2];

    auto Reg = Boss::Base<Boss::ServiceRegistry>::Create();
    Boss::RefObjQIPtr<Boss::IServiceRegistryCtrl> Ctrl(Reg);    
    if (!Ctrl.Get())
      throw std::runtime_error("Failed to get RegCtrl.");
    Boss::RefObjQIPtr<Boss::ISerializable> Serializable(Ctrl);
    if (!Serializable.Get())
      throw std::runtime_error("Failed to get ISerializable interface from Registry object.");
    
    if (!std::strcmp(argv[1], "-reg"))
    {
      std::string ModulePath = argv[3];
      
      try
      {
        Load(Serializable, RegistryFilePath);
      }
      catch (std::exception const &)
      {
      }

      auto Info = Boss::Base<Boss::LocalServiceInfo>::Create();
      {
        auto Module = Boss::ModuleHolder(std::move(Boss::DllHolder(ModulePath)));
        
        Info->SetModulePath(ModulePath);
        Info->SetServiceId(Module.GetServiceId());
        
        for (auto const &i : Module.GetClassIds())
          Info->AddCoClassId(i);
        
        if (Ctrl->AddService(Info.Get()) != Boss::Status::Ok)
        {
          std::cout << "Failed to reg service." << std::endl;
          return -1;
        }
        
        Save(Serializable, RegistryFilePath);
      }
      return 0;
    }
    if (!std::strcmp(argv[1], "-unreg"))
    {
      std::string ServiceName = argv[3];
      
      Load(Serializable, RegistryFilePath);
      
      if (Ctrl->DelService(Boss::Crc32(ServiceName.c_str(), ServiceName.length())) != Boss::Status::Ok)
      {
        std::cout << "Failed to reg service." << std::endl;
        return -1;
      }
      
      Save(Serializable, RegistryFilePath);

      return 0;
    }
    
    std::cout << "Bad params." << std::endl;
    return -1;
    
  }
  catch (std::exception const &e)
  {
    std::cout << e.what() << std::endl;
  }
  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xa0, %rsp
cmpl $0x1, %edi
jg 0x26354
callq 0x261e7
jmp 0x26394
movq %rsi, %rbx
cmpl $0x4, %edi
je 0x263a6
cmpl $0x2, %edi
jne 0x26379
movq 0x8(%rbx), %rdi
leaq 0xb2a7d(%rip), %rsi     # 0xd8de9
callq 0x19500
testl %eax, %eax
je 0x2644a
leaq 0xfd100(%rip), %rdi     # 0x123480
leaq 0xb2a68(%rip), %rsi     # 0xd8def
callq 0x95250
movq %rax, %rdi
callq 0x94b30
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x10(%rbx), %rsi
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0xa7de0
leaq 0x40(%rsp), %rdi
callq 0x269ca
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x26a3c
cmpq $0x0, 0x10(%rsp)
je 0x2668c
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x26a56
cmpq $0x0, (%rsp)
je 0x266be
movq 0x8(%rbx), %r14
leaq 0xb2a4a(%rip), %rsi     # 0xd8e4e
movq %r14, %rdi
callq 0x19500
testl %eax, %eax
je 0x26456
leaq 0xb2a53(%rip), %rsi     # 0xd8e6a
movq %r14, %rdi
callq 0x19500
testl %eax, %eax
je 0x26566
leaq 0xfd052(%rip), %rdi     # 0x123480
leaq 0xb29ba(%rip), %rsi     # 0xd8def
callq 0x95250
movq %rax, %rdi
callq 0x94b30
pushq $-0x1
popq %rbx
jmp 0x26631
xorl %ebx, %ebx
callq 0x261e7
jmp 0x26397
movq 0x18(%rbx), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0xa7de0
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x26a70
leaq 0x38(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x2621e
leaq 0x38(%rsp), %rdi
callq 0x26aa2
leaq 0x8(%rsp), %rdi
callq 0x1d8ea
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x26ab2
leaq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
andq $0x0, (%rdi)
callq 0x26b6c
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x26b7c
movq 0x8(%rsp), %rbx
leaq 0x18(%rsp), %rdi
callq 0x26bc0
movl %eax, 0x1c(%rbx)
leaq 0x48(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x26c70
movq 0x48(%rsp), %rbx
movq 0x50(%rsp), %r14
cmpq %r14, %rbx
je 0x26516
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
movl (%rbx), %esi
callq 0x26e10
addq $0x4, %rbx
jmp 0x264fb
leaq 0x48(%rsp), %rdi
callq 0x1e82a
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %rsi
testq %rax, %rax
cmoveq %rax, %rsi
movq (%rdi), %rax
callq *0x28(%rax)
testl %eax, %eax
je 0x265e8
leaq 0xfcf36(%rip), %rdi     # 0x123480
leaq 0xb2902(%rip), %rsi     # 0xd8e53
callq 0x95250
movq %rax, %rdi
callq 0x94b30
pushq $-0x1
popq %rbx
jmp 0x26613
movq 0x18(%rbx), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0xa7de0
leaq 0x28(%rsp), %rdi
movq %rsp, %rsi
callq 0x26a70
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x2621e
leaq 0x28(%rsp), %rdi
callq 0x26aa2
movq 0x10(%rsp), %rbx
movq 0x60(%rsp), %rdi
movl 0x68(%rsp), %esi
callq 0x26ea7
movq (%rbx), %rcx
movq %rbx, %rdi
movl %eax, %esi
callq *0x30(%rcx)
testl %eax, %eax
je 0x2665f
leaq 0xfceb1(%rip), %rdi     # 0x123480
leaq 0xb287d(%rip), %rsi     # 0xd8e53
callq 0x95250
movq %rax, %rdi
callq 0x94b30
pushq $-0x1
popq %rbx
jmp 0x26627
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x26a70
leaq 0x30(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x262ad
leaq 0x30(%rsp), %rdi
callq 0x26aa2
xorl %ebx, %ebx
leaq 0x18(%rsp), %rdi
callq 0x26b6c
leaq 0x8(%rsp), %rdi
callq 0x1db18
leaq 0x60(%rsp), %rdi
callq 0xa5530
movq %rsp, %rdi
callq 0x1e030
leaq 0x10(%rsp), %rdi
callq 0x26ed4
leaq 0x40(%rsp), %rdi
callq 0x26ee4
leaq 0x80(%rsp), %rdi
callq 0xa5530
jmp 0x26397
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x26a70
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x262ad
leaq 0x20(%rsp), %rdi
callq 0x26aa2
xorl %ebx, %ebx
jmp 0x26627
pushq $0x10
popq %rdi
callq 0x28b50
movq %rax, %r15
leaq 0xb275d(%rip), %rsi     # 0xd8dfb
movq %rax, %rdi
callq 0x3c350
leaq 0xf59c3(%rip), %rsi     # 0x11c070
leaq 0xc31c(%rip), %rdx      # 0x329d0
movq %r15, %rdi
callq 0x29ba0
jmp 0x266ee
pushq $0x10
popq %rdi
callq 0x28b50
movq %rax, %r15
leaq 0xb2742(%rip), %rsi     # 0xd8e12
movq %rax, %rdi
callq 0x3c350
leaq 0xf5991(%rip), %rsi     # 0x11c070
leaq 0xc2ea(%rip), %rdx      # 0x329d0
movq %r15, %rdi
callq 0x29ba0
movq %rdx, %r14
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x2671b
movq %rdx, %r14
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x26aa2
jmp 0x267e0
movq %rdx, %r14
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x26aa2
jmp 0x267f4
jmp 0x267b8
jmp 0x267c0
movq %rdx, %r14
movq %rax, %rbx
jmp 0x267ea
jmp 0x26796
movq %rdx, %r14
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x26aa2
jmp 0x26754
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x267f4
movq %rbx, %rdi
callq 0x28cb0
callq 0x28d20
jmp 0x26492
jmp 0x26796
jmp 0x267b8
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x28bb0
jmp 0x267fe
jmp 0x2679e
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x28bb0
jmp 0x26806
movq %rdx, %r14
movq %rax, %rbx
jmp 0x267f4
movq %rdx, %r14
movq %rax, %rbx
jmp 0x26806
movq %rdx, %r14
movq %rax, %rbx
jmp 0x26810
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2681a
jmp 0x267c8
movq %rdx, %r14
movq %rax, %rbx
jmp 0x267fe
movq %rdx, %r14
movq %rax, %rbx
jmp 0x267e0
movq %rdx, %r14
movq %rax, %rbx
jmp 0x26827
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x1e82a
leaq 0x18(%rsp), %rdi
callq 0x26b6c
leaq 0x8(%rsp), %rdi
callq 0x1db18
leaq 0x60(%rsp), %rdi
callq 0xa5530
movq %rsp, %rdi
callq 0x1e030
leaq 0x10(%rsp), %rdi
callq 0x26ed4
leaq 0x40(%rsp), %rdi
callq 0x26ee4
leaq 0x80(%rsp), %rdi
callq 0xa5530
cmpl $0x1, %r14d
jne 0x26869
movq %rbx, %rdi
callq 0x28cb0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0xfcc3b(%rip), %rdi     # 0x123480
movq %rax, %rsi
callq 0x95250
movq %rax, %rdi
callq 0x94b30
callq 0x28d20
xorl %ebx, %ebx
jmp 0x26397
movq %rax, %rbx
callq 0x28d20
movq %rbx, %rdi
callq 0xd3bc0
movq %rax, %rdi
callq 0x1e0be
nop