조회 수 3961 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

우분투 리눅스 환경에서 특정 서비스를 제공하는 데몬과 D-Bus 통신하여 데몬 서비스를 이용해보고자 한다.

서비스를 제공하는 측의 구현 방법은 포럼의 Linux를 참고 하면된다.

 

개발 환경은 Ubuntu 16.04 이고 Python2.7 이다.

 

기본적으로 왠만한 리눅스 배포판에는 파이썬이 설치되어 있으며 파이썬 버전을 확인하는 방법은 터미널에서 아래의 명령을 통해 확인 할 수 있다.

$ python --version

Python 2.7.12

 
먼저 pydbus 패키지를 설치해야 하는데 아래 주소를 방문해서 패키지를 다운로드받는다.
https://pypi.python.org/pypi/pydbus#downloads
 
압축 풀기 및 패키지 설치
$ tar xvf pydbus-0.6.0.tar.gz

$ cd pydbus-0.6.0

$ sudo python setup.py install

 

혹시 아래와 같은 에러가 나온다면 

ImportError: No module named setuptools

 

python-setuptools 패키지를 설치해준다.

$ sudo apt-get install python-setuptools

 

아래와 같은 메시지를 확인 하자.

Finished processing dependencies for pydbus==0.6.0

 

이제 준비 과정이 끝났으니 서비스를 이용하는 클라이언트 예제 소스코드를 작성해보자.

HelloString 예제를 테스트했던 것과 같이 어떤 문자열을 전달하면 서비스측은 "전달한 문자열" + "world!" 하여 반환한다.

client.py

from pydbus import SessionBus

bus = SessionBus()
interface = bus.get('org.freedesktop.DBus.EchoService','/org/freedesktop/DBus/Examples/Echo') # Get Interface via Bus_Name and Object_Path.
demo = interface['org.freedesktop.DBus.EchoDemo']

response = demo.HelloString("https://makersweb.net") # Call Method

print(response)

 

위 파이썬 소스코드를 실행하면 

$ python client.py 

 

다음 그림과 같은 출력 결과를 볼 수 있다.

makersweb.net_world!!.png

 

아래는 이 예제를 대략적인 그림으로 나타낸 것이다.

dbus.png

 

다음에 기회가 된다면 서비스 데몬으로부터 비동기로 메시지를 받아 처리하는 방법을 소개하겠다.

 

pydbus바인딩의 더 많은 활용 법은 아래사이트를 참고하면 된다.

https://github.com/LEW21/pydbus/blob/master/doc/tutorial.rst


  1. No Image

    pybind11 에 대해서

    Date2023.07.23 CategoryGeneral Bymakersweb Views5796
    Read More
  2. Qt For Python(PySide2) QML 프로젝트 예제

    Date2019.10.17 CategoryBeginner Bymakersweb Views6538
    Read More
  3. 명령어 한줄로 내컴퓨터를 웹서버로

    Date2019.01.25 CategoryGeneral By운영자 Views5312
    Read More
  4. pydbus 바인딩을 이용하여 서비스 데몬과 D-Bus통신

    Date2018.03.12 Bymakersweb Views3961
    Read More
  5. Boost Python을 이용하여 python을 위한 C++ API 바인딩

    Date2017.01.08 Bymakersweb Views11222
    Read More
  6. No Image

    [Python]EXE또는 DLL파일의 버전정보를 알아내기위한 몇가지 방법

    Date2015.06.25 Bymakersweb Views10640
    Read More
  7. QML 및 Window 투명처리

    Date2015.04.22 CategoryPyQt4 Bymakersweb Views5848
    Read More
  8. No Image

    [pyqt4]QTimer 예제 - 버튼을 누르면 3초후 함수 또는 메소드 호출

    Date2015.04.01 CategoryPyQt4 Bymakersweb Views11561
    Read More
  9. No Image

    Python + QML with PyQt4

    Date2015.03.24 CategoryPyQt4 Bymakersweb Views9604
    Read More
  10. No Image

    print를 로그파일로 생성하기 (log출력 Redirection)

    Date2015.03.18 CategoryGeneral Bymakersweb Views7416
    Read More
  11. No Image

    외부 프로그램 실행

    Date2015.02.10 CategoryGeneral Bypjk Views17016
    Read More
  12. No Image

    우분투에 Python새 버전 설치 사용법

    Date2015.02.10 CategoryGeneral Bypjk Views4845
    Read More
  13. No Image

    How to Use Freeze

    Date2014.09.06 Bypjk Views6490
    Read More
  14. No Image

    [PyQt4]개발 프로그램 버전표시 메세지 박스

    Date2014.09.02 CategoryPyQt4 Bypjk Views9397
    Read More
  15. [PyQt4]여러가지 버튼 예제

    Date2014.08.29 CategoryPyQt4 Bypjk Views18981
    Read More
  16. No Image

    Python 문자열 관련 함수 레퍼런스

    Date2014.08.29 CategoryGeneral Bypjk Views8569
    Read More
  17. [PyQt4]스레드 및 ProgressBar 예제 코드

    Date2014.08.26 CategoryPyQt4 Bypjk Views9505
    Read More
  18. No Image

    [PyQt4]multiprocess 예제 코드

    Date2014.08.26 CategoryPyQt4 Bypjk Views9315
    Read More
  19. No Image

    [PyQt4]마우스 클릭 이벤트 예제 코드

    Date2014.08.26 CategoryPyQt4 Bypjk Views7768
    Read More
  20. [PyQt4]폴더 또는 파일을 드레그하여 그 경로를 LineEdit로 가져오기

    Date2014.08.22 CategoryPyQt4 Bypjk Views14845
    Read More
Board Pagination Prev 1 2 Next
/ 2