1 // ConnectionListenerFactory.cpp 2 3 #include <new> 4 5 #include <string.h> 6 7 #include "ConnectionListenerFactory.h" 8 #include "InsecureConnectionListener.h" 9 #include "PortConnectionListener.h" 10 11 // constructor ConnectionListenerFactory()12ConnectionListenerFactory::ConnectionListenerFactory() 13 { 14 } 15 16 // destructor ~ConnectionListenerFactory()17ConnectionListenerFactory::~ConnectionListenerFactory() 18 { 19 } 20 21 // CreateConnectionListener 22 status_t CreateConnectionListener(const char * type,const char * parameters,ConnectionListener ** connectionListener)23ConnectionListenerFactory::CreateConnectionListener(const char* type, 24 const char* parameters, ConnectionListener** connectionListener) 25 { 26 if (!type) 27 return B_BAD_VALUE; 28 // create the connection listener 29 ConnectionListener* listener = NULL; 30 if (strcmp(type, "insecure") == 0) 31 listener = new(std::nothrow) InsecureConnectionListener; 32 else if (strcmp(type, "port") == 0) 33 listener = new(std::nothrow) PortConnectionListener; 34 else 35 return B_BAD_VALUE; 36 if (!listener) 37 return B_NO_MEMORY; 38 // init it 39 status_t error = listener->Init(parameters); 40 if (error != B_OK) { 41 delete listener; 42 return error; 43 } 44 *connectionListener = listener; 45 return B_OK; 46 } 47 48