You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bluesky-commits@incubator.apache.org by pi...@apache.org on 2009/11/30 12:18:38 UTC
svn commit: r885395 [23/23] - in /incubator/bluesky/trunk/RealClass/Student:
./ autom4te.cache/ src/ src/.deps/ src/pic/
Added: incubator/bluesky/trunk/RealClass/Student/src/tcpcomm.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Student/src/tcpcomm.h?rev=885395&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Student/src/tcpcomm.h (added)
+++ incubator/bluesky/trunk/RealClass/Student/src/tcpcomm.h Mon Nov 30 12:18:34 2009
@@ -0,0 +1,58 @@
+/** \file tcpcomm.h interface for the CTCPComm class.
+* handle tcp communication
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+#if !defined(TCPCOMM_H)
+#define TCPCOMM_H
+
+class CTCPPollThread;
+//!TCP communication
+class CTCPComm
+{
+ friend class CTCPPollThread;
+public:
+ //!Constructor
+ CTCPComm();
+ //!Destructor
+ virtual ~CTCPComm();
+ //!stop communication thread
+ void Stop();
+ //!check the status of poll whether it is running
+ bool IsPolling();
+ //!start tcp communication
+ int Start();
+ //!initialize tcp communication
+ virtual bool Init();
+
+
+protected:
+ //!time steps of polling
+ virtual void OnPollThreadStep() = 0;
+ //!if poll thread error return -1
+ virtual int OnPollThreadError(int status);
+ //!poll socket , return the status of socket
+ virtual int PolledSocket() = 0;
+ virtual int Poll() = 0;
+
+private:
+ CTCPPollThread *m_pThread;
+};
+
+#endif // !defined(TCPCOMM_H)
Added: incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.cpp?rev=885395&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.cpp (added)
+++ incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.cpp Mon Nov 30 12:18:34 2009
@@ -0,0 +1,103 @@
+/** \file tcppollthread.cpp implementation of CTCPPollThread class
+*
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+#include "tcppollthread.h"
+#include "tcpcomm.h"
+
+CTCPPollThread::CTCPPollThread(CTCPComm* pcomm)
+{
+ m_pcomm = pcomm;
+ stop = false;
+}
+
+CTCPPollThread::~CTCPPollThread()
+{
+ Stop();
+}
+
+int CTCPPollThread::Start()
+{
+ if (JThread::IsRunning())
+ return -1;
+
+ if (!stopmutex.IsInitialized())
+ {
+ if (stopmutex.Init() < 0)
+ return -1;
+ }
+ stop = false;
+ if (JThread::Start() < 0)
+ return -1;
+ return 0;
+}
+
+void CTCPPollThread::Stop()
+{
+ if (!IsRunning())
+ return;
+
+ stopmutex.Lock();
+ stop = true;
+ stopmutex.Unlock();
+
+ if (JThread::IsRunning())
+ {
+ JThread::Kill();
+ }
+ stop = false;
+}
+
+void *CTCPPollThread::Thread()
+{
+ JThread::ThreadStarted();
+
+ int status;
+ bool stopthread;
+
+ stopmutex.Lock();
+ stopthread = stop;
+ stopmutex.Unlock();
+ while (!stopthread)
+ {
+ status = m_pcomm->Poll();
+ if (status < 0)
+ {
+ stopthread = 0;
+ m_pcomm->OnPollThreadError(status);
+ }
+ else
+ {
+ status = m_pcomm->PolledSocket();
+ if (status < 0)
+ {
+ stopthread = true;
+ m_pcomm->OnPollThreadError(status);
+ }
+ else
+ {
+ m_pcomm->OnPollThreadStep();
+ stopmutex.Lock();
+ stopthread = stop;
+ stopmutex.Unlock();
+ }
+ }
+ }
+ return 0;
+}
Added: incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.h?rev=885395&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.h (added)
+++ incubator/bluesky/trunk/RealClass/Student/src/tcppollthread.h Mon Nov 30 12:18:34 2009
@@ -0,0 +1,56 @@
+/** \file tcppollthread.h define CTCPPollThread class
+*
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+#ifndef CTCPPOLLTHREAD_H
+
+#define CTCPPOLLTHREAD_H
+
+#include "jthread.h"
+#include "jmutex.h"
+
+class CTCPComm;
+
+class CTCPPollThread: private JThread
+{
+ friend class CTCPComm;
+public:
+ //!Constructor
+ /*!
+ \param pcomm create poll thread
+ */
+ CTCPPollThread(CTCPComm* pcomm);
+ //!Destructor
+ ~CTCPPollThread();
+ //!poll thread start
+ int Start();
+ //!poll thread stop
+ void Stop();
+private:
+ //!from JThread, start thread
+ void *Thread();
+ //! flag of stop
+ bool stop;
+ //! thread stop mutex
+ JMutex stopmutex;
+ //! tcp communication
+ CTCPComm *m_pcomm;
+};
+
+#endif // CTCPPOLLTHREAD_H
Added: incubator/bluesky/trunk/RealClass/Student/stamp-h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Student/stamp-h?rev=885395&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Student/stamp-h (added)
+++ incubator/bluesky/trunk/RealClass/Student/stamp-h Mon Nov 30 12:18:34 2009
@@ -0,0 +1 @@
+timestamp