Skip to content

Commit

Permalink
Merge branch 'master' into development/refine-bluez-headers-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bramoosterhuis authored Sep 18, 2024
2 parents f18cef3 + 19dc04c commit 36143ff
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 139 deletions.
2 changes: 1 addition & 1 deletion Source/Thunder/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ namespace Plugin {
data.Interface = proxy->InterfaceId();
data.Count = proxy->ReferenceCount();
data.Name = proxy->Name();

elements.emplace_back(std::move(data));
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Thunder/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ POP_WARNING()

for (const ProxyStub::UnknownProxy* proxy : proxies) {
Core::instance_id instanceId = proxy->Implementation();
printf("[%s] InstanceId: 0x%" PRIx64 ", RefCount: %d, InterfaceId %d [0x%X]\n", proxy->Name(), static_cast<uint64_t>(instanceId), proxy->ReferenceCount(), proxy->InterfaceId(), proxy->InterfaceId());
printf("[%s] InstanceId: 0x%" PRIx64 ", RefCount: %d, InterfaceId %d [0x%X]\n", proxy->Name().c_str(), static_cast<uint64_t>(instanceId), proxy->ReferenceCount(), proxy->InterfaceId(), proxy->InterfaceId());
}
printf("\n");
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3726,6 +3726,9 @@ namespace PluginHost {
response->Message = _T("JSONRPC executed succesfully");
}
else {
#ifdef LEGACY_JSONRPCOVERHTTP_ERRORCODE
response->ErrorCode = Web::STATUS_ACCEPTED;
#endif
response->Message = _T("Failure on JSONRPC: ") + Core::NumberType<int32_t>(body->Error.Code).Text();
}
}
Expand Down
6 changes: 3 additions & 3 deletions Source/com/IUnknown.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace ProxyStub {
, _parent(parent)
, _channel(channel)
, _remoteReferences(1)
, _name(&(name[7])) /* It always starts with "struct ", remove it...*/
, _name(name)
{
}
virtual ~UnknownProxy() = default;
Expand Down Expand Up @@ -402,8 +402,8 @@ namespace ProxyStub {

return (result);
}
inline const char* Name() const {
return (_name);
inline string Name() const {
return Core::ClassName(_name).Text();
}

private:
Expand Down
97 changes: 72 additions & 25 deletions Source/core/Portability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,8 @@ void DumpCallStack(const ThreadId threadId VARIABLE_IS_NOT_USED, std::list<Thund
entry.line = ~0;
}
else {
char* demangled;
int status = -1;

demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);

if ( (demangled == nullptr) || (status != 0) || (demangled[0] == '\0') ) {
entry.function = string(info.dli_sname);
}
else {
entry.function = string(demangled);
}

entry.function = Core::ClassName(info.dli_sname).Text();
entry.line = (char*)callstack[i] - (char*)info.dli_saddr;

if (demangled != nullptr) {
free(demangled);
}
}
}

Expand All @@ -255,7 +240,10 @@ void DumpCallStack(const ThreadId threadId VARIABLE_IS_NOT_USED, std::list<Thund

#endif
}
}

} // extern c



#ifdef __LINUX__

Expand Down Expand Up @@ -295,14 +283,11 @@ void SleepUs(const unsigned int time) {

#if defined(__WINDOWS__)

void SleepUs(const uint32_t time) {
std::this_thread::sleep_for(std::chrono::microseconds(time));
}
void SleepUs(const uint32_t time) {
std::this_thread::sleep_for(std::chrono::microseconds(time));
}

#endif



#if !defined(__WINDOWS__) && !defined(__APPLE__)

uint64_t htonll(const uint64_t& value)
Expand Down Expand Up @@ -410,5 +395,67 @@ namespace Core {
{
toString(dst, format, ap);
}
}
}

TextFragment Demangled(const char name[]) {

#ifdef __LINUX__
int status;
char* temp = abi::__cxa_demangle(name, nullptr, nullptr, &status);
std::string newName;

// Check for, and deal with, error.
if (temp != nullptr) {
newName = temp;
::free(temp);
} else {
newName = name;
}
#endif

#ifdef __WINDOWS__
char allocationName[512];
size_t allocationSize = sizeof(allocationName) - 1;
uint16_t index = 0;
uint16_t moveTo = 0;
while ((name[index] != '\0') && (moveTo < (allocationSize - 1))) {
if ((name[index] == 'c') && (name[index + 1] == 'l') && (name[index + 2] == 'a') && (name[index + 3] == 's') && (name[index + 4] == 's') && (name[index + 5] == ' ')) {
// we need to skip class :-)
index += 6;
} else if ((name[index] == 's') && (name[index + 1] == 't') && (name[index + 2] == 'r') && (name[index + 3] == 'u') && (name[index + 4] == 'c') && (name[index + 5] == 't') && (name[index + 6] == ' ')) {
// We need to skip struct
index += 7;
} else if ((name[index] == 'e') && (name[index + 1] == 'n') && (name[index + 2] == 'u') && (name[index + 3] == 'm') && (name[index + 4] == ' ')) {
// We need to skip enum
index += 5;
} else {
allocationName[moveTo++] = name[index++];
}
}
allocationName[moveTo] = '\0';
std::string newName(allocationName, moveTo);
#endif

return (TextFragment(newName));
}

