Skip to content

Commit e03137b

Browse files
anthonypayne-GMammolitor
authored andcommitted
lib: someip-c: Added SOME/IP C library
The SOME/IP C library is a wrapper around vsomeip. Signed-off-by: Anthony Payne <[email protected]>
1 parent ea3ffc1 commit e03137b

File tree

9 files changed

+1362
-0
lines changed

9 files changed

+1362
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ if(FLB_ALL)
239239
set(FLB_IN_NGINX_STATUS 1)
240240
set(FLB_IN_EXEC 1)
241241
set(FLB_IN_UNIX_SOCKET 1)
242+
set(FLB_IN_SOMEIP 1)
242243

243244
# Output plugins
244245
set(FLB_OUT_ES 1)
@@ -665,6 +666,11 @@ if(FLB_WASM)
665666
endif ()
666667
endif()
667668

669+
# SOME/IP
670+
if(FLB_IN_SOMEIP)
671+
add_subdirectory(${FLB_PATH_LIB_SOMEIP_C} EXCLUDE_FROM_ALL)
672+
endif()
673+
668674
# AWS
669675
if (FLB_AWS)
670676
FLB_DEFINITION(FLB_HAVE_AWS)

cmake/libraries.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ set(FLB_PATH_LIB_RDKAFKA "lib/librdkafka-2.4.0")
2626
set(FLB_PATH_LIB_RING_BUFFER "lib/lwrb")
2727
set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.3.3")
2828
set(FLB_PATH_LIB_ZSTD "lib/zstd-1.5.7")
29+
set(FLB_PATH_LIB_SOMEIP_C "lib/libsomeip-c")

