Skip to content

Commit

Permalink
add server error category class
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Apr 11, 2014
1 parent 848fba4 commit 95945b9
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cpp/server/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ file(GLOB_RECURSE SERVER_HEADER_FILES "*.h*")
set(SERVER_SOURCE_FILES
ServerAppArmor.cpp
ServerBrowser.cpp
ServerErrorCategory.cpp
ServerEval.cpp
ServerInit.cpp
ServerMain.cpp
Expand Down
64 changes: 64 additions & 0 deletions src/cpp/server/ServerErrorCategory.cpp
@@ -0,0 +1,64 @@
/*
* ServerErrorCategory.cpp
*
* Copyright (C) 2009-12 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/

#include <server/ServerErrorCategory.hpp>

namespace server {

class ServerErrorCategory : public boost::system::error_category
{
public:
virtual const char * name() const;
virtual std::string message( int ev ) const;
};

const boost::system::error_category& serverCategory()
{
static ServerErrorCategory serverErrorCategoryConst ;
return serverErrorCategoryConst ;
}

const char * ServerErrorCategory::name() const
{
return "server" ;
}

std::string ServerErrorCategory::message( int ev ) const
{
std::string message ;
switch (ev)
{
case errc::AuthenticationError:
message = "Authentication error";
break;

default:
message = "Unknown error" ;
break;
}

return message ;
}


bool isAuthenticationError(const core::Error& error)
{
if (error.code() == server::errc::AuthenticationError)
return true;
else
return false;
}

} // namespace server
69 changes: 69 additions & 0 deletions src/cpp/server/include/server/ServerErrorCategory.hpp
@@ -0,0 +1,69 @@
/*
* ServerErrorCategory.hpp
*
* Copyright (C) 2009-12 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/

#ifndef SERVER_SERVER_ERROR_CATEGORY_HPP
#define SERVER_SERVER_ERROR_CATEGORY_HPP

#include <boost/system/error_code.hpp>

namespace server {
namespace errc {

enum errc_t {
Success = 0,
AuthenticationError
};

} // namespace errc
} // namespace r


namespace boost {
namespace system {
template <>
struct is_error_code_enum<server::errc::errc_t>
{ static const bool value = true; };
} // namespace system
} // namespace boost


#include <core/Error.hpp>

namespace server {

const boost::system::error_category& serverCategory() ;

namespace errc {

inline boost::system::error_code make_error_code( errc_t e )
{
return boost::system::error_code( e, serverCategory() ); }

inline boost::system::error_condition make_error_condition( errc_t e )
{
return boost::system::error_condition( e, serverCategory() );
}

} // namespace errc


bool isAuthenticationError(const core::Error& error);


} // namespace server


#endif // SERVER_SERVER_ERROR_CATEGORY_HPP

0 comments on commit 95945b9

Please sign in to comment.