| 790 | } |
| 791 | |
| 792 | Kernel* Kernel::CreateRemoteConnection(bool sharedFileSystem, char const* pIPaddress, int port, bool ignoreOutput) |
| 793 | { |
| 794 | ErrorCode errorCode = 0 ; |
| 795 | |
| 796 | /* -- Create Soar_Instance and Output_Manager singletons -- */ |
| 797 | Soar_Instance* lSoarInstance = instantiate_singletons(); |
| 798 | |
| 799 | // Initialize the socket library before attempting to create a connection |
| 800 | sock::SocketLib* pLib = new sock::SocketLib() ; |
| 801 | |
| 802 | // Connect to the remote socket |
| 803 | Connection* pConnection = Connection::CreateRemoteConnection(sharedFileSystem, pIPaddress, port, &errorCode) ; |
| 804 | |
| 805 | // Even if pConnection is NULL, we still build a kernel object, so we have |
| 806 | // a clean way to pass the error code back to the caller. |
| 807 | Kernel* pKernel = new Kernel(pConnection) ; |
| 808 | lSoarInstance->init_Soar_Instance(pKernel); |
| 809 | |
| 810 | pKernel->SetSocketLib(pLib) ; |
| 811 | pKernel->SetError(errorCode) ; |
| 812 | |
| 813 | // If this client isn't interested in getting output we can speed things up a bit for them. |
| 814 | pKernel->m_bIgnoreOutput = ignoreOutput ; |
| 815 | |
| 816 | // If we had an error creating the connection, abort before |
| 817 | // we try to get the current agent list |
| 818 | if (pKernel->HadError()) |
| 819 | { |
| 820 | return pKernel ; |
| 821 | } |
| 822 | |
| 823 | // Register for "calls" from the kernel. |
| 824 | pConnection->RegisterCallback(ReceivedCall, pKernel, sml_Names::kDocType_Call, true) ; |
| 825 | |
| 826 | // Register for important events |
| 827 | pKernel->InitEvents() ; |
| 828 | |
| 829 | // Initialize our time tags |
| 830 | pKernel->InitializeTimeTagCounter() ; |
| 831 | |
| 832 | // Get the current list of active agents |
| 833 | pKernel->UpdateAgentList() ; |
| 834 | |
| 835 | return pKernel ; |
| 836 | } |
| 837 | |
| 838 | /************************************************************* |
| 839 | * @brief Returns the number of agents (from our list of known agents). |