RpcDispatcher.cpp
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:8k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* RpcDispatcher */
  2. /* Copyright (c) 1999 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01r,17dec01,nel  Add include symbol for diab.
  7. 01q,13jul01,dbs  fix up includes, exclude priority propagation for now
  8. 01p,13jul00,nel  Win2K fix.
  9. 01o,26jun00,dbs  implement presentation context IDs
  10. 01n,19aug99,aim  added TraceCall header
  11. 01m,13aug99,drm  Documentation updates
  12. 01l,10aug99,aim  fix compiler warnings on solaris
  13. 01k,06aug99,drm  Correcting bug related to error checking.
  14. 01j,03aug99,drm  Adding code to set server priority.
  15. 01i,28jul99,drm  Adding clsid argument to interfaceInfoGet() call.
  16. 01h,09jul99,dbs  convert to final naming scheme
  17. 01g,02jul99,aim  fix for name changes in RpcPduFactory
  18. 01f,29jun99,dbs  release IUnknown-ptr after use
  19. 01e,25jun99,dbs  add channel ID to stub msg
  20. 01d,24jun99,dbs  move authn into new class
  21. 01c,23jun99,dbs  fix authn on response packets
  22. 01b,08jun99,aim  rework
  23. 01a,27may99,aim  created
  24. */
  25. #include "RpcDispatcher.h"
  26. #include "RpcPdu.h"
  27. #include "RpcPduFactory.h"
  28. #include "NdrStreams.h" // marshaling streams
  29. #include "Syslog.h"
  30. #include "orpcLib.h"
  31. #include "orpc.h"
  32. #include "vxdcomExtent.h"
  33. #include "TraceCall.h"
  34. /* Include symbol for diab */
  35. extern "C" int include_vxdcom_RpcDispatcher (void)
  36.     {
  37.     return 0;
  38.     }
  39. RpcDispatcher::RpcDispatcher (RpcDispatchTable* dispatchTable)
  40.   : m_dispatchTable (dispatchTable)
  41.     {
  42.     TRACE_CALL;
  43.     }
  44. RpcDispatcher::~RpcDispatcher ()
  45.     {
  46.     TRACE_CALL;
  47.     }
  48. bool
  49. RpcDispatcher::supportsInterface (REFIID riid)
  50.     {
  51.     return m_dispatchTable->supportsInterface (riid);
  52.     }
  53. extern IID IID_ISystemActivator;
  54. int
  55. RpcDispatcher::dispatch (const RpcPdu& request, RpcPdu& reply, int channelId, REFIID iid)
  56.     {
  57.     PFN_ORPC_STUB pfn;
  58.     IUnknown*  punkItf=0;
  59.     CLSID  classid = GUID_NULL; // CLSID of object
  60.     ORPCTHIS orpcThis; // holds unmarshalled ORPCTHIS 
  61.     HRESULT hr = m_dispatchTable->interfaceInfoGet (iid,
  62.     request.objectId (),
  63.     request.opnum (),
  64.     &punkItf,
  65.     &pfn,
  66.     classid);
  67.     // Here, we test explicitly for S_OK (rather than using FAILED())
  68.     // since there is only one success (S_OK) and *any* other result
  69.     // is a kind of failure...
  70.     if (hr == S_OK)
  71. {
  72. // Create a marshaling-stream ready to hold the reply
  73. NdrMarshalStream ms (NdrPhase::STUB_MSHL, request.drep ());
  74. // Create an unmarshaling-stream holding the received
  75. // stub-data
  76. NdrUnmarshalStream us (NdrPhase::STUB_UNMSHL,
  77.        request.drep (),
  78.        (byte*) request.stubData (),
  79.        request.stubDataLen ());
  80. if (request.objectId() != GUID_NULL)
  81.     {
  82.     // Remove the ORPCTHIS from the stream...
  83.     hr = ndrUnmarshalORPCTHIS (&us, &orpcThis);
  84.     // Insert an ORPCTHAT at the start of the stub-data
  85.     ORPCTHAT orpcThat = { 0, 0 };
  86.     ms.insert (sizeof (ORPCTHAT), &orpcThat, false);
  87.     }
  88. // Fill in msg structure
  89. RPC_STUB_MSG msg (&us, &ms, channelId);
  90. #if 0
  91. #ifdef VXDCOM_PLATFORM_VXWORKS
  92. int oldPriority; // used to restore priority 
  93. int  currentId=0; // task ID of current task
  94. BOOL priorityChanged=FALSE; // whether or not priority was set
  95. ORPC_EXTENT*  pExtent; // ptr to VXDCOM_EXTENT
  96.         
  97.         currentId = taskIdSelf ();
  98. // Lookup the priority scheme for the object and set the 
  99. // priority to the appropriate value.
  100.         if (classid != GUID_NULL)
  101.             {
  102.             int priority;
  103.             vxdcomClassObjRegInfo regInfo;      // result of lookup
  104.             hr = vxdcomSymLookup (classid, &regInfo);
  105.             if (SUCCEEDED (hr))
  106.                 {
  107.                 switch (regInfo.priorityScheme)
  108.                     {
  109.                     case PS_DEFAULT:
  110.                         priority = g_defaultServerPriority;
  111.                         break;
  112.                     case PS_SVR_ASSIGNED:
  113.                         priority = regInfo.priority;
  114.                         break;
  115.                     case PS_CLNT_PROPAGATED:
  116. // If client propagated priority is not present,
  117. // use the default server priority.
  118.                         if (orpcThis.orpcExtentFind (GUID_VXDCOM_EXTENT,
  119.                                                      &pExtent) == S_OK)
  120.                             {
  121.     VXDCOM_EXTENT* pVExtent=NULL; // ptr to derived type
  122.     pVExtent = static_cast<VXDCOM_EXTENT*> (pExtent);
  123.                             if (pVExtent != NULL)
  124.         pVExtent->getPriority(priority);
  125.                             else
  126.                                 priority = g_defaultServerPriority;
  127.                             }
  128.                         else
  129.                             {
  130.                             priority = regInfo.priority;
  131.                             }
  132.                         break;
  133.                     default:
  134. // Unknown priority scheme.  Rather than produce an error
  135. // we will simply use the default server priority.
  136.                         priority = g_defaultServerPriority;
  137.                         break;
  138.                     }
  139.         // Check for valid priority
  140.                 if ( (priority < 0)  || (priority > 255) )
  141.                     {
  142.                     // Invalid priority.  
  143.     // Let's use the system default priority.
  144.                     priority = g_defaultServerPriority;
  145.                     }
  146.                 if (taskPriorityGet (currentId, &oldPriority) == OK)
  147.             {
  148.                     if (taskPrioritySet (currentId, priority) == OK)
  149.                         {
  150.                         priorityChanged = TRUE;
  151.                         }
  152.                     else
  153.                         {
  154.                         // Unable to set priority
  155.                         // There's really nothing we can do in this case - we'll
  156.                         // just run the function at the current priority.
  157.                         }
  158.                     }
  159.                 else
  160.                     {
  161.                     // Unable to get priority.
  162.                     // We might be able to set the priority here, but we wouldn't be 
  163.                     // able to restore, so we'll just run the function at the current
  164.                     // priority.
  165.                     }
  166.                 }
  167.             }
  168.         else
  169.             {
  170.             // Since we can't find the class object, we don't know what priority
  171.             // scheme to use. We'll try to run the function at the default server 
  172.             // priority.
  173.             if (taskPriorityGet (currentId, &oldPriority) == OK)
  174.         {
  175.                 if (taskPrioritySet (currentId, g_defaultServerPriority) == OK)
  176.                     {
  177.                     priorityChanged = TRUE;
  178.                     }
  179.                 else
  180.                     {
  181.                     // Unable to set priority
  182.                     // There's really nothing we can do in this case - we'll
  183.                     // just run the function at the current priority.
  184.                     }
  185.                 }
  186.             else
  187.                 {
  188.                 // Unable to get priority.
  189.                 // We might be able to set the priority here, but we wouldn't be 
  190.                 // able to restore, so we'll just run the function at the current
  191.                 // priority.
  192.                 }
  193.             }
  194.            
  195. #endif
  196. #endif
  197. // Call stub function...
  198. hr = pfn (punkItf, msg);
  199. #if 0
  200. #ifdef VXDCOM_PLATFORM_VXWORKS
  201. // Restore the priority to its previous value.
  202.         if (priorityChanged)
  203.             {
  204.             if (taskPrioritySet (currentId, oldPriority) != OK)
  205.                 {
  206.                 // We were unable to restore the priority to the default value.  
  207.                 // There's not really anything we can do, but leave the thread at the
  208.                 // new priority.
  209.                 }
  210.             }
  211. #endif
  212. #endif
  213. // Release itf ptr...
  214. if (punkItf)
  215.     punkItf->Release ();
  216. if (SUCCEEDED (hr))
  217.     {
  218.     RpcPduFactory::formatResponsePdu (request, reply);
  219.     if (ms.size() > 0)
  220. reply.stubDataAppend (ms.begin (), ms.size ());
  221.     }
  222. else
  223.     {
  224.     RpcPduFactory::formatFaultPdu (request, reply, hr, false);
  225.     }
  226. }
  227.     else
  228. {
  229. RpcPduFactory::formatFaultPdu (request, reply, hr, true);
  230. }
  231.     return hr;
  232.     }