Skip to content

Commit

Permalink
Adding code and files to be able to embed TDI shell with one command
Browse files Browse the repository at this point in the history
Signed-off-by: Bandyopadhyay, Sayan <[email protected]>
  • Loading branch information
saynb committed Nov 15, 2024
1 parent 1abebdd commit 6628868
Show file tree
Hide file tree
Showing 7 changed files with 538 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS}")


add_subdirectory(src)
if(STANDALONE)
add_subdirectory(cli)
endif()

#Building tdi doxygen
find_package(Doxygen)
Expand Down
34 changes: 34 additions & 0 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.12)
project(libtdi_cli VERSION 0.1 LANGUAGES C)

find_package(Python3 COMPONENTS Interpreter Development)

set(TDI_CLI_SRCS
tdi_cli.c
)

set(TDI_CLI_EXAMPLES_SRCS
cli_example.c
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/target-syslibs/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/target-utils/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/target-utils/third-party/klish)

set(CMAKE_SHARED_LIBRARY_PREFIX "")

add_library(tdi_cli_o OBJECT ${TDI_CLI_SRCS})
target_include_directories(tdi_cli_o PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(tdi_cli_o PUBLIC target_sys tdi clish python3.11)

add_library(bfshell_plugin_tdi SHARED $<TARGET_OBJECTS:tdi_cli_o>)
target_link_libraries(bfshell_plugin_tdi PUBLIC target_sys tdi clish python3.11)

add_executable(tdi_cli_example ${TDI_CLI_EXAMPLES_SRCS})
target_link_libraries(tdi_cli_example bfshell_plugin_tdi)

install(TARGETS tdi_cli_example DESTINATION bin)
install(FILES xml/startup.xml xml/tdi.xml DESTINATION share/cli/xml)
36 changes: 36 additions & 0 deletions cli/cli_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright(c) 2024 Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>

#include "tdi_cli.h"

int main() {
char loc[] = "/root";
char * p4_names[] = {
"Program 1",
"Program 2",
};

tdi_shell_start(loc,
p4_names);
sleep(200);
}

Loading

0 comments on commit 6628868

Please sign in to comment.