|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include "URLCellsWriter.hpp" 00023 00024 #include "FileCellsWriter.hpp" 00025 #include "DummyCellsWriter.hpp" 00026 #include "SocketCellsWriter.hpp" 00027 00028 #include <stdio.h> 00029 #include <stdlib.h> 00030 00031 URLCellsWriter::URLCellsWriter(string url) { 00032 int pos1 = url.find_first_of("://"); 00033 if (pos1 == -1) { 00034 fprintf(stderr, "URLCellsWriter: Wrong URL format: %s\n", url.c_str()); 00035 exit(1); 00036 } 00037 string type = url.substr(0, pos1); 00038 string param = url.substr(pos1+3); 00039 00040 00041 fprintf(stderr, "%s: %s - %s\n", url.c_str(), type.c_str(), param.c_str()); 00042 if (type == "socket") { 00043 int port; 00044 string hostname; 00045 int pos2 = param.find_first_of(":"); 00046 if (pos2 > 0) { 00047 port = atoi(param.substr(pos2+1).c_str()); 00048 hostname = param.substr(0, pos2); 00049 } else { 00050 hostname = param; 00051 } 00052 writer = new SocketCellsWriter(hostname, port); 00053 } else if (type == "file") { 00054 writer = new FileCellsWriter(param); 00055 } else if (type == "null") { 00056 writer = new DummyCellsWriter(); 00057 } else { 00058 fprintf(stderr, "URLCellsWriter: Unknown writer type: %s\n", type.c_str()); 00059 exit(1); 00060 } 00061 } 00062 00063 URLCellsWriter::~URLCellsWriter() { 00064 // TODO Auto-generated destructor stub 00065 } 00066 00067 void URLCellsWriter::close() { 00068 if (writer != NULL) { 00069 writer->close(); 00070 writer = NULL; 00071 } 00072 } 00073 00074 int URLCellsWriter::write(const cell_t* buf, int len) { 00075 return writer->write(buf, len); 00076 }
1.7.6.1