void SipPublishContentMgr::getContentChangeObserver(const char* eventType,
                                                    SipPublisherContentChangeCallback& callbackFunction,
                                                    void*& applicationData)
{
   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                 "SipPublishContentMgr::getContentChangeObserver eventType '%s'",
                 eventType);
   UtlString eventTypeString(eventType);

   lock();

   PublishCallbackContainer* callbackEntry = 
      dynamic_cast <PublishCallbackContainer*>
      (mEventContentCallbacks.find(&eventTypeString));
   if (callbackEntry)
   {
      callbackFunction = callbackEntry->mpCallback;
      applicationData = callbackEntry->mpApplicationData;
   }
   else
   {
      callbackFunction = NULL;
      applicationData = NULL;
   }

   unlock();

   return;
}
Пример #2
0
UtlBoolean SipPublishContentMgr::removeContentChangeObserver(const char* eventType,
        void*& applicationData,
        SipPublisherContentChangeCallback& callbackFunction)
{
    OsSysLog::add(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::removeContentChangeObserver eventType '%s', callbackFunction %p",
                  eventType, &callbackFunction);
    UtlBoolean callbackRemoved = FALSE;
    UtlString eventTypeString(eventType);
    PublishCallbackContainer* callbackEntry = NULL;

    lock();

    // eventType must be defined
    if(eventType == NULL ||
            *eventType == 0)
    {
        OsSysLog::add(FAC_SIP, PRI_ERR,
                      "SipPublishContentMgr::setContentChangeObserver ignored, event type not set.");

    }

    // There should not be a callback set, need to unset first
    else if((callbackEntry = (PublishCallbackContainer*)
                             mEventContentCallbacks.remove(&eventTypeString)))
    {
        callbackRemoved = TRUE;
        callbackFunction = callbackEntry->mpCallback;
        applicationData = callbackEntry->mpApplicationData;
        delete callbackEntry;
        callbackEntry = NULL;
    }

    else
    {
        OsSysLog::add(FAC_SIP, PRI_ERR,
                      "SipPublishContentMgr::setContentChangeObserver ignored, no callback exists for event: %s",
                      eventType ? eventType : "<null>");
    }

    unlock();

    return (callbackRemoved);
}
Пример #3
0
UtlBoolean SipPublishContentMgr::setContentChangeObserver(const char* eventType,
        void* applicationData,
        SipPublisherContentChangeCallback callbackFunction)
{
    OsSysLog::add(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::setContentChangeObserver eventType '%s', callbackFunction %p",
                  eventType, callbackFunction);
    UtlBoolean callbackSet = FALSE;
    UtlString eventTypeString(eventType);

    lock();

    // eventTypeKey and eventType must be defined
    if(eventType == NULL ||
            *eventType == 0)
    {
        OsSysLog::add(FAC_SIP, PRI_ERR,
                      "SipPublishContentMgr::setContentChangeObserver ignored, event type not set.");

    }

    // There should not be a callback set, need to unset first
    else if((mEventContentCallbacks.find(&eventTypeString)))
    {
        OsSysLog::add(FAC_SIP, PRI_ERR,
                      "SipPublishContentMgr::setContentChangeObserver ignored, callback already exists for event: %s",
                      eventType ? eventType : "<null>");
    }

    else
    {
        callbackSet = TRUE;
        PublishCallbackContainer* callbackEntry = new PublishCallbackContainer();
        *((UtlString*)callbackEntry) = eventType;
        callbackEntry->mpApplicationData = applicationData;
        callbackEntry->mpCallback = callbackFunction;
        mEventContentCallbacks.insert(callbackEntry);
    }

    unlock();

    return (callbackSet);
}
void SipPublishContentMgr::setContentChangeObserver(const char* eventType,
                                                    SipPublisherContentChangeCallback callbackFunction,
                                                    void* applicationData)
{
    Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::setContentChangeObserver eventType '%s', callbackFunction %p, applicationData = %p",
                  eventType, callbackFunction, applicationData);
    UtlString eventTypeString(eventType);

    lock();

    // eventType must be defined
    if (!eventTypeString.isNull())
    {
       // Delete any existing callback.
       mEventContentCallbacks.destroy(&eventTypeString);
       // Insert the new callback, if it is not NULL.
       if (callbackFunction)
       {
          mEventContentCallbacks.insert(
             new PublishCallbackContainer(eventTypeString,
                                          callbackFunction,
                                          applicationData));
       }
    }
    else
    {
       Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                     "SipPublishContentMgr::setContentChangeObserver "
                     "ignored, eventType is null.");
    }

    unlock();

    return;
}
Пример #5
0
UtlBoolean SipPublishContentMgr::publish(const char* resourceId,
                                         const char* eventTypeKey,
                                         const char* eventType,
                                         int numContentTypes,
                                         HttpBody* eventContent[],
                                         int maxOldContentTypes,
                                         int& numOldContentTypes,
                                         HttpBody* oldEventContent[])
{
#ifdef TEST_PRINT
    osPrintf("SipPublishContentMgr::publish(%s, %s, %s, %d, [%p], ...)\n",
        resourceId, eventTypeKey, eventType, numContentTypes, eventContent[0]);
#endif

    UtlBoolean contentAdded = FALSE;
    UtlBoolean resourceIdProvided = FALSE;
    UtlString key;

    if(resourceId && *resourceId)
    {
        resourceIdProvided = TRUE;
        key = resourceId;
    }

    if(eventTypeKey)
    {
        key.append(eventTypeKey);
    }

    int numOld = 0;
    lock();
    PublishContentContainer* container = NULL;
    if(resourceIdProvided)
    {
        // See if resource specific content already exists
        container = 
            (PublishContentContainer*) mContentEntries.find(&key);
    }
    else
    {
        // See if default content already exists
        container = 
            (PublishContentContainer*) mDefaultContentEntries.find(&key);
    }

    if(container == NULL && numContentTypes > 0)
    {
        container = new PublishContentContainer();
        *((UtlString*)container) = key;
        container->mResourceId = "";
        container->mEventTypeKey = eventTypeKey;
        numOldContentTypes = 0;
        if(resourceIdProvided)
        {
            // Add resource specific content
            mContentEntries.insert(container);
        }
        else
        {
            // Add default content
            mDefaultContentEntries.insert(container);
        }
    }

    // No existing content and no new content
    else if(container == NULL && numContentTypes <= 0)
    {
    }

    // The content default for this event type already existed
    else
    {
        numOld = container->mEventContent.entries();

        if(numOld <= maxOldContentTypes)
        {
            // Remove the old content
            numOldContentTypes = numOld;
            for(int index = 0; index < numOld; index++)
            {
                oldEventContent[index] = (HttpBody*)
                    container->mEventContent.first();
                container->mEventContent.remove(oldEventContent[index]);
            }

            if(numContentTypes <= 0)
            {
                // Remove and delete the container
                if(resourceIdProvided)
                {
                    // Remove resource specific content
                    mContentEntries.remove(container);
                }
                else
                {
                    // Remove default content
                    mDefaultContentEntries.remove(container);
                }
                delete container;
                container = NULL;
            }
        }
    }


    // If there is old content and we did not get a big enough array
    // to put the old content in, don't do anything
    if(numOld <= maxOldContentTypes)
    {
        // Add the new content
        for(int index = 0; index < numContentTypes; index++)
        {
            container->mEventContent.append(eventContent[index]);
        }
        contentAdded = TRUE;


        // See if there is a observer for the content change
        UtlString eventTypeString(eventType);
        PublishCallbackContainer* callbackContainer = (PublishCallbackContainer*)
            mEventContentCallbacks.find(&eventTypeString);
        if(callbackContainer && callbackContainer->mpCallback)
        {
            (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                          resourceId,
                                          eventTypeKey,
                                          eventTypeString,
                                          !resourceIdProvided);
        }
    }
    unlock();

    return(contentAdded);
}
void SipPublishContentMgr::unpublish(const char* resourceId,
                                     const char* eventTypeKey,
                                     const char* eventType,
                                     const char* reason)
{
    Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::unpublish resourceId '%s', eventTypeKey '%s', eventType '%s', reason '%s'",
                  resourceId ? resourceId : "(null)",
                  eventTypeKey, eventType,
                  reason ? reason : "(null)");

    // Construct the key to look up.
    UtlString key;
    key.append(resourceId);
    key.append(CONTENT_KEY_SEPARATOR);
    key.append(eventTypeKey);

    lock();

    // Look up the key in the specific or default entries, as appropriate.
    if (resourceId)
    {
       PublishContentContainer* content =
          dynamic_cast <PublishContentContainer*> (mContentEntries.remove(&key));
       PublishContentContainer* partialContent =
          dynamic_cast <PublishContentContainer*> (mPartialContentEntries.remove(&key));

       // Call the default content constructors, if available.
       
       // Construct the key for the default data.
       UtlString default_key;
       default_key.append(CONTENT_KEY_SEPARATOR);
       default_key.append(eventTypeKey);

       // If it exists, call it to publish full content for this resource/event.
       SipPublishContentMgrDefaultConstructor* constructor =
          dynamic_cast <SipPublishContentMgrDefaultConstructor*>
          (mDefaultContentConstructors.findValue(&default_key));
       if (constructor)
       {
          constructor->generateDefaultContent(this, resourceId,
                                              eventTypeKey, eventType);
       }

       // If it exists, call it to publish partial content for this resource/event.
       constructor =
          dynamic_cast <SipPublishContentMgrDefaultConstructor*>
          (mDefaultPartialContentConstructors.findValue(&default_key));
       if (constructor)
       {
          constructor->generateDefaultContent(this, resourceId,
                                              eventTypeKey, eventType);
       }

       // Is there a callback for this eventType?  (Probably so.)
       UtlString eventTypeString(eventType);
       PublishCallbackContainer* callbackContainer =
          dynamic_cast <PublishCallbackContainer*>
          (mEventContentCallbacks.find(&eventTypeString));
       if (callbackContainer)
       {
          // See if resource-specific (full) content exists now.
          PublishContentContainer* newContent =
             dynamic_cast <PublishContentContainer*> (mContentEntries.find(&key));

          // If no (full) content was generated, check if (fixed) default content exists.
          PublishContentContainer* defaultContent = NULL;
          if (!newContent)
          {
             defaultContent =
                dynamic_cast <PublishContentContainer*> (mDefaultContentEntries.find(&default_key));
          }

          // Now, newContent is non-NULL if default content exists for
          // 'key', which means that the resource still has
          // publishable content.
          if (newContent || defaultContent)
          {
             // Replace the new content for the resource with the previous content.
             if (newContent)
             {
                mContentEntries.removeReference(newContent);
             }
             PublishContentContainer* newPartialContent =
                dynamic_cast <PublishContentContainer*> (mPartialContentEntries.remove(&key));

             // Insert the previous content for the resource.
             if (content)
             {
                mContentEntries.insert(content);
             }
             if (partialContent)
             {
                mPartialContentEntries.insert(partialContent);
             }

             // Do a "publish" callback.
             (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                             resourceId,
                                             eventTypeKey,
                                             eventTypeString,
                                             NULL);

             // Remove the previous content again.
             // Insert the previous content for the resource.
             if (content)
             {
                mContentEntries.removeReference(content);
             }
             if (partialContent)
             {
                mPartialContentEntries.removeReference(partialContent);
             }

             // Insert the new content again.
             if (newContent)
             {
                mContentEntries.insert(newContent);
             }
             if (newPartialContent)
             {
                mContentEntries.insert(newPartialContent);
             }
          }
          else
          {
             // No publishable content, so do an "unpublish" callback.
             (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                             resourceId,
                                             eventTypeKey,
                                             eventTypeString,
                                             reason);
          }
       }

       // Delete the old content containers.
       if (content)
       {
          delete content;
       }
       if (partialContent)
       {
          delete partialContent;
       }
    }
    else
    {
       // Remove default content.
       mDefaultContentEntries.destroy(&key);
       // Remove any default constructor.
       mDefaultContentConstructors.destroy(&key);
    }

    unlock();
}
void SipPublishContentMgr::publish(const char* resourceId,
                                   const char* eventTypeKey,
                                   const char* eventType,
                                   int numContentTypes,
                                   HttpBody* eventContent[],
                                   UtlBoolean fullState,
                                   UtlBoolean noNotify)
{
    Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::publish resourceId '%s', eventTypeKey '%s', eventType '%s', numContentTypes %d, noNotify %d, fullState %d",
                  resourceId ? resourceId : "(null)",
                  eventTypeKey, eventType, numContentTypes, noNotify, fullState);

    if (numContentTypes < 1)
    {
       Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                     "SipPublishContentMgr::publish "
                     "No content bodies supplied for resourceId '%s', "
                     "eventTypeKey '%s', fullState %d",
                     resourceId? resourceId : "(null)",
                     eventTypeKey, fullState);
       
    }

    // Construct the key to look up.
    UtlString key;
    key.append(resourceId);
    key.append(CONTENT_KEY_SEPARATOR);
    key.append(eventTypeKey);

    lock();

    // Determine the storage we will be using.
    UtlHashBag* pContent;
    // resourceId can be NULL if we are called from ::publishDefault()
    if (resourceId)
    {
       if (fullState)
       {
          // Full dialog events
          pContent = &mContentEntries;
       }
       else
       {
          // Partial dialog events
          pContent = &mPartialContentEntries;
       }
    }
    else
    {
       // Default dialog events
       if (fullState)
       {
          pContent = &mDefaultContentEntries;
       }
       else
       {
          pContent = &mDefaultPartialContentEntries;
       }
    }

    // Look up the key in the specific or default entries, as appropriate.
    PublishContentContainer* container =
       dynamic_cast <PublishContentContainer*> (pContent->find(&key));

    // If not found, create a container.
    if (container == NULL)
    {
        container = new PublishContentContainer(key);
	// Save the container in the appropriate hash.
        pContent->insert(container);
    }
    // The content for this event type already existed
    else
    {
        // Remove the old content
        container->mEventContent.destroyAll();
    }

    // Add the new content
    for (int index = 0; index < numContentTypes; index++)
    {
        Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
            "SipPublishContentMgr::publish eventContent[%d] = %p, key = '%s', content type = '%s', getBytes() = %p '%s'",
                      index,
                      eventContent[index],
                      key.data(),
                      eventContent[index]->data(),
                      eventContent[index]->getBytes(),
                      eventContent[index]->getBytes());
        container->mEventContent.append(eventContent[index]);
    }

    // Don't call the observers if noNotify is set or if this is default content.
    if (!noNotify && resourceId)
    {
       // Call the observer for the content change, if any.
       UtlString eventTypeString(eventType);
       PublishCallbackContainer* callbackContainer =
          dynamic_cast <PublishCallbackContainer*>
          (mEventContentCallbacks.find(&eventTypeString));
       if (callbackContainer)
       {
          (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                          resourceId,
                                          eventTypeKey,
                                          eventTypeString,
                                          NULL);
       }
    }

    unlock();
}
Пример #8
0
void SipPublishContentMgr::unpublish(const char* resourceId,
                                     const char* eventTypeKey,
                                     const char* eventType)
{
    OsSysLog::add(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::unpublish resourceId '%s', eventTypeKey '%s', eventType '%s'",
                  resourceId, eventTypeKey, eventType);
    UtlBoolean resourceIdProvided = resourceId && *resourceId;

    // Construct the key to look up.
    UtlString key;
    if(resourceIdProvided)
    {
        key = resourceId;
    }

    if(eventTypeKey)
    {
        key.append(eventTypeKey);
    }

    lock();

    // Look up the key in the specific or default entries, as appropriate.
    PublishContentContainer* container;
    if (resourceIdProvided)
    {
        container = dynamic_cast <PublishContentContainer*>(mContentEntries.find(&key));
        if (container)
        {
            container->mEventContent.destroyAll();
            container->mEventVersion.destroyAll();
            mContentEntries.destroy(container);
        }

        container = dynamic_cast <PublishContentContainer*>(mPartialContentEntries.find(&key));
        if (container)
        {
            container->mEventContent.destroyAll();
            container->mEventVersion.destroyAll();
            mPartialContentEntries.destroy(container);
        }
    }
    else
    {
        container = dynamic_cast <PublishContentContainer*>(mDefaultContentEntries.find(&key));
        if (container)
        {
            container->mEventContent.destroyAll();
            container->mEventVersion.destroyAll();
            mDefaultContentEntries.destroy(container);
        }

        // Remove any default constructor.
        mDefaultContentConstructors.destroy(&key);
    }

    // Call the observer for the content change, if any, unless this
    // is default content.
    if (resourceIdProvided)
    {
        UtlString eventTypeString(eventType);
        PublishCallbackContainer* callbackContainer =
            dynamic_cast <PublishCallbackContainer*>
            (mEventContentCallbacks.find(&eventTypeString));
        if(callbackContainer && callbackContainer->mpCallback)
        {
            (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                            resourceId,
                                            eventTypeKey,
                                            eventTypeString);
        }
    }

    unlock();
}
Пример #9
0
void SipPublishContentMgr::publish(const char* resourceId,
                                   const char* eventTypeKey,
                                   const char* eventType,
                                   int numContentTypes,
                                   HttpBody* eventContent[],
                                   const int eventVersion[],
                                   UtlBoolean noNotify,
                                   UtlBoolean fullState)
{
    OsSysLog::add(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::publish resourceId '%s', eventTypeKey '%s', eventType '%s', numContentTypes %d, noNotify %d, fullState %d",
                  resourceId, eventTypeKey, eventType, numContentTypes,
                  noNotify, fullState);

    UtlBoolean resourceIdProvided = resourceId && *resourceId;

    // Construct the key to look up.
    UtlString key;
    if(resourceIdProvided)
    {
        key = resourceId;
    }

    if(eventTypeKey)
    {
        key.append(eventTypeKey);
    }

    lock();

    // Determine the type of storage we will be using
    UtlHashBag* pContent;
    if (resourceIdProvided)
    {
        if (fullState)
        {
            // Full dialog events
            pContent = &mContentEntries;
        }
        else
        {
            // Partial dialog events
            pContent = &mPartialContentEntries;
        }
    }
    else
    {
        // Default dialog events
        pContent = &mDefaultContentEntries;
    }

    // Look up the key in the specific or default entries, as appropriate.
    PublishContentContainer* container =
        dynamic_cast <PublishContentContainer*> (pContent->find(&key));

    // If not found, create a container.
    if(container == NULL)
    {
        container = new PublishContentContainer();
        *((UtlString*) container) = key;
        // Save the container in the appropriate hash.
        pContent->insert(container);
    }

    // The content for this event type already existed
    else
    {
        // Remove the old content
        container->mEventContent.destroyAll();
        container->mEventVersion.destroyAll();
    }

    // Add the new content
    for (int index = 0; index < numContentTypes; index++)
    {
        OsSysLog::add(FAC_SIP, PRI_DEBUG,
                      "SipPublishContentMgr::publish eventContent[%d] = %p, key = '%s', content type = '%s', version = %d, getBytes() = %p '%s'",
                      index,
                      eventContent[index],
                      key.data(),
                      eventContent[index]->data(),
                      eventVersion[index],
                      eventContent[index]->getBytes(),
                      eventContent[index]->getBytes());
        container->mEventContent.append(eventContent[index]);
        container->mEventVersion.append(new UtlInt(eventVersion[index]));
    }

    // Don't call the observers if noNotify is set or if this is default content.
    if (!noNotify && resourceIdProvided)
    {
        // Call the observer for the content change, if any.
        UtlString eventTypeString(eventType);
        PublishCallbackContainer* callbackContainer =
            dynamic_cast <PublishCallbackContainer*>
            (mEventContentCallbacks.find(&eventTypeString));
        if(callbackContainer && callbackContainer->mpCallback)
        {
            (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                            resourceId,
                                            eventTypeKey,
                                            eventTypeString);
        }
    }

    unlock();
}