|
From: <mik...@us...> - 2003-12-26 10:04:54
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/exceptions
In directory sc8-pr-cvs1:/tmp/cvs-serv24435/src/exceptions
Modified Files:
Exception.h ThreadException.cpp
Added Files:
SocketException.h SocketException.cpp
Log Message:
26/12/2003 Mikael Barbeaux
* Implemented Socket, ServerSocket and SocketException classes.
* Added simple test program for Sockets.
--- NEW FILE: SocketException.h ---
/*
* This file is part of webInterface.
* Copyright (C) 2003 Mikael Barbeaux <mik...@us...>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _SOCKET_EXCEPTION_H_
#define _SOCKET_EXCEPTION_H_
#include "Exception.h"
enum SocketError {
InvalidSockExcp,
ClosedSockExcp,
SendSockExcp,
RecvSockExcp,
AlreadyValidSockExcp,
CantCreateSockExcp,
AlreadyBoundSockExcp,
CantBindSockExcp,
UnboundSockExcp,
CantListenSockExcp,
NotListeningSockExcp
};
/**
* Defines a Exception for handling socket errors.
*/
class SocketException : public Exception {
public:
/**
* Creates a Socket exception handler.
*
* @param eCode - code of this exception
* @param message - Message to send to this exception
* @param origin - Method who throws the exception
*/
SocketException(SocketError eCode, const string& message,
const string& origin);
/**
* Returns the message sent by this Socket exception.
*
* @return const string
*/
virtual const string getMessage() const;
};
#endif
--- NEW FILE: SocketException.cpp ---
/*
* This file is part of webInterface.
* Copyright (C) 2003 Mikael Barbeaux <mik...@us...>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "SocketException.h"
#include <sstream>
using namespace std;
/**
* Creates a SocketException object with the given error code and
* message.
*/
SocketException::SocketException(SocketError eCode, const string& message,
const string& origin) : Exception(eCode, message, origin) {
}
/**
* Returns the message sent by this exception, depending the
* error code sent.
*/
const string SocketException::getMessage() const {
ostringstream message;
// Build error message depending error code
message << "-----------------------" << endl;
message << "WARNING : SocketException thrown !!" << endl;
message << "| Type : ";
switch(code) {
case InvalidSockExcp:
message << "InvalidSocket error";
break;
case ClosedSockExcp:
message << "ClosedSocket error";
break;
case SendSockExcp:
message << "SendSocket error";
break;
case RecvSockExcp:
message << "ReceiveSocket error";
break;
case AlreadyValidSockExcp:
message << "AlreadyValidSocket error";
break;
case CantCreateSockExcp:
message << "CantCreateSocket error";
break;
case AlreadyBoundSockExcp:
message << "AlreadyBoundSocket error";
break;
case CantBindSockExcp:
message << "CantBindSocket error";
break;
case UnboundSockExcp:
message << "UnboundSocket error";
break;
case CantListenSockExcp:
message << "CantListenSocket error";
break;
case NotListeningSockExcp:
message << "NotListeningSocket error";
break;
default:
message << "UnknownError";
break;
}
message << endl << "| From : " << origin << endl;
message << "| Message : " << what() << endl;
message << "-----------------------" << endl;
return message.str();
}
Index: Exception.h
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/exceptions/Exception.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Exception.h 24 Dec 2003 11:52:49 -0000 1.2
+++ Exception.h 26 Dec 2003 10:04:50 -0000 1.3
@@ -27,7 +27,10 @@
/**
* Defines a generic Exception object for handling
* exceptions into the program.
- *
+ * Exceptions are defined with a error code, that describes it,
+ * a string message for explaining the error meaning, and finally
+ * a string containing the name of the method which launches it,
+ * in order to provide a more powerful debugging.
*/
class Exception : public runtime_error {
Index: ThreadException.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/exceptions/ThreadException.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ThreadException.cpp 24 Dec 2003 13:03:54 -0000 1.3
+++ ThreadException.cpp 26 Dec 2003 10:04:50 -0000 1.4
@@ -37,7 +37,7 @@
ostringstream message;
// Build error message depending error code
message << "-----------------------" << endl;
- message << "WARNING : Exception thrown !!" << endl;
+ message << "WARNING : ThreadException thrown !!" << endl;
message << "| Type : ";
switch(code) {
case MutexExcp:
|