convert line ends
[canaan.git] / prj / tech / libsrc / comtools / comconn.cpp
blobbff9510cd7cad301c00f5fd56e9141f21f0165a6
1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/comtools/RCS/comconn.cpp $
3 // $Author: TOML $
4 // $Date: 1996/10/10 14:31:26 $
5 // $Revision: 1.2 $
6 //
8 #include <lg.h>
9 #include <comtools.h>
10 #include <comconn.h>
12 ///////////////////////////////////////////////////////////////////////////////
14 int LGAPI GetCOMConnectionPriority(const void * p)
16 return ((sCOMConnection *)p)->priority;
19 ///////////////////////////////////////////////////////////////////////////////
21 BOOL cCOMConnectionSetBase::Search(IUnknown * p)
23 // Because these lists never get very long, and because
24 // insertion/removal is an uncommon event relative
25 // to iteration, we simply use a linear search
26 for (index_t i = 0; i < m_Connections.Size(); i++)
28 if (m_Connections[i].pSink == p)
29 return TRUE;
31 return FALSE;
34 ///////////////////////////////////////
36 BOOL cCOMConnectionSetBase::Insert(IUnknown * p, DWORD * pCookie)
38 if (Search(p))
40 CriticalMsg("Multiple connection point advises are not permitted");
41 return FALSE;
44 sCOMConnection connection;
45 connection.pSink = p;
46 connection.priority = 0;
47 m_Connections.Append(connection);
49 p->AddRef();
50 *pCookie = DWORD(p);
52 return TRUE;
55 ///////////////////////////////////////
57 BOOL cCOMConnectionSetBase::Insert(IUnknown * p, int priority, DWORD * pCookie)
59 if (Search(p))
61 CriticalMsg("Multiple connection point advises are not permitted");
62 return FALSE;
65 m_fPrioritized = TRUE;
66 m_fSorted = FALSE;
68 sCOMConnection connection;
69 connection.pSink = p;
70 connection.priority = priority;
71 m_Connections.Append(connection);
73 p->AddRef();
74 *pCookie = DWORD(p);
76 return TRUE;
79 ///////////////////////////////////////
81 BOOL cCOMConnectionSetBase::Remove(DWORD cookie)
83 IUnknown * p = (IUnknown *) cookie;
84 for (index_t i = 0; i < m_Connections.Size(); i++)
86 if (m_Connections[i].pSink == p)
88 m_Connections.DeleteItem(i);
89 p->Release();
90 return TRUE;
93 CriticalMsg("Unknown notification sink");
94 return FALSE;
97 ///////////////////////////////////////
99 IUnknown * cCOMConnectionSetBase::GetFirst(tConnSetHandle & hIndex)
101 if (m_Connections.Size())
103 if (m_fPrioritized && !m_fSorted)
105 m_Connections.Sort();
107 hIndex = (tConnSetHandle)0;
108 return m_Connections[(index_t)0].pSink;
110 return NULL;
113 ///////////////////////////////////////
115 IUnknown * cCOMConnectionSetBase::GetNext(tConnSetHandle & hIndex)
117 const index_t index = (index_t)hIndex + 1;
118 if (index < m_Connections.Size())
120 hIndex = (tConnSetHandle)index;
121 return m_Connections[index].pSink;
123 return NULL;
126 ///////////////////////////////////////