1
/*****************************************************************************\
2
dbuscomm.cpp : Interface for DBusCommunicator class
4
Copyright (c) 1996 - 2011, Hewlett-Packard Co.
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
10
1. Redistributions of source code must retain the above copyright
11
notice, this list of conditions and the following disclaimer.
12
2. Redistributions in binary form must reproduce the above copyright
13
notice, this list of conditions and the following disclaimer in the
14
documentation and/or other materials provided with the distribution.
15
3. Neither the name of Hewlett-Packard nor the names of its
16
contributors may be used to endorse or promote products derived
17
from this software without specific prior written permission.
19
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24
TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
Author: Amarnath Chitumalla
30
\*****************************************************************************/
34
DBusCommunicator::DBusCommunicator()
37
m_strPrinterName = "";
48
bool DBusCommunicator::initDBusComm(string strDbusPath/*=""*/,string strInterfaceName/*=""*/,
49
string strPrinterURI/*=""*/, string strPrinterName/*= ""*/, int iJobId/*=0*/, string strUser/*=""*/)
53
DBusError * pDBusError=&objError;
55
m_strPrinterURI = strPrinterURI;
56
m_strPrinterName = strPrinterName;
57
m_strDbusInterface = strInterfaceName;
58
m_strDbusPath = strDbusPath;
62
dbus_error_init(pDBusError);
63
m_DbusConnPtr = dbus_bus_get(DBUS_BUS_SYSTEM, pDBusError);
64
if(dbus_error_is_set(pDBusError))
66
dbglog("Error: dBus Connection Error (%s)!\n", pDBusError->message);
67
dbus_error_free(pDBusError);
70
if(m_DbusConnPtr == NULL)
72
dbglog("Error: dBus Connection Error (%s)!\n", pDBusError->message);
79
bool DBusCommunicator::sendEvent(string strDbusPath,string strInterfaceName, string strDeviceURI, string strPrinterName, int iEvent,
80
string strTitle/*=""*/, int iJobId/*=0*/, string strUser/*=""*/)
84
if(NULL == m_DbusConnPtr )
86
dbglog("Error: dBus connection ptr is NULL.\n");
89
if(true == strDbusPath.empty() || true == strInterfaceName.empty() || 0 == iEvent)
91
dbglog("Error: dBus service Name can't be empty. DBus Path(%s) DBus Interface (%s) Event(%d)!\n",
92
strDbusPath.c_str(), strInterfaceName.c_str(), iEvent);
95
DBusMessage * msg = dbus_message_new_signal(strDbusPath.c_str(), strInterfaceName.c_str(), "Event");
98
dbglog("Error: dBus dbus_message_new_signal returned error. DBus Interface (%s) Event(%d)!\n", strInterfaceName.c_str(), iEvent);
104
dbglog("dbus message is NULL!\n");
107
const char * stURI=strDeviceURI.c_str();
108
const char * stPRNTNM=strPrinterName.c_str();
109
const char * stUSR=strUser.c_str();
110
const char * stTtl=strTitle.c_str();
112
dbus_message_append_args(msg,
113
DBUS_TYPE_STRING, &stURI,
114
DBUS_TYPE_STRING, &stPRNTNM,
115
DBUS_TYPE_UINT32, &iEvent,
116
DBUS_TYPE_STRING, &stUSR,
117
DBUS_TYPE_UINT32, &iJobId,
118
DBUS_TYPE_STRING, &stTtl,
121
if (!dbus_connection_send(m_DbusConnPtr , msg, NULL))
123
dbglog("dbus message send failed!\n");
127
dbus_connection_flush(m_DbusConnPtr );
128
dbus_message_unref(msg);
135
bool DBusCommunicator::sendEvent(int iEvent, string strTitle/*=""*/, int iJobId/*=0*/,string strUser/*=""*/)
137
return sendEvent(m_strDbusPath, m_strDbusInterface, m_strPrinterURI, m_strPrinterName, iEvent, strTitle, iJobId,strUser);
140
DBusCommunicator::~DBusCommunicator()