Author: derek
Date: Sun Nov 5 21:08:36 2006
New Revision: 155
Modified:
sofaswitch/trunk/mcu/audio.cxx
sofaswitch/trunk/mcu/comms.cxx
sofaswitch/trunk/mcu/manager.cxx
sofaswitch/trunk/mcu/manager.h
sofaswitch/trunk/mcu/member.cxx
sofaswitch/trunk/mcu/member.h
sofaswitch/trunk/mcu/participant.cxx
sofaswitch/trunk/mcu/participant.h
Log:
Big tidyup.
Remove the use of PSafePtr structures in a class decleration.
Use SafeReference and SafeDereference to keep the pointers good.
Move activeMembers and activeRooms to be public components of the manager.
Modified: sofaswitch/trunk/mcu/audio.cxx
==============================================================================
--- sofaswitch/trunk/mcu/audio.cxx (original)
+++ sofaswitch/trunk/mcu/audio.cxx Sun Nov 5 21:08:36 2006
@@ -61,8 +61,8 @@
PString name = "Reader " + memberId;
PThread::Current()->SetThreadName(name);
- PSafePtr <Member> member = manager->GetMember(memberId);
-
+ PSafePtr <Member> member = manager->activeMembers.FindWithLock(memberId, PSafeReadOnly);
+
PINDEX readSize = 480;
PBYTEArray data;
data.SetSize(readSize);
@@ -111,7 +111,7 @@
PString name = "Writer " + memberId;
PThread::Current()->SetThreadName(name);
- PSafePtr <Member> member = manager->GetMember(memberId);
+ PSafePtr <Member> member = manager->activeMembers.FindWithLock(memberId, PSafeReadOnly);
PINDEX maxSize = 480;
PBYTEArray data;
Modified: sofaswitch/trunk/mcu/comms.cxx
==============================================================================
--- sofaswitch/trunk/mcu/comms.cxx (original)
+++ sofaswitch/trunk/mcu/comms.cxx Sun Nov 5 21:08:36 2006
@@ -147,7 +147,7 @@
void Comms::ProcessStatusQuery(PStringArray &cmds, PString & sender)
{
PTRACE(3, "Coms::ProcessStatusQuery");
- PSafePtr <Member> member = manager.GetMember(GetOurId());
+ PSafePtr <Member> member = manager.activeMembers.FindWithLock(GetOurId(), PSafeReadOnly);;
if (member != NULL) {
PString message = PString("In conference room \"") + member->GetRoomId() + "\"";
SendThisMessageTo(message, sender);
@@ -174,7 +174,7 @@
PString Comms::GetConferenceParticipants()
{
- PSafePtr <Member> member = manager.GetMember(GetOurId());
+ PSafePtr <Member> member = manager.activeMembers.FindWithLock(GetOurId(), PSafeReadOnly);
if (member == NULL)
return " No participant information available";
@@ -187,7 +187,7 @@
return "waiting to connect to Sofa Switch entity";
}
- PSafePtr <Member> member = manager.GetMember(GetOurId());
+ PSafePtr <Member> member = manager.activeMembers.FindWithLock(GetOurId(), PSafeReadOnly);
if (member == NULL)
return " No duration information available";
Modified: sofaswitch/trunk/mcu/manager.cxx
==============================================================================
--- sofaswitch/trunk/mcu/manager.cxx (original)
+++ sofaswitch/trunk/mcu/manager.cxx Sun Nov 5 21:08:36 2006
@@ -320,20 +320,6 @@
}
-
-PSafePtr<ConferenceRoom> Manager::GetConferenceRoom(PString roomId)
-{
- PSafePtr<ConferenceRoom> room = activeRooms.FindWithLock(roomId, PSafeReadOnly);
- return room;
-}
-
-PSafePtr<Member> Manager::GetMember(PString memberId)
-{
- PSafePtr <Member> mem= activeMembers.FindWithLock(memberId, PSafeReadOnly);
- return mem;
-}
-
-
void Manager::RemoveAllCalls()
{
PTRACE(3, "Remove All callls from the manager, close running comms down");
Modified: sofaswitch/trunk/mcu/manager.h
==============================================================================
--- sofaswitch/trunk/mcu/manager.h (original)
+++ sofaswitch/trunk/mcu/manager.h Sun Nov 5 21:08:36 2006
@@ -128,12 +128,6 @@
/**Wait until the supervisor has finished */
void WaitForSupervisorEnd();
- /**get a safe ptr to the conference room matching a particular ID */
- PSafePtr<ConferenceRoom> GetConferenceRoom(PString roomId);
-
- /**Get one element from the list of members */
- PSafePtr<Member> GetMember(PString memberId);
-
/**Get the status on all conferences, or just one conference */
PString ProcessStatusQuery(PStringArray & cmds);
@@ -159,7 +153,23 @@
/**Callback for removing a connection from the list of active
connections */
void OnReleased(const PString & memberId);
+
+ /**List of available members in the system, which is all calls +
+ file members */
+ MemberDict activeMembers;
+
+ /**The thread safe list of conference rooms that we manage */
+ class ConferenceRoomDict : public PSafeDictionary<PString, ConferenceRoom>
+ {
+ /**One function that we have to define for this usage, and that
+ is the deletion of existing methods. PWLib will have removed
+ the object to be deleted from the list. We simply need to
+ delete it. */
+ virtual void DeleteObject(PObject * object) const;
+ } activeRooms;
+
+
protected:
/**Go through the list of active calls, and tell them to "die now" */
@@ -198,21 +208,6 @@
/**Sync point that can be called to end the whole thing */
PSyncPoint syncPoint;
-
-
- /**The thread safe list of conference rooms that we manage */
- class ConferenceRoomDict : public PSafeDictionary<PString, ConferenceRoom>
- {
- /**One function that we have to define for this usage, and that
- is the deletion of existing methods. PWLib will have removed
- the object to be deleted from the list. We simply need to
- delete it. */
- virtual void DeleteObject(PObject * object) const;
- } activeRooms;
-
- /**List of available members in the system, which is all calls +
- file members */
- MemberDict activeMembers;
/**The list of initialised, ready to go, Comms instances */
CommsProvider *runningComms;
Modified: sofaswitch/trunk/mcu/member.cxx
==============================================================================
--- sofaswitch/trunk/mcu/member.cxx (original)
+++ sofaswitch/trunk/mcu/member.cxx Sun Nov 5 21:08:36 2006
@@ -99,8 +99,10 @@
buffer = NULL;
}
}
+
DecCountMembers();
}
+
void Member::PrintOn(ostream & strm /// Stream to output text representation
) const
@@ -148,7 +150,7 @@
PTRACE(3, "START Tell conference room \"" << roomId
<< "\" to remove me (" << memberId << ")");
{
- PSafePtr <ConferenceRoom> conferenceRoom = manager.GetConferenceRoom(roomId);
+ PSafePtr <ConferenceRoom> conferenceRoom = manager.activeRooms.FindWithLock(roomId, PSafeReadOnly);
if (conferenceRoom != NULL) {
conferenceRoom->RemoveMember(memberId);
} else {
@@ -291,7 +293,7 @@
PTRACE(3, "OnRelease thread started for " << *this);
{
- PSafePtr <ConferenceRoom> conferenceRoom = manager.GetConferenceRoom(roomId);
+ PSafePtr <ConferenceRoom> conferenceRoom = manager.activeRooms.FindWithLock(roomId, PSafeReadOnly);
if (conferenceRoom != NULL) {
conferenceRoom->RemoveMember(memberId);
} else {
@@ -378,19 +380,19 @@
SetThreadName(PString("FillMemberList ") + targetMemberId);
PTRACE(3, "Append Start " << *this);
- PSafePtr <Member> targetMember = manager.GetMember(targetMemberId);
+ PSafePtr <Member> targetMember = manager.activeMembers.FindWithLock(targetMemberId, PSafeReadOnly);
if (targetMember == NULL)
return;
for(PINDEX i = 0; i < membersToAdd.GetSize(); i++) {
- PSafePtr <Member> otherMember = manager.GetMember(membersToAdd[i]);
- if ((otherMember != NULL) && (otherMember->GetMemberId() != targetMember->GetMemberId())) {
- targetMember->AddMemberToRoom(membersToAdd[i]);
- otherMember->AddMemberToRoom(targetMemberId);
- }
+ PSafePtr <Member> otherMember = manager.activeMembers.FindWithLock(membersToAdd[i] , PSafeReadOnly);
+ if ((otherMember != NULL) && (otherMember->GetMemberId() != targetMember->GetMemberId())) {
+ targetMember->AddMemberToRoom(membersToAdd[i]);
+ otherMember->AddMemberToRoom(targetMemberId);
+ }
}
-
+
PTRACE(3, "Append Done " << *this);
}
Modified: sofaswitch/trunk/mcu/member.h
==============================================================================
--- sofaswitch/trunk/mcu/member.h (original)
+++ sofaswitch/trunk/mcu/member.h Sun Nov 5 21:08:36 2006
@@ -223,6 +223,9 @@
/**Flag to indicate we are being cleared, or have been cleared */
BOOL isClearing;
+
+
+
};
Modified: sofaswitch/trunk/mcu/participant.cxx
==============================================================================
--- sofaswitch/trunk/mcu/participant.cxx (original)
+++ sofaswitch/trunk/mcu/participant.cxx Sun Nov 5 21:08:36 2006
@@ -40,18 +40,23 @@
////////////////////////////////////////////////////////////////////////////////
Participant::Participant(Manager & _mgr, ParticipantDict & _partyDict,
- const PString &baseMemberId,
- PSafePtr <Member> member)
+ const PString &_srcMemberId,
+ const PString &_dstMemberId)
: manager(_mgr),
dictionary(_partyDict),
- srcMemberId(baseMemberId)
+ srcMemberId(_srcMemberId),
+ dstMemberId(_dstMemberId)
{
- dstMemberId = member->GetMemberId();
SetKey (srcMemberId + PString("-->") + dstMemberId);
SetMatchingKey(dstMemberId + PString("-->") + srcMemberId);
isClearing = FALSE;
- memberPtr = member;
+ srcMemberPtr = manager.activeMembers.FindWithLock(srcMemberId, PSafeReadOnly);
+ srcMemberPtr->SafeReference();
+ dstMemberPtr = manager.activeMembers.FindWithLock(dstMemberId, PSafeReadOnly);
+ dstMemberPtr->SafeReference();
+
+
PTRACE(3, "Participant\tConstructor " << *this);
currentReadIndex = 0;
IncCountParticipants();
@@ -63,6 +68,8 @@
DecCountParticipants();
PTRACE(3, "Participant " << *this << " destroyed dead and gone");
+ srcMemberPtr->SafeDereference();
+ dstMemberPtr->SafeDereference();
dictionary.ParticipantDestroyed();
}
@@ -72,14 +79,9 @@
strm << "(" << GetKey() << ")";
}
-PString Participant::GetMemberId()
-{
- return srcMemberId;
-}
-
BOOL Participant::ReadAndMixAudio(BYTE * data, PINDEX amount)
{
- return memberPtr->ReadAndMixAudio(data, amount, currentReadIndex);
+ return dstMemberPtr->ReadAndMixAudio(data, amount, currentReadIndex);
}
void Participant::OnReleased()
@@ -90,13 +92,14 @@
void Participant::Clear()
{
- PTRACE(3, *this << " has been told to CLEAR");
{
PWaitAndSignal m(clearMutex);
if (isClearing)
return;
isClearing = TRUE;
}
+ PTRACE(3, *this << " commence CLEAR now");
+
// Add a reference for the thread we are about to start
SafeReference();
PString clearName = PString("OnRelease ") + GetKey();
@@ -122,7 +125,7 @@
void Participant::DestroyNeighboursLink()
{
- new MatchingParticipantConsumer(manager, dstMemberId, GetMatchingKey());
+ dstMemberPtr->DestroyThisParticipant(matchingKey);
}
@@ -176,8 +179,12 @@
void ParticipantDict::WaitForTotallyEmpty()
{
+ int loops = 0;
while (countEntries > 0) {
- PThread::Sleep(500);
+ loops++;
+ PThread::Sleep(300);
+ if ((loops % 6) == 0)
+ EmptyParticipantDict(TRUE);
}
}
@@ -193,7 +200,7 @@
PSortedStringList res;
for (PSafePtr<Participant> participant(*this, PSafeReadOnly);
participant != NULL; ++participant)
- res.AppendString(participant->GetMemberId());
+ res.AppendString(participant->GetDstMemberId());
return res;
}
@@ -217,20 +224,20 @@
return;
}
- PSafePtr <Member> dstMemberPtr = mgr.GetMember(dstMember);
+ PSafePtr <Member> dstMemberPtr = mgr.activeMembers.FindWithLock(dstMember, PSafeReadOnly);
if (dstMemberPtr != NULL) {
- PSafePtr <Participant> participant = new Participant(mgr, *this, srcMember, dstMemberPtr);
+ PSafePtr <Participant> participant = new Participant(mgr, *this, srcMember, dstMember);
SetAt(participant->GetKey(), participant);
PTRACE(3, "Done add new participant of " << participant->GetKey());
}
}
-void ParticipantDict::EmptyParticipantDict()
+void ParticipantDict::EmptyParticipantDict(BOOL doForce)
{
{
PWaitAndSignal m(addNewParticipantMutex);
- if (shuttingDown)
+ if (shuttingDown && (!doForce))
return;
shuttingDown = TRUE;
}
@@ -261,34 +268,3 @@
RemoveAt(partKey);
}
}
-
-/////////////////////////////////////////////////////////////////////////////
-
-
-MatchingParticipantConsumer::MatchingParticipantConsumer(Manager & _mgr,
- const PString & _otherMember,
- const PString & _partyKey)
- :PThread(10000, AutoDeleteThread, LowPriority, "%X participantdelete"),
- mgr(_mgr),
- otherMember(_otherMember),
- partyKey(_partyKey)
-{
- PTRACE(3, "ParticipantConsumer contructor " << partyKey);
- Resume();
-}
-
-MatchingParticipantConsumer::~MatchingParticipantConsumer()
-{
- PTRACE(3, "ParticipantConsumer destructor " << partyKey);
-}
-
-void MatchingParticipantConsumer::Main()
-{
- PSafePtr <Member> member = mgr.GetMember(otherMember);
-
- if (member == NULL)
- return;
-
- member->DestroyThisParticipant(partyKey);
-}
-
Modified: sofaswitch/trunk/mcu/participant.h
==============================================================================
--- sofaswitch/trunk/mcu/participant.h (original)
+++ sofaswitch/trunk/mcu/participant.h Sun Nov 5 21:08:36 2006
@@ -102,9 +102,12 @@
Note, if there is one member in a conference, and only one Member,
there will be no participants in this dictionary. The reason is that
a Participant links from one Member to another Member.
+
+ The argument, doForce is turned on only for desperate times, when the
+ dictionary does not appear to be shutting down on its own accord.
*/
- void EmptyParticipantDict();
+ void EmptyParticipantDict(BOOL doForce = FALSE);
/**Wait for this class to go totally empty, with zero entries in it. */
void WaitForTotallyEmpty();
@@ -150,6 +153,8 @@
PDECLARE_NOTIFIER(PThread, ParticipantDict, GarbageMain);
#endif
+
+
private:
/**Count of the additions/deleteions to this class */
PAtomicInteger countEntries;
@@ -186,8 +191,8 @@
and knows the conference we are a part of */
Participant(Manager & _mgr,
ParticipantDict & partDict,
- const PString &baseMember,
- PSafePtr <Member> member);
+ const PString &_srcMemberId,
+ const PString &_dstMemberId);
/** Destructor */
~Participant();
@@ -208,9 +213,12 @@
and active */
BOOL ReadAndMixAudio(BYTE * ptr, PINDEX amount);
- /**Get the id used by the Member class that this Participant looks after */
- PString GetMemberId();
+ /**Get the id used by the Member class that this Participant is held by */
+ PString GetSrcMemberId() { return srcMemberId; }
+ /**Get the id used by the Member class that this Participant points to. */
+ PString GetDstMemberId() { return dstMemberId; }
+
/**Report the key which this participant is known by. The key
describes the id of the member who created us, and the member we
are connected to. */
@@ -269,9 +277,13 @@
/** Current read position in the buffer.*/
PINDEX currentReadIndex;
- /**The remote member that we are connected to */
- PSafePtr <Member> memberPtr;
+ /**The local member, who looks after us */
+ Member * srcMemberPtr;
+ /**The remote member, who is also in this conference. This Participant
+ instance is responsible for sending data to this one remote member */
+ Member * dstMemberPtr;
+
/**The id of the Member who will use us to link to memberId */
PString srcMemberId;
@@ -299,40 +311,6 @@
BOOL isClearing;
};
-/////////////////////////////////////////////////////////////////////////////
-/**Delete one participant, whoc matches a previous participant that
- died. . Do this in a separate thread so it is really fast to
- delete lots of participants, and not hold up the household
- delettion prcoess cause one was slow to delete.. Thus, this program
- will scale nicely when placed on a multi cpu machine */
-
-class MatchingParticipantConsumer: public PThread
-{
- PCLASSINFO(MatchingParticipantConsumer, PThread);
-
- /**Constructor - create this class, which is given the class to destroy.
- This class then does the rest */
- MatchingParticipantConsumer(Manager & _mgr,
- const PString &_otherMember,
- const PString & _partyKey);
-
- /**Destructor. */
- ~MatchingParticipantConsumer();
-
- /**Where this thread runs to do the work */
- void Main();
-
- protected:
- /**Reference to the manager of this conference */
- Manager & mgr;
-
- /**The instance we have to talk to, so the matching Participant
- class can be deleted */
- PString otherMember;
-
- /**The key of the matching Participant class we want to delete */
- PString partyKey;
-};
#endif // _Mcu_Participant_H