diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2017-06-08 10:55:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-08 10:55:44 -0700 |
commit | 817052ffe35991d6927e9176528821323b4e6812 (patch) | |
tree | 7f2d71734472cc1e2729914a5c9dbf81eccd4ef2 | |
parent | aaa56de4838de3147616c7e88d312a2dc623ad7d (diff) | |
parent | 9d2148a9ba9edc814654b97b70c4a0f999ebcf8b (diff) | |
download | sdl_core-817052ffe35991d6927e9176528821323b4e6812.tar.gz |
Merge pull request #1543 from smartdevicelink/feature/external_policy_manager
Sample External Policy Manager
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | src/appMain/CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/appMain/sample_policy_manager.py | 123 | ||||
-rw-r--r-- | src/appMain/start.sh | 2 | ||||
-rw-r--r-- | src/appMain/start_external_proprietary.sh | 21 |
5 files changed, 167 insertions, 2 deletions
@@ -49,7 +49,7 @@ Once SDL Core is compiled and installed you can start it from the executable in ``` %cd bin/ -%LD_LIBRARY_PATH=. ./smartDeviceLinkCore +%./start.sh ``` ## Start WEB HMI @@ -73,6 +73,11 @@ The dependencies for SDL Core vary based on the configuration. You can change SD |Testing framework|Needed to support running unit tests|libgtest-dev| |Cmake|Needed to configure SDL prior to compilation|cmake| +#### Sample Policy Manager +The included sample policy manager (for use with `EXTERNAL_PROPRIETARY` policy mode) requires the following packages: + - python-pip + - python-dev + ### Known Dependency Issues * log4cxx - We know that the version of log4cxx on a linux machine can conflict with the one used, which is why it is provided in the repository. To avoid the conflict, we recommend removing liblog4cxx*. * cmake - on some versions of linux, the included cmake package doesn't have the right version. If apt-get is your package manager, you can find the correct version using diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index 9fddc3226a..de81a0b07e 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -149,6 +149,9 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.txt DESTINATION ${CMAKE_CURRENT_BINAR file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/smartDeviceLink.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/hmi_capabilities.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/sdl_preloaded_pt.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/sample_policy_manager.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/start.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/start_external_proprietary.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) if (CMAKE_SYSTEM_NAME STREQUAL "QNX") file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/init_policy.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) endif () @@ -198,7 +201,7 @@ endif () install(TARGETS ${PROJECT} DESTINATION bin) install( FILES log4cxx.properties audio.8bit.wav test.txt smartDeviceLink.ini - hmi_capabilities.json sdl_preloaded_pt.json + hmi_capabilities.json sdl_preloaded_pt.json sample_policy_manager.py ${CMAKE_SOURCE_DIR}/mycert.pem ${CMAKE_SOURCE_DIR}/mykey.pem DESTINATION bin ) @@ -218,3 +221,14 @@ if (CMAKE_SYSTEM_NAME STREQUAL "QNX") PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif () + +if (${EXTENDED_POLICY} STREQUAL "EXTERNAL_PROPRIETARY") + install(FILES start_external_proprietary.sh DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ + GROUP_EXECUTE WORLD_READ WORLD_EXECUTE RENAME start.sh) +else() + install(FILES start.sh DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ + GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +endif() + diff --git a/src/appMain/sample_policy_manager.py b/src/appMain/sample_policy_manager.py new file mode 100644 index 0000000000..681c7bbb91 --- /dev/null +++ b/src/appMain/sample_policy_manager.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +import argparse +import asyncore +import socket +import json + +import tornado.httpserver +import tornado.websocket +import tornado.ioloop +import tornado.web + +parser = argparse.ArgumentParser() +parser.add_argument("--host", type=str, default="127.0.0.1", + help="Host to listen HMI") +parser.add_argument("--pack_port", type=int, default="8088", + help="Port for packing policy table", required=True) +parser.add_argument("--unpack_port", type=int, default="8089", + help="Port for unpacking policy table", required=True) +parser.add_argument("--buffer_size", type=int, default=8192, + help="Size of buffer for input data") +parser.add_argument("--add_http_header", action="store_true", + help="Enter this parameter to add HTTP heaer on packing policy table") +parser.add_argument("--encryption", action="store_true", + help="Encrypt policy table") + + +def http_header(data): + header = {} + header["HTTPRequest"] = {} + header["HTTPRequest"]["headers"] = { + "ConnectTimeout": 60, + "ContentType": "application/json", + "Content-Length": len(data), + "DoInput": True, + "DoOutput": True, + "InstanceFollowRedirects": False, + "ReadTimeout": 60, + "RequestMethod": "POST", + "UseCaches": False, + "charset": "utf-8"} + header["HTTPRequest"]["body"] = data + return json.dumps(header) + + +def crypt(data): + return data + + +def decrypt(data): + return data + +def pack(file_path, encryption, add_http_header): + + file = open(file_path, "r+") + data = file.read() + file.seek(0) + file.truncate() + + if encryption: + data = crypt(data) + if add_http_header: + data = http_header(data) + + file.write(data) + file.close() + return file_path + + +def unpack(file_path, encryption): + + file = open(file_path, 'r+') + read_data = file.read() + file.seek(0) + file.truncate() + + json_data = json.loads(read_data) + policy_data = json.dumps(json_data['data'][0]) + + if encryption: + policy_data = decrypt(policy_data) + + file.write(policy_data) + file.close() + + return file_path + + +class WebSocketHandler(tornado.websocket.WebSocketHandler): + + def initialize(self,encryption, add_http_header, handle_func): + self.handle_func = handle_func + self.encryption = encryption + self.add_http_header = add_http_header + + def open(self): + print ("Socket Connected\n") + + def on_message(self, data): + self.write_message(self.handle_func(data, self.encryption, self.add_http_header)) + + def on_close(self): + print ("Connection Closed\n") + + def check_origin(self, origin): + return True + + +if __name__ == "__main__": + + args = parser.parse_args() + + pack_application = tornado.web.Application([(r'/', WebSocketHandler, dict(encryption=args.encryption, add_http_header=args.add_http_header, + handle_func = lambda data, encryption, add_http_header: pack(data, encryption, add_http_header)))]) + + unpack_application = tornado.web.Application([(r'/', WebSocketHandler, dict(encryption=args.encryption, add_http_header=None, + handle_func = lambda data, encryption, add_http_header: unpack(data, encryption)))]) + + pack_server = tornado.httpserver.HTTPServer(pack_application) + unpack_server = tornado.httpserver.HTTPServer(unpack_application) + + pack_server.listen(args.pack_port, args.host) + unpack_server.listen(args.unpack_port, args.host) + tornado.ioloop.IOLoop.instance().start()
\ No newline at end of file diff --git a/src/appMain/start.sh b/src/appMain/start.sh new file mode 100644 index 0000000000..ea6dea9d50 --- /dev/null +++ b/src/appMain/start.sh @@ -0,0 +1,2 @@ +#!/bin/bash +LD_LIBRARY_PATH=. ./smartDeviceLinkCore
\ No newline at end of file diff --git a/src/appMain/start_external_proprietary.sh b/src/appMain/start_external_proprietary.sh new file mode 100644 index 0000000000..15ee2ecae5 --- /dev/null +++ b/src/appMain/start_external_proprietary.sh @@ -0,0 +1,21 @@ +#!/bin/bash +pip list | grep -F tornado > /dev/null +if [ $? -eq 1 ] + then + echo "Installing tornado python package" + sudo pip install tornado +fi +echo "Starting Policy Manager" +python sample_policy_manager.py --pack_port 8088 --unpack_port 8089 --add_http_header --encryption & +POLICY_MANAGER=$! + +trap ctrl_c INT + +function ctrl_c() { + echo "Stopping SmartDeviceLinkCore" + kill -INT $POLICY_MANAGER + kill -9 $POLICY_MANAGER +} + +echo "Starting SmartDeviceLinkCore" +LD_LIBRARY_PATH=. ./smartDeviceLinkCore |