~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to prnt/hpcups/dbuscomm.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-10-06 15:03:44 UTC
  • mfrom: (1.6.1) (20.1.16 quantal)
  • Revision ID: package-import@ubuntu.com-20121006150344-2p3xz26br0t3hu2q
Tags: 3.12.10-1
* New upstream release
  - Fixes "Network scanning fails (Closes: #683033)
* quilt refresh hplip-syslog-fix-debug-messages-to-error.dpatch
* Fix "error in clean build env" updated debian/rules (Closes: #687129)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************\
 
2
  dbuscomm.cpp : Interface for DBusCommunicator class
 
3
 
 
4
  Copyright (c) 1996 - 2011, Hewlett-Packard Co.
 
5
  All rights reserved.
 
6
 
 
7
  Redistribution and use in source and binary forms, with or without
 
8
  modification, are permitted provided that the following conditions
 
9
  are met:
 
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.
 
18
 
 
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
\*****************************************************************************/
 
31
 
 
32
#include "dbuscomm.h"
 
33
 
 
34
DBusCommunicator::DBusCommunicator()
 
35
{
 
36
        m_strPrinterURI = "";
 
37
        m_strPrinterName = "";
 
38
#ifdef HAVE_DBUS
 
39
        m_DbusConnPtr = NULL; 
 
40
#endif
 
41
}
 
42
/*
 
43
*
 
44
*
 
45
*/
 
46
 
 
47
 
 
48
bool DBusCommunicator::initDBusComm(string strDbusPath/*=""*/,string strInterfaceName/*=""*/,  
 
49
                                string strPrinterURI/*=""*/, string strPrinterName/*= ""*/, int iJobId/*=0*/, string strUser/*=""*/)
 
50
{
 
51
#ifdef HAVE_DBUS
 
52
        DBusError objError;
 
53
        DBusError * pDBusError=&objError;
 
54
                
 
55
        m_strPrinterURI = strPrinterURI;
 
56
        m_strPrinterName = strPrinterName;
 
57
        m_strDbusInterface = strInterfaceName;
 
58
        m_strDbusPath = strDbusPath;
 
59
        m_strUser = strUser;
 
60
        m_iJobId = iJobId;
 
61
                
 
62
        dbus_error_init(pDBusError);
 
63
        m_DbusConnPtr = dbus_bus_get(DBUS_BUS_SYSTEM, pDBusError);
 
64
        if(dbus_error_is_set(pDBusError))
 
65
        {
 
66
                dbglog("Error: dBus Connection Error (%s)!\n", pDBusError->message);
 
67
                dbus_error_free(pDBusError);
 
68
        }
 
69
        
 
70
        if(m_DbusConnPtr == NULL)
 
71
        {
 
72
                dbglog("Error: dBus Connection Error (%s)!\n", pDBusError->message);
 
73
                return false;
 
74
        }
 
75
#endif  
 
76
        return true;
 
77
}
 
78
 
 
79
bool DBusCommunicator::sendEvent(string strDbusPath,string strInterfaceName, string strDeviceURI, string strPrinterName, int iEvent, 
 
80
                        string strTitle/*=""*/, int iJobId/*=0*/, string strUser/*=""*/)
 
81
{
 
82
#ifdef HAVE_DBUS
 
83
 
 
84
        if(NULL == m_DbusConnPtr )
 
85
        {
 
86
                dbglog("Error: dBus connection ptr is NULL.\n");
 
87
                return false;
 
88
        }
 
89
        if(true == strDbusPath.empty() || true == strInterfaceName.empty() || 0 == iEvent)
 
90
        {
 
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);
 
93
                return false;
 
94
        }
 
95
        DBusMessage * msg = dbus_message_new_signal(strDbusPath.c_str(), strInterfaceName.c_str(), "Event");
 
96
        if (NULL == msg)
 
97
        {
 
98
                dbglog("Error: dBus dbus_message_new_signal returned error. DBus Interface (%s) Event(%d)!\n", strInterfaceName.c_str(), iEvent);
 
99
                return false;
 
100
        }
 
101
        
 
102
        if (NULL == msg)
 
103
        {
 
104
                dbglog("dbus message is NULL!\n");
 
105
                return false;
 
106
        }
 
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();
 
111
 
 
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, 
 
119
                DBUS_TYPE_INVALID);
 
120
 
 
121
        if (!dbus_connection_send(m_DbusConnPtr , msg, NULL))
 
122
        {
 
123
                dbglog("dbus message send failed!\n");
 
124
                return false;
 
125
        }
 
126
 
 
127
        dbus_connection_flush(m_DbusConnPtr );
 
128
        dbus_message_unref(msg);
 
129
 
 
130
#endif
 
131
        return true;
 
132
 
 
133
}
 
134
 
 
135
bool DBusCommunicator::sendEvent(int iEvent, string strTitle/*=""*/, int iJobId/*=0*/,string strUser/*=""*/)
 
136
{
 
137
        return sendEvent(m_strDbusPath, m_strDbusInterface, m_strPrinterURI, m_strPrinterName, iEvent, strTitle, iJobId,strUser);
 
138
}
 
139
 
 
140
DBusCommunicator::~DBusCommunicator()
 
141
{
 
142
 
 
143
}