C/C++ 제품 연동
제품의 생명주기에 원격 지원을 연결합니다. 기존 glibc 앱에는 POSIX 프로세스 어댑터를 권장합니다.
통합 구조
text
OEM application (your ETK / libc)
└─ streamzet_product.c [start / poll / stop]
└─ streamzet-embedded [static ARMv5 engine]
└─ outbound TLS :443 → StreamZet
└─ enrollment · terminal · Fleet · dashboard작은 C 어댑터를 OEM 앱에 컴파일하고, 검증된 정적 실행 엔진을 함께 배포합니다. TLS와 C 런타임은 별도 프로세스에 있으므로 OEM 앱의 glibc와 공유하지 않습니다. 통신·등록·재연결은 엔진이 처리하고, 호스트 앱은 자식 프로세스의 시작·감시·종료를 담당합니다.
필요한 파일
| 파일 | 역할 |
|---|---|
| sdk/product/streamzet_product.h | C/C++ 공개 인터페이스 |
| sdk/product/streamzet_product.c | OEM ETK로 컴파일하는 POSIX 어댑터 |
| sdk/product/example.c | 시작·감시·종료·회수 예제 |
| device/streamzet-embedded | 검증된 ARMv5 정적 실행 엔진 |
| device/cacert.pem | 서버 인증용 CA 번들 |
| registration.key + state/ | 기기별 준비 과정에서 생성·유지 |
제품의 툴체인으로 컴파일
sh
# Set CC to the matching OEM ETK C compiler.
"$CC" -std=c99 -D_POSIX_C_SOURCE=200809L \
-Isdk/product sdk/product/example.c sdk/product/streamzet_product.c \
-o streamzet-product-exampleC++ 제품은 streamzet_product.c를 C로 컴파일한 객체를 링크하고 헤더를 포함하면 됩니다. 배포할 예제 실행 파일을 준비된 장비에 복사한 다음 아래처럼 실행합니다. 기존 start.sh 엔진을 먼저 종료하고, 완전히 종료된 뒤 같은 상태로 시작하세요.
sh
./streamzet-product-example \
/mnt/spp/streamzet-jci/streamzet-embedded \
/mnt/spp/streamzet-jci/registration.key \
/mnt/spp/streamzet-jci/cacert.pem \
/mnt/spp/streamzet-jci/state \
'xSpan R660 001'호스트 생명주기 예제
c
#include "streamzet_product.h"
static stz_product support = {0};
int start_remote_support(void) {
const stz_product_config config = {
.engine_path = "/mnt/spp/streamzet-jci/streamzet-embedded",
.registration_file = "/mnt/spp/streamzet-jci/registration.key",
.ca_file = "/mnt/spp/streamzet-jci/cacert.pem",
.state_directory = "/mnt/spp/streamzet-jci/state",
.device_name = "xSpan R660 001"
};
return stz_product_start(&support, &config);
}
/* Call periodically from the same host thread. */
int poll_remote_support(int *wait_status) {
return stz_product_poll(&support, wait_status);
}
/* Request stop, then keep polling until the child is reaped. */
int stop_remote_support(void) {
return stz_product_stop(&support);
}- start가 0을 반환하면 프로세스 생성에 성공한 것입니다. 온라인 확인은 StreamZet 장비 상태로 합니다.
- 동일 핸들에 대한 호출을 직렬화하고 다른 SIGCHLD 핸들러가 이 자식을 회수하지 않게 하세요.
- 호스트의 불필요한 파일 디스크립터에 close-on-exec을 설정하세요. 어댑터의 자식은 stdout/stderr를 상속합니다.
- 네트워크 재접속은 자동입니다. 프로세스 자체가 종료되면 poll로 확인하고 OEM의 재시작 정책을 적용하세요.
- SDK 모드에서는 start.sh를 동시에 실행하지 마세요. 종료 요청 후 poll로 회수하기 전 핸들을 재사용하지 마세요.
저수준 정적 라이브러리
SDK의 sdk/musl에는 libstreamzet-embedded.a와 TLS 라이브러리·헤더가 있습니다. 새 musl ARMv5 앱에서는 stz_create → 작업 스레드에서 stz_run → stz_stop → 스레드 join → stz_destroy 순서를 사용합니다. 엔트로피·기기 식별자 영속화와 단일 TLS 런타임 계약도 따라야 합니다.