cmake/plugins_options.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ DEFINE_OPTION(FLB_IN_WINDOWS_EXPORTER_METRICS "Enable windows exporter metrics i
6363
DEFINE_OPTION(FLB_IN_WINEVTLOG "Enable Windows EvtLog input plugin" OFF)
6464
DEFINE_OPTION(FLB_IN_WINSTAT "Enable Windows Stat input plugin" OFF)
6565
DEFINE_OPTION(FLB_IN_EBPF "Enable Linux eBPF input plugin" OFF)
66+
DEFINE_OPTION(FLB_IN_SOMEIP "Enable SOME/IP input plugin" OFF)
6667

6768
# Processors
6869
# ==========

cmake/windows-setup.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ if(FLB_WINDOWS_DEFAULTS)
5454
set(FLB_IN_EMITTER Yes)
5555
set(FLB_IN_PODMAN_METRICS No)
5656
set(FLB_IN_EBPF No)
57+
set(FLB_IN_SOMEIP No)
5758
set(FLB_IN_ELASTICSEARCH Yes)
5859
set(FLB_IN_SPLUNK Yes)
5960
set(FLB_IN_PROMETHEUS_REMOTE_WRITE Yes)

lib/libsomeip-c/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
project(someipc CXX)
2+
3+
find_package(vsomeip3 QUIET)
4+
5+
if(NOT(vsomeip3_FOUND))
6+
MESSAGE(STATUS "vsomeip not found disabling SOMEIP input plugin")
7+
set(FLB_IN_SOMEIP OFF PARENT_SCOPE)
8+
else()
9+
MESSAGE(DEBUG "Found vsomeip package. Adding in someip-c library.")
10+
add_library(someip-c SHARED src/someip_wrapper.cc)
11+
target_include_directories(someip-c PUBLIC include)
12+
target_link_libraries(someip-c PRIVATE vsomeip3 vsomeip3-sd vsomeip3-cfg vsomeip3-e2e)
13+
target_link_options(someip-c PUBLIC "-Wl,--disable-new-dtags")
14+
15+
add_subdirectory(example)
16+
endif()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
add_executable(someip_test_service test_service.c)
3+
target_link_libraries(someip_test_service PRIVATE someip-c)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/* Fluent Bit
2+
* ==========
3+
* Copyright (C) 2015-2024 The Fluent Bit Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include <stdint.h>
18+
#include <stdio.h>
19+
#include <stdlib.h>
20+
#include <string.h>
21+
#include <unistd.h>
22+
23+
#include "someip_api.h"
24+
25+
26+
static const char* NAME = "Test Service";
27+
static const uint16_t SERVICE_ID = 4;
28+
static const uint16_t INSTANCE_ID = 1;
29+
static const uint16_t METHOD_ID = 1;
30+
static const uint16_t EVENT_ID = 0x8000U;
31+
static const uint16_t EVENT_GROUP_ID = 1;
32+
33+
static uint16_t client_id = 0;
34+
35+
/*
36+
* Function to handle callback when a request is received.
37+
* @param request_ptr Pointer to the structure that has the request details.
38+
*/
39+
void HandleRequest(void*, struct some_ip_request *request_ptr) {
40+
static const char* response = "This is the response to the request";
41+
int ret = 0;
42+
if (request_ptr == NULL) {
43+
return;
44+
}
45+
printf("Received request (method = %d)\n", request_ptr->method_id);
46+
printf("Payload length = %ld\n", request_ptr->payload_len);
47+
48+
/* Normal service would Parse the request and perform/initiate some actions on it*/
49+
/* For this example just send back a canned response */
50+
51+
ret = someip_send_response(client_id, request_ptr->request_id.client_request_id,
52+
(void*)response, strlen(response));
53+
if (ret != SOMEIP_RET_SUCCESS) {
54+
printf("Failed to send response: %d\n", ret);
55+
}
56+
}
57+
58+
/*
59+
* Function to initialize the test service with the SOME/IP library.
60+
* @return 0 on success, -1 on failure.
61+
*/
62+
int Initialize() {
63+
int ret = someip_initialize(NAME, &client_id);
64+
if (ret != SOMEIP_RET_SUCCESS) {
65+
printf("Failed to initialize SOME/IP: %d\n", ret);
66+
return -1;
67+
}
68+
69+
/* Register Request Handler */
70+
ret = someip_register_request_handler(client_id, SERVICE_ID, INSTANCE_ID,
71+
METHOD_ID, NULL, HandleRequest);
72+
73+
if (ret != SOMEIP_RET_SUCCESS) {
74+
printf("Failed to register request handler: %d\n", ret);
75+
someip_shutdown(client_id);
76+
return -1;
77+
}
78+
79+
/* Offer Event */
80+
ret = someip_offer_event(client_id, SERVICE_ID, INSTANCE_ID, EVENT_ID, (uint16_t*)&EVENT_GROUP_ID, 1);
81+
if (ret != SOMEIP_RET_SUCCESS) {
82+
printf("Failed to Offer Event: %d\n", ret);
83+
someip_shutdown(client_id);
84+
return -1;
85+
}
86+
87+
/* Offer Service */
88+
ret = someip_offer_service(client_id, SERVICE_ID, INSTANCE_ID);
89+
if (ret != SOMEIP_RET_SUCCESS) {
90+
printf("Failed to Offer Service: %d\n", ret);
91+
someip_shutdown(client_id);
92+
return -1;
93+
}
94+
95+
return 0;
96+
}
97+
98+
void Teardown() {
99+
someip_shutdown(client_id);
100+
}
101+
102+
void SendEvent(const int num) {
103+
const char* base_msg = "Event Number ";
104+
char buffer[128];
105+
int ret = 0;
106+
strcpy(buffer, base_msg);
107+
sprintf(buffer + strlen(base_msg), "%d", num);
108+
109+
printf("Sending event with message %s\n", buffer);
110+
111+
ret = someip_send_event(client_id, SERVICE_ID, INSTANCE_ID, EVENT_ID,
112+
buffer, strlen(buffer));
113+
if (ret != SOMEIP_RET_SUCCESS) {
114+
printf ("Failed to send event, %d\n", ret);
115+
}
116+
}
117+
118+
119+
int main() {
120+
int num_events = 10;
121+
if (Initialize() != 0) {
122+
return EXIT_FAILURE;
123+
}
124+
125+
126+
for (int i = 0; i <= num_events; ++i) {
127+
SendEvent(i);
128+
sleep(2);
129+
}
130+
131+
Teardown();
132+
return EXIT_SUCCESS;
133+
}

0 commit comments

Comments
 (0)