41 private: |
41 private: |
42 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
42 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
43 std::map<int, std::shared_ptr<SubProcess>> subProcesses; |
43 std::map<int, std::shared_ptr<SubProcess>> subProcesses; |
44 std::map<int, std::vector<AttributeMetadata>> cachedMetadata; |
44 std::map<int, std::vector<AttributeMetadata>> cachedMetadata; |
45 |
45 |
46 string_t getExecCommand(const RequestedField& field) { |
46 string_t getStreamletPath() { |
47 // TODO: move to another directory, exec, not script + use custom $PATH with no prefix |
47 const char* originalPath = getenv("PATH"); |
48 return SCRIPT_PREFIX + field.name; |
48 const char* streamletPath = getenv("RELPIPE_IN_FILESYSTEM_STREAMLET_PATH"); |
|
49 |
|
50 if (originalPath && streamletPath) return convertor.from_bytes(std::string(streamletPath) + ":" + originalPath); |
|
51 else if (originalPath) return convertor.from_bytes(std::string(originalPath)); |
|
52 else if (streamletPath) return convertor.from_bytes(std::string(streamletPath)); |
|
53 else return L""; |
49 } |
54 } |
50 |
|
51 protected: |
55 protected: |
52 |
56 |
53 void startFile(const fs::path& file, const string& fileRaw, bool exists) override { |
57 void startFile(const fs::path& file, const string& fileRaw, bool exists) override { |
54 AttributeFinder::startFile(file, fileRaw, exists); |
58 AttributeFinder::startFile(file, fileRaw, exists); |
55 if (exists) { |
59 if (exists) { |
84 |
88 |
85 if (cachedMetadata.count(field.id)) { |
89 if (cachedMetadata.count(field.id)) { |
86 return cachedMetadata[field.id]; |
90 return cachedMetadata[field.id]; |
87 } else { |
91 } else { |
88 |
92 |
89 std::vector<string_t> commandLine = {getExecCommand(field)}; |
93 std::vector<string_t> commandLine = {field.name}; |
90 std::map<string_t, string_t> environment; |
94 std::map<string_t, string_t> environment; |
91 |
95 |
92 for (auto mn : StreamletMsg::getMessageNames()) { |
96 for (auto mn : StreamletMsg::getMessageNames()) { |
93 environment[L"EXEC_MSG_" + mn.second] = std::to_wstring(mn.first); |
97 environment[L"EXEC_MSG_" + mn.second] = std::to_wstring(mn.first); |
94 environment[L"EXEC_MSG_" + std::to_wstring(mn.first)] = mn.second; |
98 environment[L"EXEC_MSG_" + std::to_wstring(mn.first)] = mn.second; |
95 } |
99 } |
|
100 |
|
101 environment[L"PATH"] = getStreamletPath(); |
96 |
102 |
97 shared_ptr<SubProcess> subProcess(SubProcess::create(commandLine, environment)); |
103 shared_ptr<SubProcess> subProcess(SubProcess::create(commandLine, environment)); |
98 subProcesses[field.id] = subProcess; |
104 subProcesses[field.id] = subProcess; |
99 |
105 |
100 string_t version = L"1"; |
106 string_t version = L"1"; |