STREAMDEV: synchronize time with server patch (against CVS)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This patch enhances the streamdev plugin by adding client time 
synchronization. Time synchronization needs to be enabled on the client side 
under streamdev plugin setup. In such case, time synchronization will occur 
every channel request(switch).

Enjoy,

Alexw

------------------------------------------------------------------------
[4] streamdev (anoncvs@xxxxxxxxxxxxxxxxx:/var/cvsroot/)
? streamdev/.dependencies
Index: streamdev/client/device.c
===================================================================
RCS file: /var/cvsroot/streamdev/client/device.c,v
retrieving revision 1.8
diff -u -r1.8 device.c
--- streamdev/client/device.c	15 Jan 2007 12:15:12 -0000	1.8
+++ streamdev/client/device.c	2 Apr 2007 12:20:56 -0000
@@ -45,6 +45,9 @@
 
 	if (StreamdevClientSetup.SyncEPG)	
 		ClientSocket.SynchronizeEPG();
+
+	if (StreamdevClientSetup.SyncTime)	
+		ClientSocket.SynchronizeTime();
 }
 
 cStreamdevDevice::~cStreamdevDevice() {
Index: streamdev/client/menu.c
===================================================================
RCS file: /var/cvsroot/streamdev/client/menu.c,v
retrieving revision 1.4
diff -u -r1.4 menu.c
--- streamdev/client/menu.c	12 Mar 2005 12:54:19 -0000	1.4
+++ streamdev/client/menu.c	2 Apr 2007 12:20:56 -0000
@@ -29,6 +29,7 @@
 	Add(new cOsdItem(hk(tr("Remote Recordings")), (eOSState)subRecordings));
 	Add(new cOsdItem(hk(tr("Suspend Server")),    (eOSState)subSuspend));
 	Add(new cOsdItem(hk(tr("Synchronize EPG")),   (eOSState)subSyncEPG));
+	Add(new cOsdItem(hk(tr("Synchronize Time")),   (eOSState)subSyncTime));
 }
 
 cStreamdevMenu::~cStreamdevMenu() {
@@ -42,6 +43,7 @@
 	case subRecordings: return AddSubMenu(new cStreamdevMenuRecordings);
 	case subSuspend:    SuspendServer(); return osEnd;
 	case subSyncEPG:		ClientSocket.SynchronizeEPG(); return osEnd;
+	case subSyncTime:		ClientSocket.SynchronizeTime(); return osEnd;
 	default:            return state;
 	}
 }
Index: streamdev/client/menu.h
===================================================================
RCS file: /var/cvsroot/streamdev/client/menu.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 menu.h
--- streamdev/client/menu.h	30 Dec 2004 22:44:02 -0000	1.1.1.1
+++ streamdev/client/menu.h	2 Apr 2007 12:20:56 -0000
@@ -22,6 +22,7 @@
 		subRecordings,
 		subSuspend,
 		subSyncEPG
+		subSyncTime
 	};
 
 protected:
Index: streamdev/client/setup.c
===================================================================
RCS file: /var/cvsroot/streamdev/client/setup.c,v
retrieving revision 1.2
diff -u -r1.2 setup.c
--- streamdev/client/setup.c	8 Feb 2005 15:34:38 -0000	1.2
+++ streamdev/client/setup.c	2 Apr 2007 12:20:56 -0000
@@ -17,6 +17,7 @@
 	StreamFilters = false;
 #endif
 	SyncEPG       = false;
+	SyncTime      = false;
 	strcpy(RemoteIp, "");
 }
 
@@ -33,6 +34,7 @@
 	else if (strcmp(Name, "StreamFilters") == 0) StreamFilters = atoi(Value);
 #endif
 	else if (strcmp(Name, "SyncEPG") == 0)       SyncEPG = atoi(Value);
+	else if (strcmp(Name, "SyncTime") == 0)       SyncTime = atoi(Value);
 	else return false;
 	return true;
 }
@@ -47,6 +49,7 @@
 	AddBoolEdit (tr("Filter Streaming"),   m_NewSetup.StreamFilters);
 #endif
 	AddBoolEdit (tr("Synchronize EPG"),    m_NewSetup.SyncEPG);
+	AddBoolEdit (tr("Synchronize Time"),    m_NewSetup.SyncTime);
 	SetCurrent(Get(0));
 }
 
@@ -71,6 +74,7 @@
 	SetupStore("StreamFilters", m_NewSetup.StreamFilters);
 #endif
 	SetupStore("SyncEPG",       m_NewSetup.SyncEPG);
+	SetupStore("SyncTime",       m_NewSetup.SyncTime);
 
 	StreamdevClientSetup = m_NewSetup;
 
