Skip to content

Commit

Permalink
- Comply with widow monitor topology
Browse files Browse the repository at this point in the history
  • Loading branch information
JPersson77 committed Nov 2, 2022
1 parent 0302e58 commit b391ba0
Show file tree
Hide file tree
Showing 19 changed files with 967 additions and 91 deletions.
1 change: 1 addition & 0 deletions LGTV Companion Service/LGTV Companion Service.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>C:\Users\jorge\Programs\boost_1_75_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
56 changes: 53 additions & 3 deletions LGTV Companion Service/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ void InitDeviceSessions()
params.PowerOnTimeout = Prefs.PowerOnTimeout;

CSession S(&params);
S.DeviceID = params.DeviceId;
DeviceCtrlSessions.push_back(S);
Log(s.str());
}
Expand Down Expand Up @@ -981,7 +982,6 @@ void IPCThread(void)
SetSecurityDescriptorDacl(psd, TRUE, (PACL)NULL, FALSE);
SECURITY_ATTRIBUTES sa = { sizeof(sa), psd, FALSE };

// Log("Creating named pipe");
hPipe = CreateNamedPipe(PIPENAME,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, // FILE_FLAG_FIRST_PIPE_INSTANCE is not needed but forces CreateNamedPipe(..) to fail if the pipe already exists...
Expand All @@ -1002,7 +1002,7 @@ void IPCThread(void)
transform(t.begin(), t.end(), t.begin(), ::tolower);

vector <string> cmd = stringsplit(t, " ");
if (cmd.size() > 1)
if (cmd.size() > 0)
{
int param1 = 0;

Expand Down Expand Up @@ -1030,6 +1030,16 @@ void IPCThread(void)
param1 = APP_CMDLINE_SETHDMI3;
else if (param == "-sethdmi4")
param1 = APP_CMDLINE_SETHDMI4;
else if (param == "-clearlog")
{
string w = "IPC, clear log ";
wstring log = DataPath;
log += L"Log.txt";
w += narrow(log);
Log(w);
DeleteFile(log.c_str());
}

else if (param1 > 0)
{
if (param1 == APP_IPC_DAEMON)
Expand Down Expand Up @@ -1099,7 +1109,47 @@ void IPCThread(void)
Log("IPC, Remote session disconnected.");
}
}
else if (param == "topology")
{
param1 = APP_IPC_DAEMON_TOPOLOGY;
for (auto &d : DeviceCtrlSessions)
{
d.SetTopology(false);
}
}

}
else if (param1 == APP_IPC_DAEMON_TOPOLOGY)
{
if (param == "*")
{
//debuggy
stringstream s;
s << "IPC, windows monitor topology was changed.";
Log(s.str());
DispatchSystemPowerEvent(SYSTEM_EVENT_TOPOLOGY);
}
else
{
for (auto &d : DeviceCtrlSessions)
{
string id = d.DeviceID;
transform(id.begin(), id.end(), id.begin(), ::tolower);

if (param == id)
{
//debuggy
stringstream s;
s << "IPC, ";
s << d.DeviceID;
s << " - enabled in windows monitor topology.";
Log(s.str());
d.SetTopology(true);
}
}
}
}

else
{
for (auto& device : DeviceCtrlSessions)
Expand Down Expand Up @@ -1264,4 +1314,4 @@ vector <string> GetOwnIP(void)
}
}
return IPs;
}
}
13 changes: 11 additions & 2 deletions LGTV Companion Service/Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#pragma comment(lib, "Iphlpapi.lib")

#define APPNAME L"LGTV Companion"
#define APPVERSION L"1.7.0"
#define APPVERSION L"1.8.0"
#define SVCNAME L"LGTVsvc"
#define SVCDISPLAYNAME L"LGTV Companion Service"
#define SERVICE_PORT "3000"
Expand All @@ -53,6 +53,7 @@
#define JSON_IDLEBLANK "BlankWhenIdle"
#define JSON_IDLEBLANKDELAY "BlankWhenIdleDelay"
#define JSON_RDP_POWEROFF "PowerOffDuringRDP"
#define JSON_ADHERETOPOLOGY "AdhereDisplayTopology"

#define SERVICE_DEPENDENCIES L"Dhcp\0Dnscache\0LanmanServer\0\0"
#define SERVICE_ACCOUNT NULL //L"NT AUTHORITY\\LocalService"
Expand All @@ -77,6 +78,7 @@
#define SYSTEM_EVENT_FORCESETHDMI 15
#define SYSTEM_EVENT_BOOT 16
#define SYSTEM_EVENT_UNBLANK 17
#define SYSTEM_EVENT_TOPOLOGY 18

#define APP_CMDLINE_ON 1
#define APP_CMDLINE_OFF 2
Expand All @@ -89,6 +91,9 @@
#define APP_CMDLINE_SETHDMI2 9
#define APP_CMDLINE_SETHDMI3 10
#define APP_CMDLINE_SETHDMI4 11
#define APP_IPC_DAEMON_TOPOLOGY 12



