D-BUS
(비) [D-BUS] 간단한 예제 CMakefile.txt 작성법 - bb file 작성법
2025. 3. 28. 00:32반응형
아래는 Yocto 프로젝트에서 이 D-Bus 예제를 빌드하기 위한 레시피(.bb 파일)와 관련 설정입니다.
(모든 파일은 meta-custom 레이어에 추가한다고 가정합니다.)
1. 레시피 파일 (simple-dbus-example_1.0.bb)
bitbake
Copy
SUMMARY = "Simple D-Bus Client/Server Example"
DESCRIPTION = "Demonstrates synchronous D-Bus communication between two processes"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://simple-dbus-example-1.0.tar.gz"
DEPENDS = "glib-2.0"
S = "${WORKDIR}/simple-dbus-example-1.0"
inherit cmake pkgconfig
do_install() {
install -d ${D}${bindir}
install -m 0755 ${B}/dbus_server ${D}${bindir}
install -m 0755 ${B}/dbus_client ${D}${bindir}
# D-Bus 서비스 활성화 (시스템 서비스인 경우)
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${S}/dbus-server.service ${D}${systemd_system_unitdir}
}
FILES:${PN} += "${bindir}/dbus_server ${bindir}/dbus_client"
2. 시스템 서비스 파일 (dbus-server.service)
ini
Copy
[Unit]
Description=Simple D-Bus Server
After=dbus.socket
[Service]
Type=simple
ExecStart=/usr/bin/dbus_server
[Install]
WantedBy=multi-user.target
3. 소스 코드 패키징 (수동 생성)
bash
Copy
mkdir -p simple-dbus-example-1.0
cp dbus_server.c dbus_client.c CMakeLists.txt dbus-server.service simple-dbus-example-1.0/
tar czvf simple-dbus-example-1.0.tar.gz simple-dbus-example-1.0
4. Yocto 빌드 설정 방법
1) 커스텀 레이어 생성 (이미 있다면 생략)
bash
Copy
bitbake-layers create-layer meta-custom
bitbake-layers add-layer meta-custom
2) 디렉토리 구조
Copy
meta-custom/
├── recipes-example/
│ └── simple-dbus-example/
│ ├── simple-dbus-example-1.0/
│ │ ├── dbus_server.c
│ │ ├── dbus_client.c
│ │ ├── CMakeLists.txt
│ │ └── dbus-server.service
│ └── simple-dbus-example_1.0.bb
3) 이미지에 패키지 추가
bash
Copy
echo 'IMAGE_INSTALL:append = " simple-dbus-example"' >> meta-custom/recipes-core/images/core-image-minimal.bbappend
4) 빌드 실행
bash
Copy
bitbake core-image-minimal
5. 타겟 시스템에서 테스트
1) 서버 실행 (수동 또는 시스템 서비스로)
bash
Copy
# 수동 실행
dbus_server &
# 시스템 서비스로 등록된 경우
systemctl start dbus-server
2) 클라이언트 테스트
bash
Copy
dbus_client
# 출력: "Client: Received 'Hello DBus!'"
6. 주요 고려사항
- D-Bus 정책 설정 (필요시 추가):
/etc/dbus-1/system.d/org.example.SimpleService.conf 파일 생성 -
xmlCopy
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> <busconfig> <policy context="default"> <allow own="org.example.SimpleService"/> <allow send_destination="org.example.SimpleService"/> </policy> </busconfig>
- 의존성 확인:
DEPENDS에 dbus 추가 필요시: -
bitbakeCopy
DEPENDS = "glib-2.0 dbus"
- 시스템 D-Bus vs 세션 D-Bus:
- 시스템 버스 사용시 서비스 파일과 정책 파일을 시스템 위치에 설치
- 세션 버스 사용시 사용자 단위로 실행 (User= 옵션 추가)
- 디버깅:
-
bashCopy
# D-Bus 메시지 모니터링 dbus-monitor --session "interface='org.example.SimpleService'"
7. 완전 자동화된 예제 패키지
모든 파일을 포함하는 자동 생성 스크립트 (prepare.sh):
bash
Copy
#!/bin/bash
mkdir -p simple-dbus-example-1.0
cat > simple-dbus-example-1.0/dbus_server.c << 'EOF'
[위의 server.c 내용 전체]
EOF
cat > simple-dbus-example-1.0/dbus_client.c << 'EOF'
[위의 client.c 내용 전체]
EOF
cat > simple-dbus-example-1.0/CMakeLists.txt << 'EOF'
[위의 CMakeLists.txt 내용 전체]
EOF
cat > simple-dbus-example-1.0/dbus-server.service << 'EOF'
[위의 service 파일 내용 전체]
EOF
tar czvf simple-dbus-example-1.0.tar.gz simple-dbus-example-1.0
이 스크립트 실행 후 생성된 tarball을 Yocto 레시피 디렉토리에 배치하면 즉시 빌드 가능합니다.
반응형
'D-BUS' 카테고리의 다른 글
[D-BUS] client.c server.c 예제 (0) | 2025.03.26 |
---|---|
[D-BUS] D-BUS란? (0) | 2025.03.24 |