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