TextFragment ClassName(const char name[]) {
return(Demangled(name));
}

TextFragment ClassNameOnly(const char name[]) {

TextFragment result(Demangled(name));
uint16_t index = 0;
uint16_t lastIndex = static_cast<uint16_t>(~0);

while ((index < result.Length()) && (result[index] != '<')) {
if (result[index] == ':') {
lastIndex = index;
}
index++;
}

return (lastIndex < (index - 1) ? TextFragment(result, lastIndex + 1, result.Length() - (lastIndex + 1)) : result);
}
} // namespace Core
} // namespace Thunder
38 changes: 21 additions & 17 deletions Source/core/Portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ inline void SleepMs(const uint32_t time)
::Sleep(time);
}

EXTERNAL void SleepUs(const uint32_t time);
EXTERNAL extern void SleepUs(const uint32_t time);

#ifdef _UNICODE
typedef std::wstring string;
Expand Down Expand Up @@ -436,10 +436,10 @@ typedef std::string string;
#define SOCK_CLOEXEC 0
#define __APPLE_USE_RFC_3542

extern "C" EXTERNAL void* mremap(void* old_address, size_t old_size, size_t new_size, int flags);
extern "C" EXTERNAL extern void* mremap(void* old_address, size_t old_size, size_t new_size, int flags);
//clock_gettime is available in OSX Darwin >= 10.12
//int clock_gettime(int, struct timespec*);
extern "C" EXTERNAL uint64_t gettid();
extern "C" EXTERNAL extern uint64_t gettid();
#else
#include <linux/input.h>
#include <linux/types.h>
Expand Down Expand Up @@ -529,9 +529,9 @@ uint64_t ntohll(const uint64_t& value);

#define ALLOCA alloca

extern void EXTERNAL SleepMs(const unsigned int a_Time);
extern void EXTERNAL SleepUs(const unsigned int a_Time);
inline void EXTERNAL SleepS(unsigned int a_Time)
EXTERNAL extern void SleepMs(const unsigned int a_Time);
EXTERNAL extern void SleepUs(const unsigned int a_Time);
EXTERNAL inline void SleepS(unsigned int a_Time)
{
::SleepMs(a_Time * 1000);
}
Expand Down Expand Up @@ -619,12 +619,11 @@ struct TemplateIntToType {

extern "C" {

DEPRECATED inline EXTERNAL void* memrcpy(void* _Dst, const void* _Src, size_t _MaxCount)
DEPRECATED EXTERNAL inline void* memrcpy(void* _Dst, const void* _Src, size_t _MaxCount)
{
return (::memmove(_Dst, _Src, _MaxCount));
}


}

#define SLEEPSLOT_POLLING_TIME 100
Expand Down Expand Up @@ -696,9 +695,10 @@ typedef DWORD ThreadId;
#endif

namespace Thunder {

namespace Core {

class TextFragment;

#if defined(__CORE_INSTANCE_BITS__) && (__CORE_INSTANCE_BITS__ != 0)
#if __CORE_INSTANCE_BITS__ <= 8
typedef uint8_t instance_id;
Expand Down Expand Up @@ -780,9 +780,9 @@ namespace Core {
std::transform(inplace.begin(), inplace.end(), inplace.begin(), ::tolower);
}

string EXTERNAL Format(const TCHAR formatter[], ...) PRINTF_FORMAT(1, 2);
void EXTERNAL Format(string& dst, const TCHAR format[], ...) PRINTF_FORMAT(2, 3);
void EXTERNAL Format(string& dst, const TCHAR format[], va_list ap);
EXTERNAL extern string Format(const TCHAR formatter[], ...) PRINTF_FORMAT(1, 2);
EXTERNAL extern void Format(string& dst, const TCHAR format[], ...) PRINTF_FORMAT(2, 3);
EXTERNAL extern void Format(string& dst, const TCHAR format[], va_list ap);

const uint32_t infinite = -1;
static const string emptyString;
Expand Down Expand Up @@ -964,6 +964,11 @@ namespace Core {
}

#undef ERROR_CODE

EXTERNAL TextFragment Demangled(const char name[]);
EXTERNAL TextFragment ClassName(const char name[]);
EXTERNAL TextFragment ClassNameOnly(const char name[]);

}
}

Expand All @@ -981,13 +986,12 @@ namespace NESTED_NAMESPACE { \
extern "C" {

#ifdef __WINDOWS__
extern int EXTERNAL inet_aton(const char* cp, struct in_addr* inp);
extern void EXTERNAL usleep(const uint32_t value);
EXTERNAL extern int inet_aton(const char* cp, struct in_addr* inp);
EXTERNAL extern void usleep(const uint32_t value);
#endif

void EXTERNAL DumpCallStack(const ThreadId threadId, std::list<Thunder::Core::callstack_info>& stack);
uint32_t EXTERNAL GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t bufferSize);

EXTERNAL void DumpCallStack(const ThreadId threadId, std::list<Thunder::Core::callstack_info>& stack);
EXTERNAL uint32_t GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t bufferSize);
}


