23 #include "lighteningcastservice.h"
26 rtRemoteEnvironment* env;
27 pthread_t lcast_thread;
28 static GMainLoop *gLoop =
nullptr;
33 static gboolean pumpRemoteObjectQueue(gpointer data)
37 GSource *source = (GSource *)data;
39 g_source_set_ready_time(source, -1);
40 err = rtRemoteProcessSingleItem();
41 }
while (err == RT_OK);
42 if (err != RT_OK && err != RT_ERROR_QUEUE_EMPTY) {
44 return G_SOURCE_CONTINUE;
46 return G_SOURCE_CONTINUE;
49 static GSource *attachRtRemoteSource()
52 static GSourceFuncs g_sourceFuncs =
56 [](GSource *source, GSourceFunc callback, gpointer data) -> gboolean
58 if (g_source_get_ready_time(source) != -1) {
59 g_source_set_ready_time(source, -1);
60 return callback(data);
62 return G_SOURCE_CONTINUE;
68 GSource *source = g_source_new(&g_sourceFuncs,
sizeof(GSource));
69 g_source_set_name(source,
"RT Remote Event dispatcher");
70 g_source_set_can_recurse(source,
TRUE);
71 g_source_set_callback(source, pumpRemoteObjectQueue, source,
nullptr);
72 g_source_set_priority(source, G_PRIORITY_HIGH);
74 rtError e = rtRemoteRegisterQueueReadyHandler(env, [](
void *data) ->
void {
75 GSource *source = (GSource *)data;
76 g_source_set_ready_time(source, 0);
81 printf(
"Failed to register queue handler: %d", e);
82 g_source_destroy(source);
85 g_source_attach(source, NULL);
89 void * lcastPump(
void*) {
91 gLoop = g_main_loop_new( NULL , FALSE);
92 GSource *remoteSource = attachRtRemoteSource();
95 printf(
"Failed to attach rt remote source");
97 g_main_loop_run(gLoop);
98 g_source_unref(remoteSource);
102 printf(
"LighteningCastService Exit!!!\n");
103 g_main_loop_quit(gLoop);
104 pthread_join( lcast_thread, NULL );
105 rtError e = rtRemoteShutdown();
107 printf(
"rtRemoteShutdown failed: %s \n", rtStrError(e));
116 env = rtEnvironmentGetGlobal();
117 err = rtRemoteInit(env);
119 printf(
"LighteningCastService!!! Func: %s\n",__func__);
122 printf(
"rtRemoteinit Failed\n");
126 pthread_create(&lcast_thread, NULL, lcastPump, NULL);
128 objName = getenv(
"PX_WAYLAND_CLIENT_REMOTE_OBJECT_NAME");
129 if(!objName) objName =
"com.comcast.lighteningcast";
132 err = rtRemoteRegisterObject(env, objName, lCastObj);
134 printf(
"rtRemoteRegisterObject for %s failed! error:%s !\n", objName, rtStrError(err));
138 printf(
"LIGHTENINGCAST>>>>\n");
142 bool exit_lcast =
false;
145 printf(
"Select Options:\n");
146 printf(
"1) launch Application\n2) stop Application\n3) query Application status\n4) Exit\n");
148 scanf(
" %d",&options);
149 while(getchar() !=
'\n');
154 printf(
"\nLaunch Application\nApplication Name : ");
155 std::getline(std::cin,appName);
156 printf(
"Launch Params:\n");
157 std::getline(std::cin,args);
158 lCastObj->launchApplication(appName.c_str(),args.c_str());
162 printf(
"\nStop Application\nApplication Name : ");
163 std::getline(std::cin,appName);
164 lCastObj->stopApplication(appName.c_str(),NULL);
168 printf(
"\nQuery Application Status\nApplication Name : ");
169 std::getline(std::cin,appName);
170 lCastObj->getApplicationState(appName.c_str(),NULL);
180 printf(
"Invalid Option!!!\n");