
9 changed files with 151 additions and 71 deletions
@ -0,0 +1,50 @@ |
|||||
|
#include "Identity.hh" |
||||
|
#include <typeinfo> |
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace PythonAdapter { |
||||
|
using namespace std; |
||||
|
|
||||
|
Identity::Identity() |
||||
|
: _ident(new_identity(NULL, NULL, NULL, NULL)) |
||||
|
{ |
||||
|
if (!_ident) |
||||
|
throw bad_alloc(); |
||||
|
} |
||||
|
|
||||
|
Identity::Identity(Identity& second) |
||||
|
: _ident(identity_dup(second._ident)) |
||||
|
{ |
||||
|
if (!_ident) |
||||
|
throw bad_alloc(); |
||||
|
} |
||||
|
|
||||
|
Identity::~Identity() |
||||
|
{ |
||||
|
free_identity(_ident); |
||||
|
} |
||||
|
|
||||
|
Identity::operator pEp_identity *() |
||||
|
{ |
||||
|
if (!_ident) |
||||
|
throw bad_cast(); |
||||
|
return _ident; |
||||
|
} |
||||
|
|
||||
|
void Identity::lang(string value) |
||||
|
{ |
||||
|
if (value == "") |
||||
|
memset(_ident->lang, 0, 3); |
||||
|
else if (value.length() != 2) |
||||
|
throw length_error("length of lang must be 2"); |
||||
|
else |
||||
|
memcpy(_ident->lang, value.data(), 2); |
||||
|
} |
||||
|
|
||||
|
string Identity::lang() |
||||
|
{ |
||||
|
return _ident->lang; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,46 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <pEp/pEpEngine.h> |
||||
|
#include <string> |
||||
|
#include "str_attr.hh" |
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace PythonAdapter { |
||||
|
using namespace utility; |
||||
|
|
||||
|
class Identity { |
||||
|
pEp_identity *_ident; |
||||
|
|
||||
|
public: |
||||
|
Identity(); |
||||
|
Identity(Identity& second); |
||||
|
~Identity(); |
||||
|
operator pEp_identity *(); |
||||
|
|
||||
|
void address(string value) { str_attr(_ident->address, value); } |
||||
|
string address() { return str_attr(_ident->address); } |
||||
|
|
||||
|
void fpr(string value) { str_attr(_ident->fpr, value); } |
||||
|
string fpr() { return str_attr(_ident->fpr); } |
||||
|
|
||||
|
void user_id(string value) { str_attr(_ident->user_id, value); } |
||||
|
string user_id() { return str_attr(_ident->user_id); } |
||||
|
|
||||
|
void username(string value) { str_attr(_ident->username, value); } |
||||
|
string username() { return str_attr(_ident->username); } |
||||
|
|
||||
|
void comm_type(PEP_comm_type value) { _ident->comm_type = value; }; |
||||
|
PEP_comm_type comm_type() { return _ident->comm_type; } |
||||
|
|
||||
|
void lang(std::string value); |
||||
|
std::string lang(); |
||||
|
|
||||
|
void me(bool value) { _ident->me = value; } |
||||
|
bool me() { return _ident->me; } |
||||
|
|
||||
|
void me(identity_flags_t flags) { _ident->flags = flags; } |
||||
|
identity_flags_t flags() { return _ident->flags; } |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
@ -1,11 +0,0 @@ |
|||||
#include "converting.hh" |
|
||||
#include <new> |
|
||||
#include <stdexcept> |
|
||||
|
|
||||
namespace pEp { |
|
||||
namespace utility { |
|
||||
using namespace std; |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
@ -1,12 +0,0 @@ |
|||||
#pragma once |
|
||||
|
|
||||
#include <Python.h> |
|
||||
#include <pEp/pEpEngine.h> |
|
||||
#include <pEp/message_api.h> |
|
||||
|
|
||||
namespace pEp { |
|
||||
namespace utility { |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
@ -1,34 +1,24 @@ |
|||||
#include "pEpmodule.hh" |
#include "pEpmodule.hh" |
||||
#include <string> |
#include <string> |
||||
|
#include <pEp/pEpEngine.h> |
||||
|
|
||||
namespace pEp { |
namespace pEp { |
||||
namespace PythonAdapter { |
namespace PythonAdapter { |
||||
using namespace std; |
using namespace std; |
||||
|
|
||||
PyObject *about(PyObject *self, PyObject *args) |
string about(void) |
||||
{ |
{ |
||||
string version = string(version_string) + "\np≡p version " |
string version = string(version_string) + "\np≡p version " |
||||
+ PEP_VERSION + "\n"; |
+ PEP_VERSION + "\n"; |
||||
return PyUnicode_FromString(version.c_str()); |
return version; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
PEP_SESSION session; |
|
||||
|
|
||||
void module_free(void *) |
|
||||
{ |
|
||||
release(session); |
|
||||
} |
} |
||||
} |
|
||||
|
|
||||
using namespace pEp; |
|
||||
|
|
||||
PyMODINIT_FUNC PyInit_pEp(void) |
BOOST_PYTHON_MODULE(pEp) |
||||
{ |
{ |
||||
PEP_STATUS status = init(&session); |
using namespace boost::python; |
||||
if (status != PEP_STATUS_OK) |
using namespace pEp::PythonAdapter; |
||||
return NULL; |
def("about", about); |
||||
|
|
||||
return PyModule_Create(&pEpmodule); |
|
||||
} |
} |
||||
|
|
||||
|
@ -0,0 +1,24 @@ |
|||||
|
#include "str_attr.hh" |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace utility { |
||||
|
using namespace std; |
||||
|
|
||||
|
void str_attr(char *&str, string value) |
||||
|
{ |
||||
|
free(str); |
||||
|
str = strdup(value.c_str()); |
||||
|
if (!str) |
||||
|
throw bad_alloc(); |
||||
|
} |
||||
|
|
||||
|
string str_attr(char *&str) |
||||
|
{ |
||||
|
if (!str) |
||||
|
return string(""); |
||||
|
return string(str); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,13 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <string> |
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace utility { |
||||
|
using namespace std; |
||||
|
|
||||
|
void str_attr(char *&str, string value); |
||||
|
string str_attr(char *&str); |
||||
|
} |
||||
|
} |
||||
|
|
Loading…
Reference in new issue