diff --git a/src/client/spark/sys/api/Test/ApiTests.cs b/src/client/spark/sys/api/Test/ApiTests.cs index 3a1a873bd..66c16584b 100644 --- a/src/client/spark/sys/api/Test/ApiTests.cs +++ b/src/client/spark/sys/api/Test/ApiTests.cs @@ -1,4 +1,4 @@ -using bts.api; +using bts.api; using bts.api.core; using bts.api.test; using NUnit.Framework; @@ -31,7 +31,7 @@ namespace mbts.api.Test { [TearDown] public void teardown() { ApiTestsNativeMethods.apitest_stop_apitest_service(_native_server); - _managed_server.Dispose(); + Disposable.dispose(ref _managed_server); Disposable.dispose(ref _context); } diff --git a/src/client/spark/uicore/Shell/ShellModel.cs b/src/client/spark/uicore/Shell/ShellModel.cs index 28a0b139e..d489fd51c 100644 --- a/src/client/spark/uicore/Shell/ShellModel.cs +++ b/src/client/spark/uicore/Shell/ShellModel.cs @@ -45,7 +45,7 @@ namespace mbts.ui component_catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellModel).Assembly)); // Add plugin path - string plugin_path = Configuration.get().installation_specific_data_path + "/plugins/"; + string plugin_path = Configuration.get().data_path + "/plugins/"; if (Directory.Exists(plugin_path)) { component_catalog.Catalogs.Add(new DirectoryCatalog(plugin_path)); } diff --git a/src/client/spark/uicore/Shell/Workspaces/WorkspacesModel.cs b/src/client/spark/uicore/Shell/Workspaces/WorkspacesModel.cs index 4d06743c9..eaf10a17d 100644 --- a/src/client/spark/uicore/Shell/Workspaces/WorkspacesModel.cs +++ b/src/client/spark/uicore/Shell/Workspaces/WorkspacesModel.cs @@ -110,7 +110,7 @@ namespace mbts.ui.shell private static string local_workspace_path() { var system = Configuration.get(); - return @"{0}/{1}/{2}".fmt(system.installation_specific_data_path, WORKSPACE_NAMESPACE, "recover_workspace"); + return @"{0}/{1}/{2}".fmt(system.data_path, WORKSPACE_NAMESPACE, "recover_workspace"); } private static void save_workspace_locally(WorkspaceDefinition workspace) { string path = local_workspace_path(); diff --git a/src/lib/api/core/ApiServerInterop.cpp b/src/lib/api/core/ApiServerInterop.cpp index 2c1ce4eba..f44272321 100644 --- a/src/lib/api/core/ApiServerInterop.cpp +++ b/src/lib/api/core/ApiServerInterop.cpp @@ -22,7 +22,7 @@ struct ApiServerCore { qbus::RPCServer rpc; }; -BTS_EXPORT ApiServerCore* api_server_create(Quickbus* pbus, const char* type_name, const char* service_qualifier, raw_rpc_request_callback cb, void* extra) { +CAPI ApiServerCore* api_server_create(Quickbus* pbus, const char* type_name, const char* service_qualifier, raw_rpc_request_callback cb, void* extra) { bts_assert(pbus); // Invalid characters in qualifier: + for (auto ch : { '+', '_' }) { @@ -38,7 +38,7 @@ BTS_EXPORT ApiServerCore* api_server_create(Quickbus* pbus, const char* type_nam }); } -BTS_EXPORT void api_server_call_callback(ReplyHandler** ppvhandler, const uint8_t* buffer, int length) { +CAPI void api_server_call_callback(ReplyHandler** ppvhandler, const uint8_t* buffer, int length) { bts_assert(ppvhandler); bts_assert(*ppvhandler); LOG(Api,Diag,"Send rpc reply: {}",reinterpret_cast(*ppvhandler)); @@ -50,14 +50,14 @@ BTS_EXPORT void api_server_call_callback(ReplyHandler** ppvhandler, const uint8_ *pphandler = nullptr; } -BTS_EXPORT TableHandle api_server_create_table(ApiServerCore* pserver, const char* method_and_qualifier) { +CAPI TableHandle api_server_create_table(ApiServerCore* pserver, const char* method_and_qualifier) { bts_assert(pserver); auto topic = stream_topic(pserver->topic, method_and_qualifier); LOG(Api,Info,"Create table: {}",topic.value()); return new qbus::TablePublisher(pserver->qbus, topic); } -BTS_EXPORT void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count) { +CAPI void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count) { if (change_count > 0) { bts_assert(htable); qbus::TablePublisher* ptable = reinterpret_cast(htable); @@ -72,7 +72,7 @@ BTS_EXPORT void api_server_update_table(TableHandle htable, StreamUpdate* raw_ch } } -BTS_EXPORT void api_server_destroy_table(qbus::TablePublisher* ptable) { +CAPI void api_server_destroy_table(qbus::TablePublisher* ptable) { if (ptable) { ptable->disconnect(); delete ptable; diff --git a/src/lib/api/core/ApiServerInterop.h b/src/lib/api/core/ApiServerInterop.h index 7cee3553f..3e03d2be3 100644 --- a/src/lib/api/core/ApiServerInterop.h +++ b/src/lib/api/core/ApiServerInterop.h @@ -5,15 +5,14 @@ namespace bts { namespace api { struct ApiServerCore; -//struct ReplyHandler; typedef void ReplyHandler; typedef void(*raw_rpc_request_callback)(const uint8_t* buffer, size_t length, ReplyHandler* callback, void* extra); -BTS_EXPORT ApiServerCore* api_server_create(Quickbus* pbus, const char* type_name, const char* service_qualifier, raw_rpc_request_callback reply, void* extra); +CAPI ApiServerCore* api_server_create(Quickbus* pbus, const char* type_name, const char* service_qualifier, raw_rpc_request_callback reply, void* extra); -BTS_EXPORT void api_server_call_callback(ReplyHandler** pphandler, const uint8_t* buffer, int length); +CAPI void api_server_call_callback(ReplyHandler** pphandler, const uint8_t* buffer, int length); typedef void* TableHandle; -BTS_EXPORT TableHandle api_server_create_table(ApiServerCore* pserver, const char* method_and_qualifier); -BTS_EXPORT void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count); +CAPI TableHandle api_server_create_table(ApiServerCore* pserver, const char* method_and_qualifier); +CAPI void api_server_update_table(TableHandle htable, StreamUpdate* raw_changes, int change_count); }}//namespace diff --git a/src/lib/config/ConfigurationState.cpp b/src/lib/config/ConfigurationState.cpp index 0df1cec2c..42d909673 100755 --- a/src/lib/config/ConfigurationState.cpp +++ b/src/lib/config/ConfigurationState.cpp @@ -171,37 +171,17 @@ void ConfigurationState::initialize_defaults() _is_initialized = true; } - -std::string get_installation(const std::string& path) -{ - // "Installation" is defined as the directory where we are installed - // "bin" is special cased to "" as a backwards compatibility for developers - bts_assert(!path.empty()); - std::string parent_path = boost::filesystem::path(path).parent_path().string(); - size_t last = parent_path.find_last_of("/\\"); - if (last + 1 >= parent_path.size()) - return ""; - std::string installation = parent_path.substr(last + 1, parent_path.size() - last); - if (installation == "bin") - return ""; - return installation; -} - void ConfigurationState::initialize_builtins() { System sys; sys.set_host_name(os::host_name()); sys.set_process_name(os::get_application_name()); - sys.set_process_path(os::get_application_path()); + sys.set_directory(os::get_install_path()); sys.set_platform(os::platform_name()); sys.set_qualifier(os::get_qualifier()); sys.set_unittest_environment(utils::internal::is_unittest_environment()); sys.set_data_path(os::bts_data_path()); - sys.set_installation(get_installation(sys.process_path())); - sys.set_installation_specific_data_path(sys.data_path() + sys.installation() + "/"); -// sys.set_build_number(BUILD_NUMBER); - sys.set_build_number(0); sys.set_os_user(os::username()); #ifndef NDEBUG sys.set_build_type("debug"); diff --git a/src/lib/config/protos/system.proto b/src/lib/config/protos/system.proto index 807931ccc..655189967 100755 --- a/src/lib/config/protos/system.proto +++ b/src/lib/config/protos/system.proto @@ -6,16 +6,14 @@ message System { required string host_name = 1; required string process_name = 3; - required string process_path = 4; + required string directory = 4; required string platform = 5; required string qualifier = 6; required bool unittest_environment = 7; required string data_path = 8; optional string version = 9 [default = "private"]; repeated string cmd_args = 10; - required string installation = 11; - required string installation_specific_data_path = 12; - required int32 build_number = 13 [default = 0]; + // 11,12,13 required string build_type = 14 [default = "release"]; required string config_host = 15; required string config_ip = 16 [default = "127.0.0.1"]; diff --git a/src/lib/os/os.cpp b/src/lib/os/os.cpp index a664964e2..4ccdaf173 100755 --- a/src/lib/os/os.cpp +++ b/src/lib/os/os.cpp @@ -3,6 +3,7 @@ #include "lib/utils/bts_debugger.h" #include "lib/config/config.h" #include "lib/utils/bts_array_size.h" +#include "lib/utils/helper_macros.h" #include #include @@ -450,21 +451,13 @@ std::string host_name () return std::string (buffer); } -std::string get_install_path() -{ - auto result = get_application_path(); - // Trim the filename - size_t last = result.find_last_of("/\\"); - result.erase(last); - return result; -} - -std::string get_application_path() +std::string get_application_path(const char* module_name) { char buffer[1024]; #ifdef _WIN32 - int bytes = GetModuleFileName(NULL, buffer, sizeof(buffer)); + int bytes = GetModuleFileName(GetModuleHandle(module_name), buffer, sizeof(buffer)); #elif __linux__ + UNUSED(module_name); // I'm not completely happy with this solution but there doesn't seem to be anything // more standard. char temp[32]; @@ -485,9 +478,19 @@ std::string get_application_path() } } +std::string get_install_path() +{ + // The install path is the location of spark_lib (on Windows) since there may be an api client or other entry point (nunit?) + auto result = get_application_path("spark_lib"); + // Trim the filename + size_t last = result.find_last_of("/\\"); + result.erase(last); + return result; +} + std::string get_application_name() { - std::string app_path = get_application_path(); + std::string app_path = get_application_path(nullptr); size_t last = app_path.find_last_of("/\\"); if (last + 1 >= app_path.size()) return ""; @@ -714,14 +717,13 @@ std::string bts_system_path() std::string bts_data_path() { - std::string path = - bts_user_path() + "data/"; + std::string path = bts_user_path() + "data/"; if (!boost::filesystem::is_directory(path)) { boost::filesystem::create_directories(path); } - return path; + return normalize_path(path); } std::string username() { diff --git a/src/lib/os/os.h b/src/lib/os/os.h index c2500fd9e..80ebe8b30 100755 --- a/src/lib/os/os.h +++ b/src/lib/os/os.h @@ -53,7 +53,6 @@ BTS_EXPORT std::string default_host_ip (); BTS_EXPORT std::string host_ip (std::string const &interface_name); BTS_EXPORT std::map host_ips (); BTS_EXPORT uint64_t tick_count (); -BTS_EXPORT std::string get_application_path(); BTS_EXPORT std::string get_install_path(); BTS_EXPORT std::string get_application_name(); BTS_EXPORT std::string get_cwd();