#define WOL_NETWORKBROADCAST 1
#define WOL_IPSEND 2
Expand Down Expand Up @@ -146,11 +151,15 @@ class CSession {
void SystemEvent(DWORD, int param = 0);
SESSIONPARAMETERS GetParams();
bool IsBusy();
void SetTopology(bool);
std::string DeviceID;
private:
time_t ScreenDimmedRequestTime = 0;
bool ThreadedOpDisplayOn = false;
bool ThreadedOpDisplayOff = false;
bool ThreadedOpDisplaySetHdmiInput = false;
bool AdhereTopology = false;
bool TopologyEnabled = false;
time_t ThreadedOpDisplayOffTime = 0;
void TurnOnDisplay(bool SendWOL);
void TurnOffDisplay(bool forced, bool dimmed, bool blankscreen);
Expand Down Expand Up @@ -183,4 +192,4 @@ void SetDisplayHdmiInputThread(SESSIONPARAMETERS*, bool*, int, int);
void IPCThread(void);
void WOLthread(SESSIONPARAMETERS*, bool*, int);
std::vector<std::string> stringsplit(std::string str, std::string token);
std::vector<std::string> GetOwnIP(void);
std::vector<std::string> GetOwnIP(void);
80 changes: 67 additions & 13 deletions LGTV Companion Service/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ namespace {
MIB_IPNET_ROW2 row;
row.InterfaceLuid = luid;
row.Address = address;

std::stringstream log;
log << "DeleteIpNetEntry2() = " << DeleteIpNetEntry2(&row);
Log(log.str());
DeleteIpNetEntry2(&row);
}

private:
Expand All @@ -43,7 +40,6 @@ namespace {
log << "GetBestRoute2()";

if (result != NO_ERROR) {
std::stringstream log;
log << " failed with code " << result;
Log(log.str());
return boost::none;
Expand Down Expand Up @@ -72,9 +68,9 @@ namespace {
row.PhysicalAddressLength = sizeof(macAddress);
const auto result = CreateIpNetEntry2(&row);

std::stringstream log;
log << "CreateIpNetEntry2() = " << result;
Log(log.str());
// std::stringstream log;
// log << "CreateIpNetEntry2() = " << result;
// Log(log.str());

if (result != NO_ERROR) return nullptr;
return std::make_unique<NetEntryDeleter>(*luid, destination);
Expand Down Expand Up @@ -124,6 +120,16 @@ bool CSession::IsBusy(void)
mMutex.unlock();
return ret;
}
void CSession::SetTopology(bool bEnabled)
{
//thread safe section
while (!mMutex.try_lock())
Sleep(MUTEX_WAIT);
TopologyEnabled = bEnabled;
AdhereTopology = true;
mMutex.unlock();
return;
}
void CSession::SetDisplayHdmiInput(int HdmiInput)
{
string s;
Expand Down Expand Up @@ -262,12 +268,26 @@ void CSession::SystemEvent(DWORD dwMsg, int param)
case SYSTEM_EVENT_RESUMEAUTO:
{
if (Parameters.SetHDMIInputOnResume)
SetDisplayHdmiInput(Parameters.SetHDMIInputOnResumeToNumber);
{
if (AdhereTopology)
{
if (TopologyEnabled)
SetDisplayHdmiInput(Parameters.SetHDMIInputOnResumeToNumber);
}
else
SetDisplayHdmiInput(Parameters.SetHDMIInputOnResumeToNumber);
}
}break;

case SYSTEM_EVENT_DISPLAYON:
{
TurnOnDisplay(true);
if (AdhereTopology)
{
if (TopologyEnabled)
TurnOnDisplay(true);
}
else
TurnOnDisplay(true);
}break;
case SYSTEM_EVENT_DISPLAYOFF:
{
Expand All @@ -280,22 +300,56 @@ void CSession::SystemEvent(DWORD dwMsg, int param)
case SYSTEM_EVENT_USERIDLE:
{
if (Parameters.BlankWhenIdle)
TurnOffDisplay(false, false, true);
{
if (AdhereTopology)
{
if (TopologyEnabled)
TurnOffDisplay(false, false, true);
}
else
TurnOffDisplay(false, false, true);
}
}break;
case SYSTEM_EVENT_USERBUSY:
{
if (Parameters.BlankWhenIdle)
TurnOnDisplay(true);
{
if (AdhereTopology)
{
if (TopologyEnabled)
TurnOnDisplay(true);
}
else
TurnOnDisplay(true);
}
}break;
case SYSTEM_EVENT_BOOT:
{
if (Parameters.SetHDMIInputOnResume)
SetDisplayHdmiInput(Parameters.SetHDMIInputOnResumeToNumber);
{
if (AdhereTopology)
{
if(TopologyEnabled)
SetDisplayHdmiInput(Parameters.SetHDMIInputOnResumeToNumber);
}
else
SetDisplayHdmiInput(Parameters.SetHDMIInputOnResumeToNumber);
}
}break;
case SYSTEM_EVENT_UNBLANK:
{
TurnOnDisplay(false);
}break;
case SYSTEM_EVENT_TOPOLOGY:
{
if (AdhereTopology)
{
if (TopologyEnabled)
TurnOnDisplay(true);
else
TurnOffDisplay(false, false, false);
}
}break;
default:break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion LGTV Companion Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?define LGTV Companion Service_TargetDir=$(var.LGTV Companion Service.TargetDir)?><?define LGTV Companion UI_TargetDir=$(var.LGTV Companion UI.TargetDir)?>
<Product Id="9AD205C9-ACBF-4A46-9D1F-80A95DF34F2B" Name="LGTV Companion" Language="1033" Version="1.7.0" Manufacturer="J Persson" UpgradeCode="0BA17E5B-11CE-491D-B1A1-05DD2D9F610A">
<Product Id="CA079CDC-154D-40AF-8837-E91811F887A5" Name="LGTV Companion" Language="1033" Version="1.8.0" Manufacturer="J Persson" UpgradeCode="0BA17E5B-11CE-491D-B1A1-05DD2D9F610A">
<Package Id="*" InstallerVersion="301" Compressed="yes" InstallScope="perMachine" Platform='x64' Description="LGTV Companion installer" InstallPrivileges="elevated" AdminImage="yes"/>
<Media Id="1" Cabinet="LGTVapp.cab" EmbedCab="yes" />

Expand Down
Loading

0 comments on commit b391ba0

Please sign in to comment.