Expand Down
84 changes: 0 additions & 84 deletions Source/core/Trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,90 +28,6 @@

namespace Thunder {
namespace Core {
class Demangling {
public:
Demangling(const Demangling&) = delete;
Demangling& operator=(const Demangling&) = delete;

Demangling() = default;
~Demangling() = default;

inline TextFragment Demangled(const char name[])
{
char allocationName[512];
size_t allocationSize = sizeof(allocationName) - 1;

#ifdef __LINUX__
int status;
char* demangledName = abi::__cxa_demangle(name, allocationName, &allocationSize, &status);
std::string newName;

// Check for, and deal with, error.
if (demangledName == nullptr) {
newName = allocationName;
} else {
newName = demangledName;
}
#endif

#ifdef __WINDOWS__
uint16_t index = 0;
uint16_t moveTo = 0;
while ((name[index] != '\0') && (moveTo < (allocationSize - 1))) {
if ((name[index] == 'c') && (name[index + 1] == 'l') && (name[index + 2] == 'a') && (name[index + 3] == 's') && (name[index + 4] == 's') && (name[index + 5] == ' ')) {
// we need to skip class :-)
index += 6;
} else if ((name[index] == 's') && (name[index + 1] == 't') && (name[index + 2] == 'r') && (name[index + 3] == 'u') && (name[index + 4] == 'c') && (name[index + 5] == 't') && (name[index + 6] == ' ')) {
// We need to skip struct
index += 7;
} else if ((name[index] == 'e') && (name[index + 1] == 'n') && (name[index + 2] == 'u') && (name[index + 3] == 'm') && (name[index + 4] == ' ')) {
// We need to skip enum
index += 5;
} else {
allocationName[moveTo++] = name[index++];
}
}
allocationName[moveTo] = '\0';
std::string newName(allocationName, moveTo);
#endif

return (TextFragment(newName));
}

inline TextFragment ClassName(const char name[])
{
return(Demangled(name));
}

inline TextFragment ClassNameOnly(const char name[])
{
TextFragment result(Demangled(name));
uint16_t index = 0;
uint16_t lastIndex = static_cast<uint16_t>(~0);

while ((index < result.Length()) && (result[index] != '<')) {
if (result[index] == ':') {
lastIndex = index;
}
index++;
}

return (lastIndex < (index - 1) ? TextFragment(result, lastIndex + 1, result.Length() - (lastIndex + 1)) : result);
}

};

static Demangling demangleClassNames;

TextFragment ClassName(const char className[])
{
return (demangleClassNames.ClassName(className));
}

TextFragment ClassNameOnly(const char className[])
{
return (demangleClassNames.ClassNameOnly(className));
}

const char* FileNameOnly(const char fileName[])
{
Expand Down
4 changes: 0 additions & 4 deletions Source/core/Trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ namespace Thunder {

namespace Thunder {
namespace Core {
class TextFragment;

EXTERNAL TextFragment ClassName(const char className[]);
EXTERNAL TextFragment ClassNameOnly(const char className[]);
EXTERNAL const char* FileNameOnly(const char fileName[]);
EXTERNAL string LogMessage(const TCHAR filename[], const uint32_t LineNumber, const TCHAR* message);
}
Expand Down
6 changes: 3 additions & 3 deletions Source/plugins/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace PluginHost
string element;
while (all_paths->Next(element) == true) {
Core::File file(element.c_str());
if (file.Exists())
{
Core::Library resource(element.c_str());
if (file.Exists()) {

Core::Library resource = Core::ServiceAdministrator::Instance().LoadLibrary(element.c_str());
if (resource.IsLoaded())
result = Core::ServiceAdministrator::Instance().Instantiate(
resource,
Expand Down
Loading

0 comments on commit 36143ff

Please sign in to comment.