/home/dko/projects/mobilec/trunk/src/win32/LibMC.net/LibMC/MCAgency.cs

Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using System.Runtime.InteropServices;
00005 
00318 namespace LibMC
00319 {
00329     public partial class MCAgency
00330     {
00337         public enum MCAgencyState
00338         {
00339             NoState = -1,       
00340             Initialized = 0,    
00341             Running,            
00342             Halted,             
00343             Ended,              
00344         }
00345 
00351         public enum ChShellType
00352         {
00353             CH_REGULARCH = 0,   
00354             CH_SAFECH = 1,      
00355         }
00356 
00357         private IntPtr agency_p = IntPtr.Zero;
00358         private MCAgencyOptions_t options;
00359         private int port = -1;
00360         private MCAgencyState state = MCAgencyState.NoState;
00361 
00369         public MCAgency()
00370         {
00371             options = new MCAgencyOptions_t();
00372             _MC_InitializeAgencyOptions(ref options);
00373             state = MCAgencyState.Initialized;
00374         }
00375 
00376         private IntPtr Agency
00377         {
00378             get
00379             {
00380                 if (agency_p == IntPtr.Zero)
00381                     throw new SystemException("Private agency pointer is zero!");
00382                 else
00383                     return agency_p;
00384             }
00385             set
00386             {
00387                 if (agency_p == IntPtr.Zero)
00388                     agency_p = value;
00389                 else
00390                     throw new SystemException("Attempting to assign new agency to non-zero agency pointer!");
00391             }
00392         }
00393 
00403         public int Port
00404         {
00405             get
00406             {
00407                 return port;
00408             }
00409             set
00410             {
00411                 port = value;
00412             }
00413         }
00414 
00423         public MCAgencyState State
00424         {
00425             get
00426             {
00427                 return state;
00428             }
00429         }
00430 
00431         /*
00432          * Agency functions
00433          */
00434 
00445         public int Initialize()
00446         {
00447             if (port == -1)
00448                 return -1;
00449             else
00450             {
00451                 Agency = MCAgency._MC_Initialize(port, ref options);
00452                 state = MCAgencyState.Running;
00453                 return 0;
00454             }
00455         }
00456 
00467         public int End()
00468         {
00469             int temp = MCAgency._MC_End(Agency);
00470             state = MCAgencyState.Ended;
00471             return temp;
00472         }
00473 
00485         public int ChInitializeOptions(ChShellType shellType, String home)
00486         {
00487             ChOptions_t options = new ChOptions_t();
00488             options.chhome = home;
00489             options.shelltype = (int)shellType;
00490             return _MC_ChInitializeOptions(Agency, options);
00491         }
00492 
00493         /* \brief       Sets all threads for the agency to "on."
00494          * 
00495          * Sets all threads for the agency to "on." This is also the default state
00496          * for the agency.
00497          * 
00498          * \returns     The return value of the underlying MC_SetThreadsAllOn function.
00499          * 
00500          * \note        This function must be called before the agency is started.
00501          */
00502         public int SetThreadsAllOn()
00503         {
00504             return _MC_SetThreadsAllOn(ref options);
00505         }
00506 
00516         public int SetThreadsAllOff()
00517         {
00518             return _MC_SetThreadsAllOff(ref options);
00519         }
00520 
00532         public int SetThreadOn(MC_ThreadIndex_e index)
00533         {
00534             return _MC_SetThreadOn(ref options, index);
00535         }
00536 
00547         public int SetThreadOff(MC_ThreadIndex_e index)
00548         {
00549             return _MC_SetThreadOff(ref options, index);
00550         }
00551 
00562         public int HaltAgency()
00563         {
00564             int temp = _MC_HaltAgency(Agency);
00565             state = MCAgencyState.Halted;
00566             return temp;
00567         }
00568 
00579         public int ResumeAgency()
00580         {
00581             int temp = _MC_ResumeAgency(Agency);
00582             state = MCAgencyState.Running;
00583             return temp;
00584         }
00585 
00595         public int SetDefaultAgentStatus(MCAgent.MC_AgentStatus_e status)
00596         {
00597             return _MC_SetDefaultAgentStatus(Agency, status);
00598         }
00599 
00608         public MCAgent WaitRetrieveAgent()
00609         {
00610             IntPtr temp = _MC_WaitRetrieveAgent(Agency);
00611             if (temp != IntPtr.Zero)
00612                 return new MCAgent(temp);
00613             else
00614                 return new MCAgent();
00615         }
00616 
00625         public int WaitAgent()
00626         {
00627             return _MC_WaitAgent(Agency);
00628         }
00629 
00630         /*
00631          * Migration functions
00632          */
00633 
00644         public int SendAgentMigrationMessageFile(String filename, String hostname, int port)
00645         {
00646             return MCAgency._MC_SendAgentMigrationMessageFile(Agency, filename, hostname, port);
00647         }
00648 
00658         public int LoadAgentMigrationMessageFile(String filename)
00659         {
00660             return MCAgency._MC_SendAgentMigrationMessageFile(Agency, filename, "localhost", this.Port);
00661         }
00662 
00673         public int SendAgentMigrationMessage(String message, String hostname, int port)
00674         {
00675             return _MC_SendAgentMigrationMessage(Agency, message, hostname, port);
00676         }
00677 
00678         /*
00679          * Signals and threading functions
00680          */
00681 
00691         public int CondBroadcast(int id)
00692         {
00693             return _MC_CondBroadcast(Agency, id);
00694         }
00695 
00705         public int CondSignal(int id)
00706         {
00707             return _MC_CondSignal(Agency, id);
00708         }
00709 
00720         public int CondReset(int id)
00721         {
00722             return _MC_CondReset(Agency, id);
00723         }
00724 
00735         public int CondWait(int id)
00736         {
00737             return _MC_CondWait(Agency, id);
00738         }
00739 
00750         public int MutexLock(int id)
00751         {
00752             return _MC_MutexLock(Agency, id);
00753         }
00754 
00764         public int MutexUnlock(int id)
00765         {
00766             return _MC_MutexUnlock(Agency, id);
00767         }
00768 
00778         public int SemaphorePost(int id)
00779         {
00780             return _MC_SemaphorePost(Agency, id);
00781         }
00782 
00793         public int SemaphoreWait(int id)
00794         {
00795             return _MC_SemaphoreWait(Agency, id);
00796         }
00797 
00806         public int ResetSignal()
00807         {
00808             return _MC_ResetSignal(Agency);
00809         }
00810 
00820         public int SyncDelete(int id)
00821         {
00822             return _MC_SyncDelete(Agency, id);
00823         }
00824 
00836         public int SyncInit(int id)
00837         {
00838             return _MC_SyncInit(Agency, id);
00839         }
00840 
00849         public int WaitSignal(int signals)
00850         {
00851             return _MC_WaitSignal(Agency, signals);
00852         }
00853 
00863         public int BarrierDelete(int id)
00864         {
00865             return _MC_BarrierDelete(Agency, id);
00866         }
00867 
00877         public int BarrierInit(int id, int num_procs)
00878         {
00879             return _MC_BarrierInit(Agency, id, num_procs);
00880         }
00881 
00882         /*
00883          * Steering functions
00884          */
00885 
00895         public MC_SteerCommand_e SteerControl()
00896         {
00897             return _MC_SteerControl();
00898         }
00899 
00912         /*public int _MC_Steer(IntPtr agency, int (*funcptr)(void* data), void *arg);*/
00913         public int Steer(IntPtr funcptr, IntPtr arg)
00914         {
00915             //return _MC_Steer(Agency, IntPtr funcptr, IntPtr arg);
00916             throw new Exception("Steer() is not yet implemented!");
00917         }
00918 
00919         /*
00920          * Services
00921          */
00922 
00938         public int RegisterService(MCAgent agent, int agentID, String agentName, String[] serviceNames, int numServices)
00939         {
00940             return _MC_RegisterService(Agency, agent.Agent, agentID, agentName, serviceNames, numServices);
00941         }
00942 
00960         /*private static extern int _MC_SearchForService(IntPtr agency, String searchString, char*** agentNames, char*** serviceNames, int** agentIDs, int* numResults);*/
00961         public int SearchForService(String searchString, IntPtr agentNames, IntPtr serviceNames, IntPtr agentIDs, IntPtr numResults)
00962         {
00963             //return _MC_SearchForService(IntPtr agency, String searchString, IntPtr agentNames, IntPtr serviceNames, IntPtr agentIDs, IntPtr numResults);
00964             throw new Exception("SearchForService() is not yet implemented!");
00965         }
00966 
00967         /*
00968          * Agent functions
00969         */
00970 
00979         public int AddAgent(MCAgent agent)
00980         {
00981             return _MC_AddAgent(Agency, agent.Agent);
00982         }
00983 
00992         public MCAgent FindAgentByName(String name)
00993         {
00994             return new MCAgent(_MC_FindAgentByName(Agency, name));
00995         }
00996 
01005         public MCAgent FindAgentByID(int id)
01006         {
01007             return new MCAgent(_MC_FindAgentByID(Agency, id));
01008         }
01009 
01017         public MCAgent RetrieveAgent()
01018         {
01019             return new MCAgent(_MC_RetrieveAgent(Agency));
01020         }
01021 
01022         /*
01023          * ACL Functions
01024          */
01025 
01034         public int AclSend(MCAclMessage acl_message)
01035         {
01036             return MCAgency._MC_AclSend(Agency, acl_message.AclMsg);
01037         }
01038 
01047         public int MainLoop()
01048         {
01049             return _MC_MainLoop(Agency);
01050         }
01051     }
01052 }

Generated on Mon Jun 23 16:01:12 2008 for Mobile-C by  doxygen 1.5.4