Index: streamdev/client/setup.h
===================================================================
RCS file: /var/cvsroot/streamdev/client/setup.h,v
retrieving revision 1.2
diff -u -r1.2 setup.h
--- streamdev/client/setup.h	8 Feb 2005 15:34:38 -0000	1.2
+++ streamdev/client/setup.h	2 Apr 2007 12:20:57 -0000
@@ -19,6 +19,7 @@
 	int  StreamFilters;
 #endif
 	int  SyncEPG;
+	int  SyncTime;
 };
 
 extern cStreamdevClientSetup StreamdevClientSetup;
Index: streamdev/client/socket.c
===================================================================
RCS file: /var/cvsroot/streamdev/client/socket.c,v
retrieving revision 1.7
diff -u -r1.7 socket.c
--- streamdev/client/socket.c	15 Jan 2007 11:45:48 -0000	1.7
+++ streamdev/client/socket.c	2 Apr 2007 12:20:57 -0000
@@ -585,3 +585,34 @@
 	}
 	return true;
 }
+
+bool cClientSocket::SynchronizeTime( void ) {
+
+        if (!CheckConnection()) return false;
+
+	isyslog("Streamdev: Synchronizing TIME from server\n");
+
+        CMD_LOCK;
+
+        if (!Command("TIME"))
+                return false;
+
+ 	time_t sattim;
+        bool res;
+        std::string buffer;
+        if (res = Expect(266, &buffer)) {
+          sattim = atoi(buffer.c_str() + 4);
+          isyslog("Setting System Time to %s (%ld)\n", *TimeToString(sattim), sattim);
+          if (stime(&sattim) < 0)
+             esyslog("ERROR while setting system time: %m");
+        }
+
+        if (!res && buffer.substr(0, 3) != "505") {
+                if (errno == 0)
+                        esyslog("ERROR: Streamdev: Couldn't fetch time info from %s:%d",
+                                        RemoteIp().c_str(), RemotePort());
+                return false;
+        }
+        return res;
+}
+
Index: streamdev/client/socket.h
===================================================================
RCS file: /var/cvsroot/streamdev/client/socket.h,v
retrieving revision 1.3
diff -u -r1.3 socket.h
--- streamdev/client/socket.h	8 Feb 2005 17:22:35 -0000	1.3
+++ streamdev/client/socket.h	2 Apr 2007 12:20:57 -0000
@@ -54,6 +54,7 @@
 #endif
 	bool CloseDvr(void);
 	bool SynchronizeEPG(void);
+        bool SynchronizeTime( void );
 	bool LoadRecordings(cRemoteRecordings &Recordings);
 	bool StartReplay(const char *Filename);
 	bool AbortReplay(void);
Index: streamdev/server/connectionVTP.c
===================================================================
RCS file: /var/cvsroot/streamdev/server/connectionVTP.c,v
retrieving revision 1.8
diff -u -r1.8 connectionVTP.c
--- streamdev/server/connectionVTP.c	2 Mar 2007 15:27:07 -0000	1.8
+++ streamdev/server/connectionVTP.c	2 Apr 2007 12:20:58 -0000
@@ -549,6 +549,8 @@
 	else if (strcasecmp(Cmd, "ADDF") == 0) return CmdADDF(param);
 	else if (strcasecmp(Cmd, "DELF") == 0) return CmdDELF(param);
 	else if (strcasecmp(Cmd, "ABRT") == 0) return CmdABRT(param);
+	// sync time
+	else if (strcasecmp(Cmd, "TIME") == 0) return CmdTIME(param);
 	else if (strcasecmp(Cmd, "QUIT") == 0) return CmdQUIT(param);
 	else if (strcasecmp(Cmd, "SUSP") == 0) return CmdSUSP(param);
 	// Commands adopted from SVDRP
@@ -988,3 +990,15 @@
 	                                  Code < 0 ? -Code : Code,
 									  Code < 0 ? '-' : ' ', buffer);
 }
+
+bool cConnectionVTP::CmdTIME(const char *Option)
+{
+  time_t loctim = time(NULL);
+  if ( true ) {
+//    return Respond(250, "System Time = %s (%ld)", *TimeToString(loctim), loctim);
+    return Respond(266, "%ld", loctim);
+  } else {
+    return Respond(505, "ERROR in show time");
+  }
+}
+
Index: streamdev/server/connectionVTP.h
===================================================================
RCS file: /var/cvsroot/streamdev/server/connectionVTP.h,v
retrieving revision 1.6
diff -u -r1.6 connectionVTP.h
--- streamdev/server/connectionVTP.h	2 Apr 2007 10:32:34 -0000	1.6
+++ streamdev/server/connectionVTP.h	2 Apr 2007 12:20:58 -0000
@@ -60,6 +60,7 @@
 	bool CmdLSTE(char *Opts);
 	bool CmdLSTC(char *Opts);
 	bool CmdLSTT(char *Opts);
+	bool CmdTIME(const char *Option);
 
 	// Commands adopted from SVDRP
 	bool CmdMODT(const char *Option);
_______________________________________________
linux-dvb mailing list
linux-dvb@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linux-dvb

[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux