Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6bd1ad9a138a
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4ad046374b1b
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 20, 2020

  1. Copy the full SHA
    c31ff30 View commit details
  2. Copy the full SHA
    4ad0463 View commit details
Showing with 63 additions and 4 deletions.
  1. +1 −1 scopehal/ProtocolDecoder.cpp
  2. +3 −1 scopehal/ProtocolDecoder.h
  3. +57 −0 scopehal/scopehal.cpp
  4. +2 −0 scopehal/scopehal.h
  5. +0 −2 scopeprotocols/scopeprotocols.cpp
2 changes: 1 addition & 1 deletion scopehal/ProtocolDecoder.cpp
Original file line number Diff line number Diff line change
@@ -318,7 +318,7 @@ void ProtocolDecoder::RefreshIfDirty()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Enumeration

void ProtocolDecoder::AddDecoderClass(string name, CreateProcType proc)
void ProtocolDecoder::DoAddDecoderClass(string name, CreateProcType proc)
{
m_createprocs[name] = proc;
}
4 changes: 3 additions & 1 deletion scopehal/ProtocolDecoder.h
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ class ProtocolDecoder : public OscilloscopeChannel

public:
typedef ProtocolDecoder* (*CreateProcType)(std::string);
static void AddDecoderClass(std::string name, CreateProcType proc);
static void DoAddDecoderClass(std::string name, CreateProcType proc);

static void EnumProtocols(std::vector<std::string>& names);
static ProtocolDecoder* CreateDecoder(std::string protocol, std::string color);
@@ -207,4 +207,6 @@ class ProtocolDecoder : public OscilloscopeChannel
virtual std::string GetProtocolDisplayName() \
{ return GetProtocolName(); }

#define AddDecoderClass(T) ProtocolDecoder::DoAddDecoderClass(T::GetProtocolName(), T::CreateInstance)

#endif
57 changes: 57 additions & 0 deletions scopehal/scopehal.cpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@
#include "RigolOscilloscope.h"
#include "RohdeSchwarzOscilloscope.h"
#include "SiglentSCPIOscilloscope.h"
#include <libgen.h>
#include <dlfcn.h>

using namespace std;

@@ -97,3 +99,58 @@ uint64_t ConvertVectorSignalToScalar(vector<bool> bits)
rval = (rval << 1) | b;
return rval;
}

/**
@brief Initialize all plugins
*/
void InitializePlugins()
{
char tmp[1024];
vector<string> search_dirs;
search_dirs.push_back("/usr/lib/scopehal/plugins/");
search_dirs.push_back("/usr/local/lib/scopehal/plugins/");

//current binary dir
char selfPath[1024] = {0};
ssize_t readlinkReturn = readlink("/proc/self/exe", selfPath, (sizeof(selfPath) - 1) );
if ( readlinkReturn > 0)
search_dirs.push_back(dirname(selfPath));

//Home directory
snprintf(tmp, sizeof(tmp), "%s/.scopehal/plugins", getenv("HOME"));
search_dirs.push_back(tmp);

for(auto dir : search_dirs)
{
DIR* hdir = opendir(dir.c_str());
if(!hdir)
continue;

dirent* pent;
while((pent = readdir(hdir)))
{
//Don't load hidden files or parent directory entries
if(pent->d_name[0] == '.')
continue;

//Try loading it and see if it works.
//(for now, never unload the plugins)
string fname = dir + "/" + pent->d_name;
void* hlib = dlopen(fname.c_str(), RTLD_NOW);
if(hlib == NULL)
continue;

//If loaded, look for PluginInit()
typedef void (*PluginInit)();
PluginInit init = (PluginInit)dlsym(hlib, "PluginInit");
if(!init)
continue;

//If found, it's a valid plugin
LogDebug("Loading plugin %s\n", fname.c_str());
init();
}

closedir(hdir);
}
}
2 changes: 2 additions & 0 deletions scopehal/scopehal.h
Original file line number Diff line number Diff line change
@@ -75,4 +75,6 @@ std::string GetDefaultChannelColor(int i);
void TransportStaticInit();
void DriverStaticInit();

void InitializePlugins();

#endif
2 changes: 0 additions & 2 deletions scopeprotocols/scopeprotocols.cpp
Original file line number Diff line number Diff line change
@@ -35,8 +35,6 @@

#include "scopeprotocols.h"

#define AddDecoderClass(T) ProtocolDecoder::AddDecoderClass(T::GetProtocolName(), T::CreateInstance)

/**
@brief Static initialization for protocol list
*/