static void Set(string cls, string state, string[] attributes) { ByteBuffer fbfr = ATMI.tpalloc("FML32", null, 1024); try { TPFBuilder.I.FaddString(ref fbfr, TMIB.TA_OPERATION, "SET"); TPFBuilder.I.FaddString(ref fbfr, TMIB.TA_CLASS, cls); if (state != null) { TPFBuilder.I.FaddString(ref fbfr, TMIB.TA_STATE, state); if (state.Equals("CLEANING")) { TPFBuilder.I.FaddInt(ref fbfr, TMIB.TA_FLAGS, TMIB.QMIB_FORCECLOSE); } } foreach (string attribute in attributes) { int eqPos = attribute.IndexOf('='); string key = attribute.Substring(0, eqPos); string val = attribute.Substring(eqPos + 1); int fieldID = FML32.Fldid(key); TPFBuilder.I.FaddString(ref fbfr, fieldID, val); } try { Console.WriteLine("INFO: Executing " + cls + ".SET(" + state + ", " + ToString(attributes) + ")"); ATMI.tpadmcall(fbfr, ref fbfr, 0); } catch (TPEMIB) { Console.WriteLine("ERROR: " + FML32.ToString(fbfr)); Environment.Exit(1); } } finally { ATMI.tpfree(fbfr); } }
// Receives data from a Conversation and writes it to a FileStream private static void Receive(Conversation conv, FileStream fs) { byte[] bytes = new byte[4096]; int len = 0; ByteBuffer buffer = ATMI.tpalloc("CARRAY", null, 4096); try { while (true) { try { conv.Receive(ref buffer, out len, 0); } catch (TPEV_SVCFAIL) { // A download error occurred throw new IOException(StringUtils.ReadStringBuffer(buffer, len)); } catch (TPEV_SVCSUCC) { // Download complete Console.WriteLine(); return; } Console.Write('.'); // Progress indicator buffer.GetBytes(bytes, 0, len); fs.Write(bytes, 0, len); } } finally { ATMI.tpfree(buffer); } }
public static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: SimpleDequeuer <qspace> <qname>"); Environment.Exit(1); } string qSpace = args[0]; string qName = args[1]; ATMI.tpinit(null); try { ByteBuffer data = ATMI.tpalloc("STRING", null, 512); try { TPQCTL ctl = new TPQCTL(); ctl.flags = ATMI.TPQWAIT; int len; ATMI.tpdequeue(qSpace, qName, ctl, ref data, out len, 0); string message = StringUtils.ReadStringBuffer(data, len); Console.WriteLine("Dequeued '" + message + "' from " + qSpace + "." + qName); } finally { ATMI.tpfree(data); } } finally { ATMI.tpterm(); } }
// Connects to the DOWNLOAD service, passing the name of the file to download in the connect request private static Conversation Connect(string remoteFileName) { ByteBuffer request = StringUtils.NewStringBuffer(remoteFileName); try { return(new Conversation("DOWNLOAD", request, 0, ATMI.TPRECVONLY)); } finally { ATMI.tpfree(request); } }
public static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: UnsolClient <service> <message>"); Environment.Exit(1); } string service = args[0]; string message = args[1]; TPINIT tpinfo = new TPINIT(); tpinfo.cltname = "sample"; ATMI.tpinit(tpinfo); try { ATMI.tpsetunsol(new UnsolHandler(tpunsol)); try { ByteBuffer data = StringUtils.NewStringBuffer(message); try { Console.WriteLine("Sending '" + message + "' to service " + service); int cd = ATMI.tpacall(service, data, 0, 0); WaitForMessages(10); int len; ATMI.tpgetrply(ref cd, ref data, out len, 0); message = StringUtils.ReadStringBuffer(data, len); Console.WriteLine("Returned string is: " + message); } finally { ATMI.tpfree(data); } } finally { ATMI.tpsetunsol(null); } } finally { ATMI.tpterm(); } }
public static void BRDCST_TOUPPER(TPSVCINFO rqst) { ByteBuffer message = StringUtils.NewStringBuffer("Forwarding request to service TOUPPER"); try { ATMI.tpbroadcast(null, null, "sample", message, 0, 0); } finally { ATMI.tpfree(message); } ATMI.tpforward("TOUPPER", rqst.data, rqst.len, 0); }
public static void NOTIFY_TOUPPER(TPSVCINFO rqst) { ByteBuffer message = StringUtils.NewStringBuffer("Your request is forwarded to the TOUPPER service"); try { ATMI.tpnotify(rqst.cltid, message, 0, 0); } finally { ATMI.tpfree(message); } ATMI.tpforward("TOUPPER", rqst.data, rqst.len, 0); }
// Returns a STRING message from a service routine. public static void ReturnReply(int rval, int rcode, string message) { bool returned = false; ByteBuffer reply = StringUtils.NewStringBuffer(message); try { ATMI.tpreturn(ATMI.TPFAIL, rcode, reply, 0, 0); returned = true; } finally { if (!returned) { ATMI.tpfree(reply); } } }
public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: SimpleAsyncClient <message>"); Environment.Exit(1); } string message = args[0]; ATMI.tpinit(null); try { int cd; ByteBuffer sendbuf = StringUtils.NewStringBuffer(message); try { Console.WriteLine("Sending '" + message + "' to service TOUPPER"); cd = ATMI.tpacall("TOUPPER", sendbuf, 0, 0); } finally { ATMI.tpfree(sendbuf); } ByteBuffer rcvbuf = ATMI.tpalloc("STRING", null, 256); try { int rcvlen; ATMI.tpgetrply(ref cd, ref rcvbuf, out rcvlen, 0); message = StringUtils.ReadStringBuffer(rcvbuf, rcvlen); Console.WriteLine("Returned string is: " + message); } finally { ATMI.tpfree(rcvbuf); } } finally { ATMI.tpterm(); } }
public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: SimpleClient <message>"); Environment.Exit(1); } string message = args[0]; ATMI.tpinit(null); try { byte[] bytes = Encoding.Default.GetBytes(message); int sendlen = bytes.Length + 1; // One byte extra for terminating zero ByteBuffer sendbuf = ATMI.tpalloc("STRING", null, sendlen); try { ByteBuffer rcvbuf = ATMI.tpalloc("STRING", null, sendlen); try { sendbuf.PutBytes(bytes); sendbuf.PutByte(bytes.Length, 0); // Terminating zero int rcvlen; ATMI.tpcall("TOUPPER", sendbuf, 0, ref rcvbuf, out rcvlen, 0); rcvbuf.GetBytes(bytes); Console.WriteLine("Returned string is: " + Encoding.Default.GetString(bytes)); } finally { ATMI.tpfree(rcvbuf); } } finally { ATMI.tpfree(sendbuf); } } finally { ATMI.tpterm(); } }
public static void Main(string[] args) { ATMI.tpinit(null); try { ByteBuffer reply = ATMI.tpalloc("STRING", null, 1024); try { int len; ATMI.tpcall("TEST", null, 0, ref reply, out len, 0); byte[] bytes = new byte[len - 1]; reply.GetBytes(bytes); string message = Encoding.Default.GetString(bytes); Console.WriteLine(message); } finally { ATMI.tpfree(reply); } } finally { ATMI.tpterm(); } }
public static void Main(string[] args) { if ((args.Length < 3) || (args.Length > 4)) { Console.WriteLine("Usage: SimpleEnqueuer <qspace> <qname> <message> [<replyq>]"); Environment.Exit(1); } string qSpace = args[0]; string qName = args[1]; string message = args[2]; string replyQ = (args.Length < 4) ? null : args[3]; ATMI.tpinit(null); try { ByteBuffer data = StringUtils.NewStringBuffer(message); try { TPQCTL ctl = new TPQCTL(); ctl.flags = ATMI.TPNOFLAGS; if (replyQ != null) { ctl.flags = ctl.flags | ATMI.TPQREPLYQ; ctl.replyqueue = replyQ; } ATMI.tpenqueue(qSpace, qName, ctl, data, 0, 0); Console.WriteLine("Enqueued '" + message + "' in " + qSpace + "." + qName); } finally { ATMI.tpfree(data); } } finally { ATMI.tpterm(); } }
public static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: SimpleFML32Client <field>=<value> ..."); Environment.Exit(1); } ATMI.tpinit(null); try { ByteBuffer fbfr = ATMI.tpalloc("FML32", null, 512); try { foreach (string arg in args) { int eqPos = arg.IndexOf('='); string key = arg.Substring(0, eqPos); string val = arg.Substring(eqPos + 1); int fldid = FML32.Fldid(key); TPFBuilder.I.FaddString(ref fbfr, fldid, val); } int len; ATMI.tpcall("FML32_TOUPPER", fbfr, 0, ref fbfr, out len, 0); Console.WriteLine("Returned FML32 buffer is: " + FML32.ToString(fbfr)); } finally { ATMI.tpfree(fbfr); } } finally { ATMI.tpterm(); } }
public static void PUBLISH_TIME(TPSVCINFO svcinfo) { ByteBuffer message = StringUtils.NewStringBuffer("It is now " + DateTime.Now); try { ATMI.tppost("TIME", message, 0, 0); } catch (TPENOENT) { // EventBroker not running yet (ignored) } finally { ATMI.tpfree(message); } Thread.Sleep(1000); ATMI.tpacall("PUBLISH_TIME", null, 0, ATMI.TPNOREPLY); ATMI.tpreturn(ATMI.TPSUCCESS, 0, null, 0, 0); }
// Reads data from a FileStream and sends it across a conversational connection. private static void Send(FileStream fs, int cd) { byte[] bytes = new byte[4096]; ByteBuffer buffer = ATMI.tpalloc("CARRAY", null, 4096); try { while (true) { int len = fs.Read(bytes, 0, 4096); if (len == 0) { // End of file return; } buffer.PutBytes(bytes, 0, len); ATMI.tpsend(cd, buffer, len, 0); } } finally { ATMI.tpfree(buffer); } }