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

Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 
00049 namespace LibMC
00050 {
00060     public class MCAgent
00061     {
00062         private IntPtr agent_p;
00063         private String name = "";
00064         private int id = -1;
00065         private int numTasks = -1;
00066         private MC_AgentStatus_e status = MC_AgentStatus_e.MC_NO_STATUS;
00067         private MC_AgentType_e type = MC_AgentType_e.MC_NONE;
00068 
00074         public enum MC_AgentType_e
00075         {
00076             MC_NONE = -1,           
00077             MC_REMOTE_AGENT = 0,    
00078             MC_LOCAL_AGENT,         
00079             MC_RETURN_AGENT         
00080         };
00081 
00087         public enum MC_AgentStatus_e
00088         {
00089             MC_NO_STATUS = -1, 
00090             MC_WAIT_CH = 0,    
00091             MC_WAIT_MESSGSEND, 
00092             MC_AGENT_ACTIVE,   
00093             MC_AGENT_NEUTRAL,  
00094             MC_AGENT_SUSPENDED,
00095             MC_WAIT_FINISHED   
00096         };
00097 
00103         public MCAgent()
00104         {
00105             // Not using wrapper - default value
00106             agent_p = IntPtr.Zero;
00107         }
00108 
00109         internal MCAgent(IntPtr ip)
00110         {
00111             Agent = ip;
00112         }
00113 
00125         public override string ToString()
00126         {
00127             StringBuilder sb = new StringBuilder();
00128             sb.AppendFormat("MCAgent:\n\tName: {0}\n\tID: {1}\n\tNumTasks: {2}\n\tStatus: {3}\n\tType: {4}", 
00129                 AgentName.ToString(), 
00130                 AgentID.ToString(),
00131                 AgentNumTasks.ToString(),
00132                 Enum.GetName(typeof(MC_AgentStatus_e), AgentStatus),
00133                 Enum.GetName(typeof(MC_AgentType_e), AgentType));
00134 
00135             return sb.ToString();
00136         }
00137 
00138         /*
00139          * Accessors
00140          */
00141         internal IntPtr Agent
00142         {
00143             get
00144             {
00145                 if (agent_p == IntPtr.Zero)
00146                     throw new SystemException("Private agent pointer is zero!");
00147                 else
00148                     return agent_p;
00149             }
00150             set
00151             {
00152                 if (agent_p == IntPtr.Zero)
00153                 {
00154                     agent_p = value;
00155                     GetAgentFields();
00156                 }
00157                 else
00158                     throw new SystemException("Attempting to assign new agent to non-zero agent pointer!");
00159             }
00160         }
00161 
00162         private void GetAgentFields()
00163         {
00164             id = MCAgency._MC_GetAgentID(Agent);
00165             name = MCAgency._MC_GetAgentName(Agent);
00166             numTasks = MCAgency._MC_GetAgentNumTasks(Agent);
00167             status = MCAgency._MC_GetAgentStatus(Agent);
00168             type = MCAgency._MC_GetAgentType(Agent);
00169         }
00170 
00179         public int AgentID
00180         {
00181             get
00182             {
00183                 return id;
00184             }
00185             /*set
00186             {
00187                 id = value;
00188             }*/
00189         }
00190 
00199         public String AgentName
00200         {
00201             get
00202             {
00203                 return name;
00204             }
00205             /*set
00206             {
00207                 name = value;
00208             }*/
00209         }
00210 
00218         public int AgentNumTasks
00219         {
00220             get
00221             {
00222                 return numTasks;
00223             }
00224             /*set
00225             {
00226                 numTasks = value;
00227             }*/
00228         }
00229 
00240         public MC_AgentStatus_e AgentStatus
00241         {
00242             get
00243             {
00244                 status = MCAgency._MC_GetAgentStatus(Agent);
00245                 return status;
00246             }
00247             set
00248             {
00249                 MCAgency._MC_SetAgentStatus(Agent, value);
00250                 status = MCAgency._MC_GetAgentStatus(Agent);
00251             }
00252         }
00253 
00262         public MC_AgentType_e AgentType
00263         {
00264             get
00265             {
00266                 return type;
00267             }
00268             /*set
00269             {
00270                 type = value;
00271             }*/
00272         }
00273 
00274         /*
00275          * Static casting operators
00276          */
00277         static public implicit operator IntPtr(MCAgent agent)
00278         {
00279             return agent.Agent;
00280         }
00281 
00282         static public implicit operator MCAgent(IntPtr ip)
00283         {
00284             return new MCAgent(ip);
00285         }
00286 
00287         /*
00288          * Agent functions
00289          */
00290 
00299         public int DeleteAgent()
00300         {
00301             return MCAgency._MC_DeleteAgent(Agent);
00302         }
00303 
00312         public String GetAgentXMLString()
00313         {
00314             return MCAgency._MC_GetAgentXMLString(Agent);
00315         }
00316 
00325         public int PrintAgentCode()
00326         {
00327             return MCAgency._MC_PrintAgentCode(Agent);
00328         }
00329 
00337         public String RetrieveAgentCode()
00338         {
00339             return MCAgency._MC_RetrieveAgentCode(Agent);
00340         }
00341 
00350         public int TerminateAgent()
00351         {
00352             return MCAgency._MC_TerminateAgent(Agent);
00353         }
00354 
00355         /*public int _MC_CallAgentFunc(IntPtr agent, String funcName, void* returnVal, void* varg);*/
00356         /*public void* _MC_GetAgentExecEngine(IntPtr agent);*/
00357         /*public int _MC_GetAgentReturnData(IntPtr agent, int task_num, void **data, int *dim, int **extent);*/
00358 
00359         /*
00360          * ACL Functions
00361          */
00362 
00375         public int AclPost(MCAclMessage message)
00376         {
00377             return MCAgency._MC_AclPost(Agent, message.AclMsg);
00378         }
00379 
00391         public MCAclMessage AclRetrieve()
00392         {
00393             IntPtr temp = MCAgency._MC_AclRetrieve(Agent);
00394             if (temp == IntPtr.Zero)
00395                 return new MCAclMessage();
00396             else
00397                 return new MCAclMessage(temp);
00398         }
00399 
00410         public MCAclMessage AclWaitRetrieve()
00411         {
00412             IntPtr temp = MCAgency._MC_AclWaitRetrieve(Agent);
00413             if (temp == IntPtr.Zero)
00414                 return new MCAclMessage();
00415             else
00416                 return new MCAclMessage(temp);
00417         }
00418 
00434         public int CallAgentFunc(String funcName, IntPtr retval, IntPtr varg)
00435         {
00436             return MCAgency._MC_CallAgentFunc(Agent, funcName, retval, varg);
00437         }
00438 
00451         public IntPtr GetAgentExecEngine()
00452         {
00453             return MCAgency._MC_GetAgentExecEngine(Agent);
00454         }
00455 
00472         public int GetAgentReturnData(int task_num, IntPtr data, IntPtr dim, IntPtr extent)
00473         {
00474             //return _MC_GetAgentReturnData(IntPtr agent, int task_num, IntPtr data, IntPtr dim, IntPtr extent);
00475             throw new Exception("GetAgentReturnData is not yet implemented!");
00476         }
00477     }
00478 }

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