summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormike <mike>2008-07-01 15:19:39 +0000
committermike <mike>2008-07-01 15:19:39 +0000
commit579cc6fc12f9359399d42f5f45a92b1a3dfc7647 (patch)
tree466e48f12bff9d06918fa80ae12d8a57023d0b7f
parent98d3d14c451c0222cb0f0fe13a8055c17c5e02bd (diff)
downloadtog-pegasus-TASK-PEP328_SOLARIS_IX86_CC_PORT-branch.zip
tog-pegasus-TASK-PEP328_SOLARIS_IX86_CC_PORT-branch.tar.gz
tog-pegasus-TASK-PEP328_SOLARIS_IX86_CC_PORT-branch.tar.xz
TITLE: Solaris Porting DESCRIPTION: Ongoing Solaris Porting
-rw-r--r--src/slp/slp_agent/peg_slp_agent.cpp443
1 files changed, 170 insertions, 273 deletions
diff --git a/src/slp/slp_agent/peg_slp_agent.cpp b/src/slp/slp_agent/peg_slp_agent.cpp
index 0f152e9..76cb28d 100644
--- a/src/slp/slp_agent/peg_slp_agent.cpp
+++ b/src/slp/slp_agent/peg_slp_agent.cpp
@@ -39,12 +39,6 @@
#include <slp.h>
#endif /* PEGASUS_USE_OPENSLP */
-#if defined(PEGASUS_USE_OPENSLP) && defined(PEGASUS_SLP_REG_TIMEOUT)
-# error \
- "PEGASUS_USE_OPENSLP and PEGASUS_SLP_REG_TIMEOUT are incompatible, Please "
- "define one or the other but not both."
-#endif
-
PEGASUS_USING_STD;
PEGASUS_NAMESPACE_BEGIN
@@ -124,6 +118,22 @@ sa_reg_params::~sa_reg_params()
}
}
+#ifdef PEGASUS_USE_OPENSLP
+void SLPRegCallback(SLPHandle slp_handle, SLPError errcode, void* cookie)
+{
+ /* return the error code in the cookie */
+ *(SLPError*)cookie = errcode;
+
+ /*
+ You could do something else here like print out
+ the errcode, etc. Remember, as a general rule,
+ do not try to do too much in a callback because
+ it is being executed by the same thread that is
+ reading slp packets from the wire.
+ */
+}
+#endif /* PEGASUS_USE_OPENSLP */
+
slp_service_agent::slp_service_agent()
: _listen_thread(service_listener, this, false),
@@ -304,268 +314,6 @@ void slp_service_agent::_de_init()
}
}
-#ifdef PEGASUS_SLP_REG_TIMEOUT
-Semaphore& slp_service_agent::get_update_reg_semaphore()
-{
- return _update_reg_semaphore;
-}
-#else
-void slp_service_agent::update_reg_count()
-{
- _update_reg_count++;
-}
-#endif
-
-Uint32 slp_service_agent::test_registration(
- const char *url,
- const char *attrs,
- const char *type,
- const char *scopes)
-{
-
- if (_initialized.get() == 0 )
- {
- throw UninitializedObjectException();
- }
- //cout << "test_registration. type= " << type << endl;
- if (type == 0)
- {
- return 1;
- }
- if (url == 0)
- {
- return 2;
- }
- if (attrs == 0)
- {
- return 3;
- }
- if(scopes == 0)
- {
- return 4;
- }
- char* _type = strdup(type);
- char* _url = strdup(url);
- char* _attrs = strdup(attrs);
- char* _scopes = strdup(scopes);
-
- Uint32 ccode = _test_reg(_type, _url, _attrs, _scopes);
-
- //cout << "rtn from _tst_reg: " << ccode << endl;
-
- free(_type);
- free(_url);
- free(_attrs);
- free(_scopes);
- return ccode;
-}
-
-void slp_service_agent::set_registration_callback(void (*ptr)())
-{
- update_registrations = ptr;
-}
-
-//==============================================================================
-//
-// Non-PEGASUS_USE_OPENSLP definitions
-//
-//==============================================================================
-
-#if !defined(PEGASUS_USE_OPENSLP)
-
-Boolean slp_service_agent::srv_register(
- const char* url,
- const char* attributes,
- const char* type,
- const char* scopes,
- unsigned short lifetime)
-{
- if (_initialized.get() == 0 )
- {
- throw UninitializedObjectException();
- }
- if(url == 0 || attributes == 0 || type == 0)
- {
- return false;
- }
- sa_reg_params* rp = 0;
- _internal_regs.lookup(url, rp);
-
- if (rp)
- {
- _internal_regs.remove(url);
- delete rp;
- }
-
- rp = new sa_reg_params(url, attributes, type, scopes, lifetime);
-
- _internal_regs.insert(url, rp);
-
- return true;
-}
-
-void slp_service_agent::unregister()
-{
- if (_initialized.get() == 0 )
- {
- throw UninitializedObjectException();
- }
-
- _should_listen = 0;
-#ifdef PEGASUS_SLP_REG_TIMEOUT
- _update_reg_semaphore.signal();
-#endif
- _listen_thread.join();
-
- while (slp_reg_table::Iterator i = _internal_regs.start())
- {
- sa_reg_params *rp = i.value();
- // Unregister with external SLP SA.
- sa_reg_params *p;
-
- _internal_regs.lookup(rp->url, p);
- _rep->srv_reg_local(_rep,
- (const char*)p->url,
- (const char*)p->attrs,
- (const char*)p->type,
- p->scopes,
- 0);
-
- _internal_regs.remove(rp->url);
- delete rp;
- }
-}
-
-void slp_service_agent::start_listener()
-{
- // see if we need to use an slp directory agent
- if(_initialized.get() == 0 )
- {
- throw UninitializedObjectException();
- }
-}
-
-ThreadReturnType
-PEGASUS_THREAD_CDECL slp_service_agent::service_listener(void *parm)
-{
- Thread *myself = (Thread *)parm;
- if (myself == 0)
- {
- throw NullPointer();
- }
- slp_service_agent *agent = (slp_service_agent *)myself->get_parm();
-
- lslpMsg msg_list;
-
-#ifdef PEGASUS_SLP_REG_TIMEOUT
- Uint16 lifetime = PEGASUS_SLP_REG_TIMEOUT * 60;
-#endif
-
- while (agent->_should_listen.get())
- {
- Uint32 now, msec;
- System::getCurrentTime(now, msec);
-
- // now register everything
- for (slp_reg_table::Iterator i = agent->_internal_regs.start();
- i ; i++)
- {
- sa_reg_params *rp = i.value();
-
-#if defined(PEGASUS_SLP_REG_TIMEOUT)
- agent->_rep->srv_reg_local(agent->_rep,
- rp->url,
- rp->attrs,
- rp->type,
- rp->scopes,
- lifetime);
-#else
- if(rp->expire == 0 || rp->expire < now - 1)
- {
- rp->expire = now + rp->lifetime;
-
- if(agent->_using_das.get())
- {
- agent->_rep->srv_reg_all(
- agent->_rep,
- rp->url,
- rp->attrs,
- rp->type,
- rp->scopes,
- rp->lifetime);
- }
- else
- {
- agent->_rep->srv_reg_local(
- agent->_rep,
- rp->url,
- rp->attrs,
- rp->type,
- rp->scopes,
- rp->lifetime);
- }
- }
-#endif
- }
-
-#ifdef PEGASUS_SLP_REG_TIMEOUT
- Uint32 waitTime = life * 1000;
- try
- {
- agent->_update_reg_semaphore.time_wait(waitTime);
- // semaphore is signalled means we have to update registrations.
- if (agent->_should_listen.get())
- {
- agent->update_registrations();
- }
- }
- catch (const TimeOut&)
- {
- // PEGASUS_SLP_REG_TIMEOUT expired , re-register with
- // external SLP SA.
- }
- catch(...)
- {
- }
-#else
- agent->_rep->service_listener(agent->_rep, 0, &msg_list);
- _LSLP_SLEEP(1);
- if (agent->_update_reg_count.get() && agent->_should_listen.get())
- {
- agent->update_registrations();
- agent->_update_reg_count--;
- }
-#endif
- }
-
- return ThreadReturnType(0);
-}
-
-#endif /* !defined(PEGASUS_USE_OPENSLP) */
-
-//==============================================================================
-//
-// PEGASUS_USE_OPENSLP definitions
-//
-//==============================================================================
-
-#if defined(PEGASUS_USE_OPENSLP)
-
-extern "C" static void SLPRegCallback(
- SLPHandle slp_handle, SLPError errcode, void* cookie)
-{
- /* return the error code in the cookie */
- *(SLPError*)cookie = errcode;
-
- /*
- You could do something else here like print out
- the errcode, etc. Remember, as a general rule,
- do not try to do too much in a callback because
- it is being executed by the same thread that is
- reading slp packets from the wire.
- */
-}
-
Boolean slp_service_agent::srv_register(
const char* url,
const char* attributes,
@@ -594,6 +342,7 @@ Boolean slp_service_agent::srv_register(
_internal_regs.insert(url, rp);
+#if defined(PEGASUS_USE_OPENSLP) && !defined(PEGASUS_SLP_REG_TIMEOUT)
SLPHandle slp_handle = 0;
SLPError slpErr = SLP_OK;
SLPError callbackErr = SLP_OK;
@@ -619,21 +368,42 @@ Boolean slp_service_agent::srv_register(
{
return false;
}
+#endif /* PEGASUS_USE_OPENSLP */
return true;
}
-void slp_service_agent::unregister()
+#ifdef PEGASUS_SLP_REG_TIMEOUT
+Semaphore& slp_service_agent::get_update_reg_semaphore()
{
+ return _update_reg_semaphore;
+}
+#else
+void slp_service_agent::update_reg_count()
+{
+ _update_reg_count++;
+}
+#endif
+void slp_service_agent::unregister()
+{
if (_initialized.get() == 0 )
{
throw UninitializedObjectException();
}
+#ifndef PEGASUS_USE_OPENSLP
+ _should_listen = 0;
+#ifdef PEGASUS_SLP_REG_TIMEOUT
+ _update_reg_semaphore.signal();
+#endif
+ _listen_thread.join();
+#endif /* PEGASUS_USE_OPENSLP */
+
while (slp_reg_table::Iterator i = _internal_regs.start())
{
sa_reg_params *rp = i.value();
+#ifdef PEGASUS_USE_OPENSLP
SLPHandle slp_handle = 0;
SLPError slpErr = SLP_OK;
SLPError callbackErr=SLP_OK;
@@ -661,12 +431,69 @@ void slp_service_agent::unregister()
*/
continue;
}
+#elif PEGASUS_SLP_REG_TIMEOUT
+ // Unregister with external SLP SA.
+ sa_reg_params *p;
+
+ _internal_regs.lookup(rp->url, p);
+ _rep->srv_reg_local(_rep,
+ (const char*)p->url,
+ (const char*)p->attrs,
+ (const char*)p->type,
+ p->scopes,
+ 0);
+#endif
_internal_regs.remove(rp->url);
delete rp;
}
}
+Uint32 slp_service_agent::test_registration(
+ const char *url,
+ const char *attrs,
+ const char *type,
+ const char *scopes)
+{
+
+ if (_initialized.get() == 0 )
+ {
+ throw UninitializedObjectException();
+ }
+ //cout << "test_registration. type= " << type << endl;
+ if (type == 0)
+ {
+ return 1;
+ }
+ if (url == 0)
+ {
+ return 2;
+ }
+ if (attrs == 0)
+ {
+ return 3;
+ }
+ if(scopes == 0)
+ {
+ return 4;
+ }
+ char* _type = strdup(type);
+ char* _url = strdup(url);
+ char* _attrs = strdup(attrs);
+ char* _scopes = strdup(scopes);
+
+ Uint32 ccode = _test_reg(_type, _url, _attrs, _scopes);
+
+ //cout << "rtn from _tst_reg: " << ccode << endl;
+
+ free(_type);
+ free(_url);
+ free(_attrs);
+ free(_scopes);
+ return ccode;
+}
+
+
void slp_service_agent::start_listener()
{
// see if we need to use an slp directory agent
@@ -674,16 +501,26 @@ void slp_service_agent::start_listener()
{
throw UninitializedObjectException();
}
-
+#ifndef PEGASUS_USE_OPENSLP
_using_das = _find_das(_rep, NULL, "DEFAULT");
_should_listen = 1;
_listen_thread.run();
+#endif /* PEGASUS_USE_OPENSLP */
+
+}
+
+
+void slp_service_agent::set_registration_callback(void (*ptr)())
+{
+ update_registrations = ptr;
}
ThreadReturnType
PEGASUS_THREAD_CDECL slp_service_agent::service_listener(void *parm)
{
+#if !defined(PEGASUS_USE_OPENSLP) || \
+ (defined(PEGASUS_USE_OPENSLP) && defined(PEGASUS_SLP_REG_TIMEOUT))
Thread *myself = (Thread *)parm;
if (myself == 0)
{
@@ -693,16 +530,50 @@ PEGASUS_THREAD_CDECL slp_service_agent::service_listener(void *parm)
lslpMsg msg_list;
+#ifdef PEGASUS_SLP_REG_TIMEOUT
+ Uint16 life = PEGASUS_SLP_REG_TIMEOUT * 60;
+#endif
while (agent->_should_listen.get())
{
Uint32 now, msec;
System::getCurrentTime(now, msec);
+
// now register everything
for (slp_reg_table::Iterator i = agent->_internal_regs.start();
i ; i++)
{
sa_reg_params *rp = i.value();
+#ifdef PEGASUS_USE_OPENSLP
+ SLPHandle slp_handle = 0;
+ SLPError slpErr = SLP_OK;
+ SLPError callbackErr=SLP_OK;
+ if ((slpErr = SLPOpen(NULL, SLP_FALSE, &slp_handle)) == SLP_OK)
+ {
+ slpErr = SLPReg(
+ slp_handle,
+ rp->url,
+ life,
+ rp->type,
+ rp->attrs,
+ SLP_TRUE,
+ SLPRegCallback,
+ &callbackErr);
+ SLPClose(slp_handle);
+ }
+ else
+ {
+ // ATTN: Could not get SLP handle,
+ // we try again when lifetime expires.
+ }
+#elif PEGASUS_SLP_REG_TIMEOUT
+ agent->_rep->srv_reg_local(agent->_rep,
+ rp->url,
+ rp->attrs,
+ rp->type,
+ rp->scopes,
+ life);
+#else
if(rp->expire == 0 || rp->expire < now - 1)
{
rp->expire = now + rp->lifetime;
@@ -728,14 +599,40 @@ PEGASUS_THREAD_CDECL slp_service_agent::service_listener(void *parm)
rp->lifetime);
}
}
+#endif
}
+
+#ifdef PEGASUS_SLP_REG_TIMEOUT
+ Uint32 waitTime = life * 1000;
+ try
+ {
+ agent->_update_reg_semaphore.time_wait(waitTime);
+ // semaphore is signalled means we have to update registrations.
+ if (agent->_should_listen.get())
+ {
+ agent->update_registrations();
+ }
+ }
+ catch (const TimeOut&)
+ {
+ // PEGASUS_SLP_REG_TIMEOUT expired , re-register with
+ // external SLP SA.
+ }
+ catch(...)
+ {
+ }
+#else
agent->_rep->service_listener(agent->_rep, 0, &msg_list);
_LSLP_SLEEP(1);
+ if (agent->_update_reg_count.get() && agent->_should_listen.get())
+ {
+ agent->update_registrations();
+ agent->_update_reg_count--;
+ }
+#endif
}
-
+#endif /* PEGASUS_USE_OPENSLP */
return ThreadReturnType(0);
}
-#endif /* defined(PEGASUS_USE_OPENSLP) */
-
PEGASUS_NAMESPACE_END