commit 3c34b2343100838c3c6bf6a100dfb1f324d2dc01 Author: lijie <1713699517@qq.com> Date: Thu Feb 23 17:17:38 2023 +0800 ft: 初始化提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..798fb06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +.eunit +*.o +*.beam +*.plt +erl_crash.dump +.concrete/DEV_MODE + +# rebar 2.x +.rebar +rel/example_project +ebin/* +deps + +# rebar 3 +.rebar3 +_build/ +_checkouts/ +rebar.lock + +# idea +.idea +*.iml +cmake-build* +CMakeLists.txt + +# nif compile temp file +*.pdb +*.d +compile_commands.json + +# vs +.vs +x64 +*.vcx* +*.sln \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..228cf38 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 AICells + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a76aca --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +eHJps +===== + +An OTP Lib of hexagon jps implementation. + +设计模型 + nif 层采用单线程更新地图数据多线程寻路的模型 + erlang层相关请求采用队列模型 更新地图线程和寻路线程 分别从两个不同的任务队列获取新的请求并处理 + diff --git a/c_src/HJpsNif/eHJps.c b/c_src/HJpsNif/eHJps.c new file mode 100644 index 0000000..86ee3b5 --- /dev/null +++ b/c_src/HJpsNif/eHJps.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +#include "eHJpsAtom.h" + +typedef struct Node_r { + bool IsBarrier; // 是否障碍 +} Node; + +int nifLoad(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { + enif_fprintf(stdout, "IMY*************nifload00000\n"); + NIF_ATOMS(NIF_ATOM_INIT) + + enif_fprintf(stdout, "IMY*************nifload00001\n"); + *priv_data = NULL; + + return 0; +} + +int nifUpgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM load_info) { + *priv_data = *old_priv_data; + enif_fprintf(stdout, "IMY*************nifUpgrade %p %T\n", old_priv_data, load_info); + return 0; +} + +void nifUnload(ErlNifEnv* env, void* priv_data) { + enif_fprintf(stdout, "IMY*************nifUnload0000 \n"); + return; +} + +static ErlNifFunc nifFuns[] = { +}; + +ERL_NIF_INIT(eQuic, nifFuns, nifLoad, NULL, nifUpgrade, nifUnload) \ No newline at end of file diff --git a/c_src/HJpsNif/eHJpsAtom.h b/c_src/HJpsNif/eHJpsAtom.h new file mode 100644 index 0000000..86dea56 --- /dev/null +++ b/c_src/HJpsNif/eHJpsAtom.h @@ -0,0 +1,21 @@ +#ifndef __QUIC_ATOM_H_ +#define __QUIC_ATOM_H_ + +#include + +#define NIF_ATOM_DECL(a) ERL_NIF_TERM atom_ ## a; +#define NIF_ATOM_INIT(a) atom_ ## a = enif_make_atom(env, #a); + +#define NIF_ATOMS(A) \ + /* atom of common */ \ + A(ok) \ + A(quic) \ + A(error) \ + A(true) \ + A(false) \ + A(undefined) \ + A(freed) + +NIF_ATOMS(NIF_ATOM_DECL) + +#endif diff --git a/c_src/HJpsNif/rebar.config b/c_src/HJpsNif/rebar.config new file mode 100644 index 0000000..343df98 --- /dev/null +++ b/c_src/HJpsNif/rebar.config @@ -0,0 +1,8 @@ +{port_specs, [ + {"../../priv/eHJps.so", ["eHJps.c"]} +]}. + +{port_env, []}. + + + diff --git a/c_src/eNpc b/c_src/eNpc new file mode 100644 index 0000000..419399f Binary files /dev/null and b/c_src/eNpc differ diff --git a/c_src/eNpc.cmd b/c_src/eNpc.cmd new file mode 100644 index 0000000..6c7a1ca --- /dev/null +++ b/c_src/eNpc.cmd @@ -0,0 +1,4 @@ +@echo off +setlocal +set rebarscript=%~f0 +escript.exe "%rebarscript:.cmd=%" %* diff --git a/include/eHJps.hrl b/include/eHJps.hrl new file mode 100644 index 0000000..10d19ad --- /dev/null +++ b/include/eHJps.hrl @@ -0,0 +1,5 @@ +-ifndef(eHJps_H). +-define(eHJps_H, true). + + +-endif. \ No newline at end of file diff --git a/priv/eHJps.so b/priv/eHJps.so new file mode 100644 index 0000000..6b7545e Binary files /dev/null and b/priv/eHJps.so differ diff --git a/rebar.config b/rebar.config new file mode 100644 index 0000000..900a6a4 --- /dev/null +++ b/rebar.config @@ -0,0 +1,15 @@ +{erl_opts, [no_debug_info, {i, "include"}]}. +{deps, [ + {eSync, ".*", {git, "http://sismaker.tpddns.cn:53000/SisMaker/eSync.git", {branch, "master"}}} +]}. + +{shell, [ + % {config, "config/sys.config"}, + {apps, [eHJps]} +]}. + +{pre_hooks, + [{"", compile, "escript c_src/eNpc compile"}]}. + +{post_hooks, + [{"", clean, "escript c_src/eNpc clean"}]}. \ No newline at end of file diff --git a/src/eHJps.app.src b/src/eHJps.app.src new file mode 100644 index 0000000..c570d83 --- /dev/null +++ b/src/eHJps.app.src @@ -0,0 +1,10 @@ +{application, eHJps, + [{description, "An library of hexagon jps"}, + {vsn, "0.1.0"}, + {registered, []}, + {applications, [kernel, stdlib, eSync]}, + {env,[]}, + {modules, []}, + {licenses, ["MIT"]}, + {links, []} + ]}. diff --git a/src/eHJps.erl b/src/eHJps.erl new file mode 100644 index 0000000..c100763 --- /dev/null +++ b/src/eHJps.erl @@ -0,0 +1,44 @@ +-module(eHJps). + +-include("eHJps.hrl"). + +-nifs ([ + initMap/1 + , updateMap/3 + , findPath/5 +]). + +-on_load(init/0). + +-export([ + initMap/1 + , updateMap/3 + , findPath/5 +]). + +init() -> + case code:priv_dir(?MODULE) of + {error, _} -> + case code:which(?MODULE) of + Filename when is_list(Filename) -> + SoName = filename:join([filename:dirname(Filename), "../priv", atom_to_list(?MODULE)]); + _ -> + SoName = filename:join("../priv", atom_to_list(?MODULE)) + end; + Dir -> + SoName = filename:join(Dir, atom_to_list(?MODULE)) + end, + erlang:load_nif(SoName, 0). + +-define(NOT_LOADED, erlang:nif_error({not_loaded, {module, ?MODULE}, {line, ?LINE}})). + +initMap(_Data) -> + ?NOT_LOADED. + +updateMap(_X, _Y, _NodeInfo) -> + ?NOT_LOADED. + +findPath(_StartX, _StartY, _EndX, _EndY, _UpdateInfo) -> + ?NOT_LOADED. + + diff --git a/src/user_default.erl b/src/user_default.erl new file mode 100644 index 0000000..60df348 --- /dev/null +++ b/src/user_default.erl @@ -0,0 +1,4 @@ +-module(user_default). + +-compile([export_all, nowarn_export_all]). +