Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|