/***************************************************************************
* Copyright (C) 2007,2008,2009 by Rick L. Vinyard, Jr. *
* rvinyard@cs.nmsu.edu *
* *
* This file is part of the dbus-cxx library. *
* *
* The dbus-cxx library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* version 3 as published by the Free Software Foundation. *
* *
* The dbus-cxx library 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 software. If not see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "connection.h"
#include "utility.h"
#include <iostream>
#include <sys/time.h>
#include <cassert>
#include <dbus-cxx/signalmessage.h>
namespace DBus
{
dbus_int32_t Connection::m_weak_pointer_slot = -1;
Connection::Connection( DBusConnection* cobj, bool is_private ):
m_cobj( cobj )
{
if ( m_cobj ) {
dbus_connection_ref( m_cobj );
this->initialize(is_private);
}
}
Connection::Connection( BusType type, bool is_private ): m_cobj( NULL )
{
Error::pointer error = Error::create();
if ( type != BUS_NONE ) {
if ( is_private ) {
m_cobj = dbus_bus_get_private(( DBusBusType )type, error->cobj() );
if ( error->is_set() ) throw error;
if ( m_cobj == NULL ) throw ErrorFailed::create();
this->initialize(is_private);
}
else {
m_cobj = dbus_bus_get(( DBusBusType )type, error->cobj() );
if ( error->is_set() ) throw error;
if ( m_cobj == NULL ) throw ErrorFailed::create();
this->initialize(is_private);
}
}
}
Connection::Connection( const Connection& other )
{
m_cobj = other.m_cobj;
if ( m_cobj ) dbus_connection_ref( m_cobj );
}
void conn_wp_deleter( void* v )
{
Connection::weak_pointer* wp = static_cast<Connection::weak_pointer*>(v);
delete wp;
}
Connection::pointer Connection::create( DBusConnection* cobj, bool is_private )
{
pointer p = pointer( new Connection(cobj, is_private) );
if ( m_weak_pointer_slot == -1 ) throw ErrorNotInitialized::create();
if ( p and p->is_valid() )
{
dbus_bool_t result;
weak_pointer* wp = new weak_pointer;
*wp = p;
result = dbus_connection_set_data( p->cobj(), m_weak_pointer_slot, wp, conn_wp_deleter );
if ( not result ) throw -1; // TODO throw something better
}
return p;
}
Connection::pointer Connection::create( BusType type, bool is_private )
{
pointer p = pointer( new Connection(type, is_private) );
if ( m_weak_pointer_slot == -1 ) throw ErrorNotInitialized::create();
if ( p and p->is_valid() )
{
dbus_bool_t result;
weak_pointer* wp = new weak_pointer;
*wp = p;
result = dbus_connection_set_data( p->cobj(), m_weak_pointer_slot, wp, conn_wp_deleter );
if ( not result ) throw -1; // TODO throw something better
}
return p;
}
Connection::pointer Connection::create( const Connection& other )
{
pointer p = pointer( new Connection(other) );
if ( m_weak_pointer_slot == -1 ) throw ErrorNotInitialized::create();
if ( p and p->is_valid() )
{
dbus_bool_t result;
weak_pointer* wp = new weak_pointer;
*wp = p;
result = dbus_connection_set_data( p->cobj(), m_weak_pointer_slot, wp, conn_wp_deleter );
if ( not result ) throw -1; // TODO throw something better
}
return p;
}
Connection::~Connection()
{
if ( this->is_valid() and this->is_private() )
dbus_connection_close( m_cobj );
if ( m_cobj ) dbus_connection_unref( m_cobj );
}
Connection::pointer Connection::self()
{
if ( not this->is_valid() or m_weak_pointer_slot == -1 ) return pointer();
void* v = dbus_connection_get_data(this->cobj(), m_weak_pointer_slot);
if ( v == NULL ) return pointer();
weak_pointer* wp = static_cast<weak_pointer*>(v);
pointer p = wp->lock();
return p;
}
Connection::pointer Connection::self(DBusConnection * c)
{
if ( c == NULL or m_weak_pointer_slot == -1 ) return Connection::pointer();
void* v = dbus_connection_get_data(c, m_weak_pointer_slot);
if ( v == NULL ) return Connection::pointer();
Connection::weak_pointer* wp = static_cast<Connection::weak_pointer*>(v);
Connection::pointer p = wp->lock();
return p;
}
DBusConnection* Connection::cobj()
{
return m_cobj;
}
Connection::operator bool() const
{
return m_cobj;
}
bool Connection::is_valid() const
{
return m_cobj;
}
bool Connection::is_private() const
{
return m_private_flag;
}
bool Connection::bus_register()
{
dbus_bool_t result;
Error::pointer error = Error::create();
if ( not this->is_valid() ) return false;
result = dbus_bus_register( m_cobj, error->cobj() );
if ( error->is_set() ) throw error;
return result;
}
bool Connection::is_registered() const
{
return this->unique_name() != NULL;
}
const char * Connection::unique_name() const
{
if ( not this->is_valid() ) return NULL;
return dbus_bus_get_unique_name(m_cobj);
}
unsigned long Connection::unix_user( const std::string & name ) const
{
Error::pointer error = Error::create();
if ( not this->is_valid() ) return -1;
return dbus_bus_get_unix_user( m_cobj, name.c_str(), error->cobj() );
}
const char* Connection::bus_id() const
{
Error::pointer error = Error::create();
if ( not this->is_valid() ) return NULL;
return dbus_bus_get_id( m_cobj, error->cobj() );
}
int Connection::request_name( const std::string& name, unsigned int flags )
{
int result;
Error::pointer error = Error::create();
if ( not this->is_valid() ) return -1;
result = dbus_bus_request_name( m_cobj, name.c_str(), flags, error->cobj() );
if ( error->is_set() ) throw error;
return result;
}
int Connection::release_name( const std::string& name )
{
int result;
Error::pointer error = Error::create();
if ( not this->is_valid() ) return -1;
result = dbus_bus_release_name( m_cobj, name.c_str(), error->cobj() );
if ( error->is_set() ) throw error;
return result;
}
bool Connection::name_has_owner( const std::string& name ) const
{
dbus_bool_t result;
Error::pointer error = Error::create();
if ( not this->is_valid() ) return false;
result = dbus_bus_name_has_owner( m_cobj, name.c_str(), error->cobj() );
if ( error->is_set() ) throw error;
return result;
}
StartReply Connection::start_service( const std::string& name, uint32_t flags ) const
{
dbus_bool_t succeeded;
dbus_uint32_t result_code;
Error::pointer error = Error::create();
if ( not this->is_valid() ) return START_REPLY_FAILED;
succeeded = dbus_bus_start_service_by_name( m_cobj, name.c_str(), flags, &result_code, error->cobj() );
if ( error->is_set() ) throw error;
if ( succeeded )
switch ( result_code ) {
case DBUS_START_REPLY_SUCCESS: return START_REPLY_SUCCESS;
case DBUS_START_REPLY_ALREADY_RUNNING: return START_REPLY_ALREADY_RUNNING;
没有合适的资源?快使用搜索试试~ 我知道了~
dbus-cxx-0.7.0.zip_DBUS_DBUS 封装_dbus c++
共294个文件
cpp:91个
h:77个
m4:27个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 55 浏览量
2022-09-19
18:02:50
上传
评论
收藏 1014KB ZIP 举报
温馨提示
dbus-cxx-0.7.0.zip 学习dbus编程非常有参考价值. 包括low leve api的dbus编程和c++封装的dbus编程
资源推荐
资源详情
资源评论
收起资源包目录
dbus-cxx-0.7.0.zip_DBUS_DBUS 封装_dbus c++ (294个子文件)
configure.ac 10KB
Makefile.am 6KB
Makefile.am 4KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 422B
AUTHORS 44B
ChangeLog 32KB
changelog 2KB
compat 2B
configure 643KB
control 3KB
COPYING 34KB
copyright 1KB
connection.cpp 32KB
parsed_object.cpp 23KB
messageiterator.cpp 21KB
dispatcher.cpp 21KB
messageiteratortests.cpp 16KB
objectproxy.cpp 15KB
xml_parser.cpp 14KB
object.cpp 13KB
interfaceproxy.cpp 13KB
interface.cpp 13KB
generate_adapter.cpp 8KB
messageappenditerator.cpp 7KB
generate_proxy.cpp 7KB
message.cpp 7KB
dispatcher.cpp 6KB
signal_proxy_base.cpp 6KB
callmessage.cpp 6KB
callmessagetests.cpp 6KB
xml2cpp.cpp 5KB
pathclasstests.cpp 5KB
signalreceiver.cpp 5KB
caller_c.cpp 5KB
signalmessage.cpp 5KB
objectpathhandler.cpp 5KB
computer_client.cpp 5KB
signatureiterator.cpp 5KB
callee_c.cpp 5KB
signal_emitter_object.cpp 4KB
computer_client.cpp 4KB
timeout.cpp 4KB
calculator_client.cpp 4KB
calculator_client.cpp 4KB
calculator_watcher.cpp 4KB
caller_raw.cpp 4KB
path.cpp 4KB
signal_receiver_object.cpp 4KB
caller_object.cpp 4KB
caller.cpp 4KB
calculator.cpp 4KB
signal_base.cpp 4KB
calculator.cpp 4KB
watch.cpp 4KB
callee_raw.cpp 4KB
methodproxybase.cpp 3KB
computer.cpp 3KB
errormessage.cpp 3KB
signal_receiver_c.cpp 3KB
glibmm_callee_dispatched.cpp 3KB
pendingcall.cpp 3KB
callee_dispatched.cpp 3KB
callee_object_inherited.cpp 3KB
signal_emitter_c.cpp 3KB
returnmessage.cpp 3KB
callee_2.cpp 3KB
error.cpp 3KB
signature.cpp 3KB
introspect.cpp 3KB
callee_object.cpp 3KB
computer.cpp 3KB
computer_watcher.cpp 3KB
dbus_cxx_unit_tests.cpp 3KB
callee.cpp 3KB
hal_proxy.cpp 3KB
signal_receiver_raw.cpp 3KB
calculator_watcher.cpp 3KB
computer_watcher.cpp 3KB
signal_receiver.cpp 3KB
signal_receiver_2.cpp 2KB
caller_dispatched.cpp 2KB
signal_emitter_array.cpp 2KB
signal_receiver_array.cpp 2KB
calculator.cpp 2KB
共 294 条
- 1
- 2
- 3
资源评论
局外狗
- 粉丝: 64
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功