TtlGenerator.cpp 1.96 KB
Newer Older
1
2
3
/**
 * @file TtlGenerator helper application, to genereate LV2 ttl files.
 */
4
5
#include "lv2_ttl_generation.hpp"
#include <fstream>
Benjamin Heisch's avatar
Benjamin Heisch committed
6
7
#include <interfaces/IPlugin.hpp>
#include <iostream>
8
#include <sstream>
Benjamin Heisch's avatar
Benjamin Heisch committed
9
10
#include <tools/LibLoading.hpp>
#include <tools/StringTools.hpp>
11

12
using namespace APAL;
13
/********FUNCTION VARIABLES*********/
14
15
16
17
18
19
20
21
22
23
24
25
std::string (*getTTLFromPluginPtr)(IPlugin*) = nullptr;
std::string (*getManifestFromMultpleInfosPtr)(std::vector<TTLPluginInfo>) =
  nullptr;
std::vector<TTLPluginInfo> (*getPluginInfosPtr)(const std::string&) = nullptr;
void
writeOutBundle(std::vector<TTLPluginInfo> infoArray,
               const std::string& fileOutDir = "./")
{
  for (auto info : infoArray) {
    auto plugTTL = getTTLFromPluginPtr(info.plugPtr);
    std::ofstream outfile(fileOutDir + info.ttlFileName);
    outfile << plugTTL;
Benjamin Heisch's avatar
Benjamin Heisch committed
26
    outfile.close();
27
28
29
30
31
  }
  auto manifestTTL = getManifestFromMultpleInfosPtr(infoArray);
  std::ofstream outfile(fileOutDir + "manifest.ttl");
  outfile << manifestTTL;
  outfile.close();
Benjamin Heisch's avatar
Benjamin Heisch committed
32
33
}

34
35
36
37
38
39
40
41
42
43
int
main(int argc, char* argv[])
{
  if (argc < 2) {
    std::cout << "Use: TTLGenerator bundlePath LV2LibPath";
    return 0;
  }

  /*********LOAD LIBRARY AND FUNCTIONS********/
  std::string pluginLib(argv[1]);
44
  APAL::replaceInString(pluginLib, "\\", "/");
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  auto pluginLibHandle = LoadLib(pluginLib.c_str());
  if (pluginLibHandle == nullptr) {
    std::cerr << GetErrorStr() << std::endl;
    return 1;
  }

  getTTLFromPluginPtr =
    LoadFunc<std::string (*)(IPlugin*)>(pluginLibHandle, "getTTLFromPlugin");
  getManifestFromMultpleInfosPtr =
    LoadFunc<std::string (*)(std::vector<TTLPluginInfo>)>(
      pluginLibHandle, "getManifestFromMultpleInfos");
  getPluginInfosPtr =
    LoadFunc<std::vector<TTLPluginInfo> (*)(const std::string&)>(
      pluginLibHandle, "getPluginInfos");

  /***************GET INFORMATIONS*****************/
  auto y = GetErrorStr();
  std::cout << y;
  auto infos = getPluginInfosPtr(getFileName(pluginLib, true));

  writeOutBundle(infos);
Benjamin Heisch's avatar
Benjamin Heisch committed
66
}