last ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,967 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>راهنمای کامل ساخت، تست و دیباگ افزونه Azure DevOps با iFrame</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title { text-align: center; position: relative; z-index: 1; padding: 20px 0; }
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 { font-size: 26px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; line-height: 1.5; }
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #feb2b2;
|
||||
border-right: 4px solid var(--danger);
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white; }
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.step-list { list-style: none; padding: 0; counter-reset: step; }
|
||||
|
||||
.step-list > li {
|
||||
counter-increment: step;
|
||||
position: relative;
|
||||
padding: 22px 60px 22px 22px;
|
||||
margin-bottom: 18px;
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.step-list > li::before {
|
||||
content: counter(step);
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 22px;
|
||||
width: 30px; height: 30px;
|
||||
background: var(--primary);
|
||||
color: var(--accent);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.step-list h5 { font-size: 15px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
|
||||
.step-list p { font-size: 13px; color: var(--text-muted); text-indent: 0 !important; margin-bottom: 8px !important; text-align: right; }
|
||||
.step-list ul { font-size: 13px; color: var(--text-muted); padding-right: 20px; }
|
||||
|
||||
code {
|
||||
background: #edf2f7;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
color: #c53030;
|
||||
direction: ltr;
|
||||
unicode-bidi: embed;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: #1a202c;
|
||||
color: #e2e8f0;
|
||||
padding: 16px 20px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin: 12px 0;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
.page-info {
|
||||
text-align: center;
|
||||
padding: 15px;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
border-top: 1px solid var(--border);
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
@media print {
|
||||
body { background: white; padding: 0; }
|
||||
.document-container { box-shadow: none; border-radius: 0; }
|
||||
.section { page-break-inside: avoid; }
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.document-body { padding: 25px 20px; }
|
||||
.document-header { padding: 30px 20px; }
|
||||
.header-top { flex-direction: column; gap: 15px; }
|
||||
.doc-meta { text-align: center; }
|
||||
.document-title h1 { font-size: 20px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge">
|
||||
<div class="company-logo"></div>
|
||||
</div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: DEV-GUIDE-1405-003</div>
|
||||
<div>نسخه: ۲.۰</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: داخلی — تیم توسعه</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="document-title">
|
||||
<span class="label">END-TO-END DEVELOPMENT GUIDE</span>
|
||||
<h1>راهنمای کامل ساخت، تست و دیباگ افزونه Azure DevOps</h1>
|
||||
<h2>از SDK و webpack تا بارگذاری iFrame در محیط لوکال و واکشی دادهها</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف این مستند:</strong><br>
|
||||
این راهنما یک مسیر کامل و گامبهگام از صفر تا اجرای موفق یک افزونه Azure DevOps در محیط لوکال است. شما یاد میگیرید چگونه SDK را به شکل صحیح مقداردهی کنید (و خطای <code>AZDevOps is not defined</code> را برای همیشه حل کنید)، webpack را با HTTPS پیکربندی کنید، افزونه را از طریق <code>baseUri</code> در iFrame بارگذاری کنید، و اطلاعات واقعی پروژه را از SDK دریافت نمایید. تمام کدهای نمونه و دستورات در جای خود قرار دارند تا مستقیماً قابل اجرا باشند.
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 1 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>پیشنیازها و ابزارهای محیط توسعه</h3>
|
||||
<div class="subtitle">Prerequisites & Toolchain</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>ابزارهای زیر را نصب کنید. نسخههای پیشنهادی در جدول آمده است:</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ابزار</th>
|
||||
<th>نسخه پیشنهادی</th>
|
||||
<th>دلیل نیاز</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>Node.js</strong></td>
|
||||
<td>۲۰ یا بالاتر</td>
|
||||
<td>محیط اجرای npm و webpack. عدم تطابق نسخه باعث خطاهای عجیب میشود.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Visual Studio Code</strong></td>
|
||||
<td>آخرین نسخه</td>
|
||||
<td>محیط توسعه اصلی و دیباگر یکپارچه.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Firefox</strong></td>
|
||||
<td>آخرین نسخه</td>
|
||||
<td>دیباگر Chrome از iFrame پشتیبانی نمیکند؛ Firefox و افزونه Debugger for Firefox ضروری است[reference:0].</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Debugger for Firefox</strong> (افزونه VS Code)</td>
|
||||
<td>آخرین نسخه</td>
|
||||
<td>اتصال Breakpoint در VS Code به کد داخل iFrame.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>tfx-cli</strong></td>
|
||||
<td>آخرین نسخه</td>
|
||||
<td>بستهبندی و انتشار افزونه. نصب با <code>npm i -g tfx-cli</code>[reference:1].</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>📦 نصب سریع:</strong>
|
||||
<pre>npm install -g tfx-cli
|
||||
npm install -g webpack webpack-cli webpack-dev-server</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 2 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>ساختار نهایی پروژه</h3>
|
||||
<div class="subtitle">Project Structure</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>ساختار پیشنهادی که در ادامه این مستند بر اساس آن پیش میرویم به شکل زیر است. این ساختار با نمونه رسمی مایکروسافت برای Hot Reload و Debug همخوانی کامل دارد[reference:2]:</p>
|
||||
|
||||
<pre>xUiExt/
|
||||
├── src/
|
||||
│ ├── index.ts ← نقطه ورود افزونه (SDK را init میکند)
|
||||
│ └── index.html ← قالب HTML افزونه (توسط CopyWebpackPlugin کپی میشود)
|
||||
├── configs/
|
||||
│ ├── dev.json ← override مخصوص توسعه (baseUri = localhost)
|
||||
│ └── release.json ← override مخصوص انتشار
|
||||
├── dist/ ← خروجی webpack (خودکار)
|
||||
├── webpack.config.js
|
||||
├── vss-extension.json ← manifest اصلی
|
||||
├── package.json
|
||||
└── tsconfig.json ← در صورت استفاده از TypeScript</pre>
|
||||
|
||||
<div class="highlight-box">
|
||||
<strong>💡 چرا <code>configs/dev.json</code>؟</strong> مقدار <code>baseUri</code> نباید مستقیماً در manifest اصلی نوشته شود. با استفاده از فایل override و پارامتر <code>--overrides-file</code>، محیط توسعه و محیط نهایی از هم جدا میمانند و هنگام بستهبندی نهایی، خودکار حذف میشود[reference:3].
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 3 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۳</div>
|
||||
<div class="section-title">
|
||||
<h3>راهاندازی پروژه و نصب وابستگیها</h3>
|
||||
<div class="subtitle">Project Initialization & Dependencies</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<ol class="step-list">
|
||||
<li>
|
||||
<h5>ایجاد پروژه Node.js</h5>
|
||||
<p>در پوشه <code>xUiExt</code> دستور زیر را اجرا کنید:</p>
|
||||
<pre>npm init -y</pre>
|
||||
</li>
|
||||
<li>
|
||||
<h5>نصب SDK و وابستگیهای توسعه</h5>
|
||||
<p>SDK را از npm نصب کنید (روش توصیهشده برای جلوگیری از خطای <code>AZDevOps is not defined</code>):</p>
|
||||
<pre>npm install azure-devops-extension-sdk --save
|
||||
npm install --save-dev webpack webpack-cli webpack-dev-server typescript ts-loader copy-webpack-plugin</pre>
|
||||
<p>اگر از JavaScript ساده استفاده میکنید، <code>typescript</code> و <code>ts-loader</code> را حذف کنید.</p>
|
||||
</li>
|
||||
<li>
|
||||
<h5>افزودن اسکریپتهای کاربردی به package.json</h5>
|
||||
<p>در فایل <code>package.json</code>، بخش <code>scripts</code> را به شکل زیر ویرایش کنید:</p>
|
||||
<pre>"scripts": {
|
||||
"start:dev": "webpack serve --mode development --config webpack.config.js",
|
||||
"build:dev": "webpack --mode development",
|
||||
"package:dev": "tfx extension create --manifest-globs vss-extension.json --overrides-file configs/dev.json"
|
||||
}</pre>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 4 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۴</div>
|
||||
<div class="section-title">
|
||||
<h3>یکپارچهسازی صحیح SDK (حل قطعی خطای AZDevOps is not defined)</h3>
|
||||
<div class="subtitle">SDK Integration & Initialization Pattern</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>خطای <code>AZDevOps is not defined</code> ریشه در دو اشتباه رایج دارد: (۱) بارگذاری SDK با تگ اسکریپت ساده و انتظار وجود یک متغیر سراسری، و (۲) اجرای کد افزونه پیش از آماده شدن SDK. راهحل استاندارد و پایدار، استفاده از <strong>بسته npm</strong> به همراه الگوی <code>init → ready → getService</code> است.</p>
|
||||
|
||||
<div class="danger-box">
|
||||
<strong>❌ روش اشتباه (منشاء خطا):</strong>
|
||||
<pre><script src="./js/SDK.min.js"></script>
|
||||
<script src="./js/app.js"></script></pre>
|
||||
<p style="text-indent:0; margin-top:8px; font-size:13px;">در این حالت، <code>app.js</code> بلافاصله اجرا میشود و به متغیری به نام <code>AZDevOps</code> دسترسی ندارد، زیرا SDK به این شکل متغیر سراسری تعریف نمیکند.</p>
|
||||
</div>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ روش صحیح (استفاده از npm و الگوی رسمی):</strong>
|
||||
</div>
|
||||
|
||||
<h4 style="color: var(--primary); margin: 18px 0 8px;">الف) فایل <code>src/index.ts</code> (یا <code>index.js</code>)</h4>
|
||||
<p>SDK را import کرده و دقیقاً به این ترتیب مقداردهی کنید. الگوی زیر در تمام نمونههای رسمی مایکروسافت رعایت شده است[reference:4]:</p>
|
||||
|
||||
<pre>// src/index.ts
|
||||
import * as SDK from "azure-devops-extension-sdk";
|
||||
import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
|
||||
|
||||
async function initialize() {
|
||||
// ۱. مقداردهی اولیه — همیشه اولین قدم
|
||||
await SDK.init();
|
||||
|
||||
// ۲. انتظار برای آماده شدن SDK — قبل از هر فراخوانی دیگر
|
||||
await SDK.ready();
|
||||
|
||||
// ۳. اکنون امن است که سرویسها را فراخوانی کنید
|
||||
const projectService = await SDK.getService<IProjectPageService>(
|
||||
CommonServiceIds.ProjectPageService
|
||||
);
|
||||
const project = await projectService.getProject();
|
||||
|
||||
// ۴. نمایش نتیجه در صفحه
|
||||
const el = document.getElementById("result");
|
||||
if (el) {
|
||||
el.textContent = `پروژه جاری: ${project?.name ?? "نامشخص"}`;
|
||||
}
|
||||
|
||||
// ۵. اطلاعدادن به میزبان که بارگذاری کامل شد
|
||||
SDK.notifyLoadSucceeded();
|
||||
}
|
||||
|
||||
initialize().catch((err) => {
|
||||
console.error("خطا در راهاندازی افزونه:", err);
|
||||
const el = document.getElementById("result");
|
||||
if (el) el.textContent = "خطا در اتصال به Azure DevOps";
|
||||
});</pre>
|
||||
|
||||
<div class="warning-box">
|
||||
<strong>⚠️ نکته حیاتی:</strong> هرگز <code>SDK.getService</code> را قبل از <code>await SDK.ready()</code> فراخوانی نکنید. تابع <code>getService</code> بهطور خودکار منتظر <code>ready()</code> میماند، اما صریح نوشتن آن باعث میشود ترتیب اجرا شفاف و خطاها قابلردیابی باشد[reference:5].
|
||||
</div>
|
||||
|
||||
<h4 style="color: var(--primary); margin: 18px 0 8px;">ب) فایل <code>src/index.html</code></h4>
|
||||
<p>این فایل بهعنوان قالب HTML افزونه استفاده میشود. تگ اسکریپت SDK را حذف کنید؛ webpack خودش باندل را تزریق میکند:</p>
|
||||
|
||||
<pre><!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>افزونه من</title>
|
||||
<style>
|
||||
body { font-family: 'Segoe UI', sans-serif; padding: 20px; }
|
||||
#result { margin-top: 15px; font-weight: bold; color: #107c10; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>👋 سلام از افزونه من!</h2>
|
||||
<p>اطلاعات پروژه جاری:</p>
|
||||
<div id="result">در حال اتصال...</div>
|
||||
</body>
|
||||
</html></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 5 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۵</div>
|
||||
<div class="section-title">
|
||||
<h3>پیکربندی webpack با HTTPS و Hot Reload</h3>
|
||||
<div class="subtitle">Webpack Configuration for Local iFrame Testing</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>فایل <code>webpack.config.js</code> باید سه کار انجام دهد: باندل کردن کد، کپی کردن HTML به <code>dist</code>، و اجرای سرور HTTPS روی پورت ۳۰۰۰. پیکربندی زیر بر اساس نمونه رسمی Hot Reload مایکروسافت تنظیم شده است[reference:6][reference:7]:</p>
|
||||
|
||||
<pre>const path = require("path");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
devtool: "inline-source-map", // برای دیباگ بهتر
|
||||
|
||||
entry: "./src/index.ts", // یا "./src/index.js"
|
||||
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "bundle.js",
|
||||
publicPath: "/dist/", // حیاتی برای Hot Reload
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: [".ts", ".js"],
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
use: "ts-loader",
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [{ from: "**/*.html", context: "src" }],
|
||||
}),
|
||||
],
|
||||
|
||||
devServer: {
|
||||
server: { type: "https" }, // HTTPS الزامی برای iFrame
|
||||
port: 3000,
|
||||
hot: true,
|
||||
static: {
|
||||
directory: path.resolve(__dirname, "dist"),
|
||||
publicPath: "/dist/",
|
||||
},
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
},
|
||||
};</pre>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>🔍 چرا <code>publicPath: "/dist/"</code>؟</strong> بهطور پیشفرض webpack فایلها را در ریشه <code>localhost:3000</code> سرو میکند، اما افزونه به دنبال فایلها در مسیر <code>dist</code> است. تنظیم <code>publicPath</code> روی <code>/dist/</code> این ناهماهنگی را حل میکند و Hot Reload را فعال نگه میدارد[reference:8].
|
||||
</div>
|
||||
|
||||
<p>اگر از JavaScript خالص استفاده میکنید (بدون TypeScript)، بخش <code>module.rules</code> و <code>ts-loader</code> را حذف کنید و <code>entry</code> را به <code>"./src/index.js"</code> تغییر دهید.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 6 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۶</div>
|
||||
<div class="section-title">
|
||||
<h3>فایل Manifest و تنظیم baseUri برای iFrame</h3>
|
||||
<div class="subtitle">vss-extension.json & baseUri Override</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>فایل <code>vss-extension.json</code> هویت افزونه را تعریف میکند. نکته کلیدی برای تست لوکال، تنظیم <code>baseUri</code> از طریق فایل override است، نه در manifest اصلی.</p>
|
||||
|
||||
<h4 style="color: var(--primary); margin-bottom: 8px;">الف) <code>vss-extension.json</code> (بدون baseUri)</h4>
|
||||
<pre>{
|
||||
"manifestVersion": 1,
|
||||
"id": "my-local-extension",
|
||||
"publisher": "my-publisher",
|
||||
"version": "1.0.0",
|
||||
"name": "My Local Extension",
|
||||
"description": "تست افزونه در محیط لوکال",
|
||||
"targets": [{ "id": "Microsoft.VisualStudio.Services" }],
|
||||
"icons": { "default": "images/extension-icon.png" },
|
||||
"contributions": [
|
||||
{
|
||||
"id": "my-hub",
|
||||
"type": "ms.vss-web.hub",
|
||||
"targets": ["ms.vss-web.project-hub-group"],
|
||||
"properties": {
|
||||
"name": "افزونه من",
|
||||
"uri": "dist/index.html"
|
||||
}
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
{ "path": "dist", "addressable": true }
|
||||
]
|
||||
}</pre>
|
||||
|
||||
<div class="highlight-box">
|
||||
<strong>📌 توجه:</strong> مقدار <code>uri</code> روی <code>"dist/index.html"</code> تنظیم شده تا با خروجی webpack همخوان باشد. فایلهای داخل <code>dist</code> با <code>"addressable": true</code> قابل دسترسی میشوند.
|
||||
</div>
|
||||
|
||||
<h4 style="color: var(--primary); margin: 18px 0 8px;">ب) <code>configs/dev.json</code> (فایل Override مخصوص توسعه)</h4>
|
||||
<p>این فایل فقط هنگام ساخت نسخه توسعه استفاده میشود و <code>baseUri</code> را به سرور لوکال اشاره میدهد[reference:9]:</p>
|
||||
|
||||
<pre>{
|
||||
"id": "my-local-extension-dev",
|
||||
"public": false,
|
||||
"baseUri": "https://localhost:3000"
|
||||
}</pre>
|
||||
|
||||
<p>هنگام بستهبندی نسخه توسعه، از دستور زیر استفاده کنید:</p>
|
||||
<pre>npm run package:dev</pre>
|
||||
<p>یا مستقیماً:</p>
|
||||
<pre>tfx extension create --manifest-globs vss-extension.json --overrides-file configs/dev.json</pre>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ نتیجه:</strong> Azure DevOps منابع افزونه را بهجای بسته VSIX، از <code>https://localhost:3000</code> بارگذاری میکند. این یعنی هر تغییری در کد، بلافاصله در iFrame منعکس میشود، بدون نیاز به بستهبندی مجدد[reference:10].
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 7 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۷</div>
|
||||
<div class="section-title">
|
||||
<h3>اجرا و بارگذاری در iFrame — گامبهگام</h3>
|
||||
<div class="subtitle">Running the Dev Server & Loading in Azure DevOps</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<ol class="step-list">
|
||||
<li>
|
||||
<h5>اجرای سرور توسعه</h5>
|
||||
<p>در پوشه پروژه دستور زیر را اجرا کنید:</p>
|
||||
<pre>npm run start:dev</pre>
|
||||
<p>خروجی باید مشابه این باشد:</p>
|
||||
<pre><i> [webpack-dev-server] Project is running at:
|
||||
<i> [webpack-dev-server] Loopback: https://localhost:3000/, https://[::1]:3000/</pre>
|
||||
</li>
|
||||
<li>
|
||||
<h5>پذیرش گواهی HTTPS در مرورگر</h5>
|
||||
<p>آدرس <code>https://localhost:3000/dist/index.html</code> را یک بار مستقیماً در Firefox باز کنید و هشدار گواهی خودامضا (Self-Signed) را بپذیرید. اگر این کار را نکنید، iFrame در Azure DevOps بارگذاری نخواهد شد.</p>
|
||||
</li>
|
||||
<li>
|
||||
<h5>بستهبندی و نصب نسخه توسعه</h5>
|
||||
<p>فایل VSIX مخصوص توسعه را بسازید:</p>
|
||||
<pre>npm run package:dev</pre>
|
||||
<p>سپس در Azure DevOps به <strong>Organization Settings → Extensions</strong> بروید، گزینه <strong>Shared</strong> یا <strong>Browse Marketplace</strong> را انتخاب کنید و فایل <code>.vsix</code> تولیدشده را آپلود و نصب نمایید.</p>
|
||||
</li>
|
||||
<li>
|
||||
<h5>فعالسازی دسترسی به شبکه داخلی (در صورت نیاز)</h5>
|
||||
<p>اگر مرورگر iFrame را بهدلیل Private Network Access مسدود کرد، در <strong>Organization Settings → Policies</strong> گزینه <strong>“Allow extensions to access local network resources”</strong> را موقتاً فعال کنید[reference:11].</p>
|
||||
</li>
|
||||
<li>
|
||||
<h5>مشاهده افزونه در iFrame</h5>
|
||||
<p>به پروژه Azure DevOps خود بروید. در منوی Hubها، گزینه «افزونه من» را انتخاب کنید. iFrame باز میشود و صفحه شما از سرور لوکال بارگذاری میگردد. اکنون باید اطلاعات پروژه را ببینید.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 8 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۸</div>
|
||||
<div class="section-title">
|
||||
<h3>دیباگ Breakpoint در iFrame با VS Code و Firefox</h3>
|
||||
<div class="subtitle">Debugging Inside the iFrame</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>دیباگر Chrome در VS Code از iFrame پشتیبانی نمیکند؛ بنابراین از Firefox و افزونه Debugger for Firefox استفاده میکنیم[reference:12].</p>
|
||||
|
||||
<p>یک فایل <code>.vscode/launch.json</code> با محتوای زیر بسازید:</p>
|
||||
|
||||
<pre>{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Firefox against Azure DevOps",
|
||||
"type": "firefox",
|
||||
"request": "launch",
|
||||
"url": "https://dev.azure.com/{your-org}/{your-project}",
|
||||
"reAttach": true,
|
||||
"pathMappings": [
|
||||
{
|
||||
"url": "webpack:///",
|
||||
"path": "${workspaceFolder}/"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}</pre>
|
||||
|
||||
<p>سپس <code>F5</code> را بزنید (مطمئن شوید <code>npm run start:dev</code> در حال اجراست). Breakpointها در فایل <code>src/index.ts</code> فعال میشوند و میتوانید متغیرها را در VS Code بررسی کنید[reference:13].</p>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>💡 گزینه جایگزین سریع:</strong> اگر نیازی به Breakpoint در VS Code ندارید، کافی است در کد خود بنویسید <code>debugger;</code>. با باز کردن DevTools مرورگر (F12) و انتخاب فریم iFrame افزونه از منوی context، اجرا در آن خط متوقف میشود.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 9 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۹</div>
|
||||
<div class="section-title">
|
||||
<h3>واکشی دادههای بیشتر از SDK</h3>
|
||||
<div class="subtitle">Fetching Data: User, Context & Extension Data</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>پس از <code>await SDK.ready()</code>، میتوانید به طیف وسیعی از دادهها دسترسی داشته باشید. چند نمونه پرکاربرد:</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>داده</th>
|
||||
<th>کد</th>
|
||||
<th>توضیح</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>اطلاعات کاربر جاری</td>
|
||||
<td><code>SDK.getUser()</code></td>
|
||||
<td>نام نمایشی، شناسه و ایمیل کاربر.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Context کامل افزونه</td>
|
||||
<td><code>SDK.getExtensionContext()</code></td>
|
||||
<td>شامل project، team، hub و سایر اطلاعات زمینه.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>اطلاعات پروژه</td>
|
||||
<td><code>SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService)</code></td>
|
||||
<td>سرویس رسمی برای دریافت پروژه جاری[reference:14].</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>دادههای ذخیرهشده افزونه</td>
|
||||
<td><code>SDK.getService<IExtensionDataService>(CommonServiceIds.ExtensionDataService)</code></td>
|
||||
<td>برای ذخیره و بازیابی تنظیمات افزونه[reference:15].</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>مثال کامل برای دریافت اطلاعات کاربر و پروژه بهصورت همزمان:</p>
|
||||
|
||||
<pre>async function fetchData() {
|
||||
await SDK.init();
|
||||
await SDK.ready();
|
||||
|
||||
const user = SDK.getUser();
|
||||
const projectService = await SDK.getService<IProjectPageService>(
|
||||
CommonServiceIds.ProjectPageService
|
||||
);
|
||||
const project = await projectService.getProject();
|
||||
|
||||
document.getElementById("result")!.innerHTML = `
|
||||
<p>کاربر: <strong>${user.displayName}</strong></p>
|
||||
<p>پروژه: <strong>${project?.name}</strong></p>
|
||||
`;
|
||||
|
||||
SDK.notifyLoadSucceeded();
|
||||
}</pre>
|
||||
|
||||
<div class="warning-box">
|
||||
<strong>⚠️ محدودیت iFrame:</strong> برخی APIهای مرورگر (مانند <code>getDisplayMedia</code> برای ضبط صفحه) در iFrame سندباکس مسدود هستند. اگر افزونه شما به چنین قابلیتی نیاز دارد، آن را در یک Pop-up سطح بالا باز کنید، نه داخل iFrame.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- SECTION 10 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱۰</div>
|
||||
<div class="section-title">
|
||||
<h3>رفع اشکالات رایج</h3>
|
||||
<div class="subtitle">Troubleshooting Common Errors</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>خطا</th>
|
||||
<th>علت</th>
|
||||
<th>راهحل</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>AZDevOps is not defined</code></td>
|
||||
<td>بارگذاری SDK با تگ اسکریپت و انتظار متغیر سراسری</td>
|
||||
<td>از بسته npm و الگوی <code>init → ready → getService</code> استفاده کنید (بخش ۴).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>Can't resolve './src'</code></td>
|
||||
<td>webpack فایل پیکربندی را پیدا نکرده و به پیشفرض برگشته</td>
|
||||
<td>با <code>--config ./webpack.config.js</code> اجرا کنید و وجود فایل را بررسی نمایید.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>Unknown option '--https'</code></td>
|
||||
<td>حذف فلگ <code>--https</code> در webpack-cli جدید</td>
|
||||
<td>از <code>devServer: { server: { type: 'https' } }</code> در فایل پیکربندی استفاده کنید.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>iFrame بارگذاری نمیشود (صفحه سفید)</td>
|
||||
<td>عدم پذیرش گواهی HTTPS لوکال، یا فعال نبودن دسترسی شبکه داخلی</td>
|
||||
<td>ابتدا <code>https://localhost:3000/dist/index.html</code> را در مرورگر باز و گواهی را بپذیرید؛ سپس سیاست Private Network Access را فعال کنید[reference:16].</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>SDK.getService</code> مقدار <code>undefined</code> برمیگرداند</td>
|
||||
<td>فراخوانی قبل از <code>ready()</code> یا عدم انتظار برای Promise</td>
|
||||
<td>همیشه <code>await SDK.ready()</code> را قبل از <code>getService</code> قرار دهید و خروجی را <code>await</code> کنید[reference:17].</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Hot Reload کار نمیکند</td>
|
||||
<td>تنظیم نبودن <code>publicPath</code> روی <code>/dist/</code></td>
|
||||
<td>در <code>output</code>، مقدار <code>publicPath: "/dist/"</code> را تنظیم کنید[reference:18].</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- CONCLUSION -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">✓</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست نهایی</h3>
|
||||
<div class="subtitle">Final Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 مسیر کامل در یک نگاه</h3>
|
||||
<p>۱. SDK را از npm نصب و با الگوی <code>await SDK.init(); await SDK.ready();</code> مقداردهی کنید.</p>
|
||||
<p>۲. webpack را با <code>server: { type: 'https' }</code>، <code>publicPath: "/dist/"</code> و <code>CopyWebpackPlugin</code> پیکربندی کنید.</p>
|
||||
<p>۳. <code>baseUri</code> را در <code>configs/dev.json</code> روی <code>https://localhost:3000</code> تنظیم کنید.</p>
|
||||
<p>۴. سرور را با <code>npm run start:dev</code> اجرا کنید و گواهی HTTPS را در مرورگر بپذیرید.</p>
|
||||
<p>۵. VSIX توسعه را با <code>npm run package:dev</code> بسازید و در سازمان آپلود کنید.</p>
|
||||
<p>۶. با Firefox + Debugger for Firefox در VS Code، Breakpoint بگذارید و دادهها را از SDK واکشی کنید.</p>
|
||||
</div>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✅ چکلیست قبل از شروع:</strong>
|
||||
<ul style="padding-right: 20px; margin-top: 8px; font-size: 13px;">
|
||||
<li>Node.js نسخه ۲۰ یا بالاتر نصب است.</li>
|
||||
<li>Firefox و افزونه Debugger for Firefox در VS Code نصب هستند.</li>
|
||||
<li>فایل <code>src/index.html</code> هیچ تگ <code><script src="./js/SDK.min.js"></code> ندارد.</li>
|
||||
<li><code>baseUri</code> در manifest اصلی وجود ندارد و فقط در <code>configs/dev.json</code> تعریف شده است.</li>
|
||||
<li>پورت ۳۰۰۰ آزاد است (در غیر این صورت آن را در <code>webpack.config.js</code> و <code>dev.json</code> همزمان تغییر دهید).</li>
|
||||
<li>آدرس <code>https://localhost:3000/dist/index.html</code> در مرورگر بدون خطا باز میشود.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>📚 منابع رسمی برای مطالعه بیشتر:</strong>
|
||||
<ul style="padding-right: 20px; margin-top: 8px; font-size: 13px;">
|
||||
<li>مخزن نمونه Hot Reload و Debug مایکروسافت: <code>github.com/microsoft/azure-devops-extension-hot-reload-and-debug</code>[reference:19]</li>
|
||||
<li>مخزن نمونه رسمی SDK: <code>github.com/microsoft/azure-devops-extension-sample</code></li>
|
||||
<li>مستندات SDK: <code>learn.microsoft.com/azure/devops/extend/develop/using-the-sdk</code></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info">
|
||||
این مستند برای استفاده داخلی تیم توسعه تهیه شده است. تنظیمات امنیتی سازمان (مانند دسترسی به شبکه داخلی) باید پس از اتمام تست به حالت اولیه بازگردانده شود.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">راهنمای جامع توسعه و تست افزونه Azure DevOps — نسخه ۲.۰</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>آبان ۱۴۰۵ | طبقهبندی: داخلی — تیم توسعه</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,349 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: Lang/GlobalVariable.mqh |
|
||||
//| This file is part of the mql4-lib project: |
|
||||
//| https://github.com/dingmaotu/mql4-lib |
|
||||
//| |
|
||||
//| Copyright 2017 Li Ding <dingmaotu@126.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
//+------------------------------------------------------------------+
|
||||
//| Encapsulates global variable functions |
|
||||
//+------------------------------------------------------------------+
|
||||
class GlobalVariable
|
||||
{
|
||||
public:
|
||||
static int total()
|
||||
{
|
||||
return GlobalVariablesTotal();
|
||||
}
|
||||
static string name(int index)
|
||||
{
|
||||
return GlobalVariableName(index);
|
||||
}
|
||||
static void flush()
|
||||
{
|
||||
GlobalVariablesFlush();
|
||||
}
|
||||
|
||||
static bool exists(string name)
|
||||
{
|
||||
return GlobalVariableCheck(name);
|
||||
}
|
||||
static datetime lastAccess(string name)
|
||||
{
|
||||
return GlobalVariableTime(name);
|
||||
}
|
||||
|
||||
static bool makeTemp(string name)
|
||||
{
|
||||
return GlobalVariableTemp(name);
|
||||
}
|
||||
static double get(string name)
|
||||
{
|
||||
return GlobalVariableGet(name);
|
||||
}
|
||||
static bool get(string name, double &value)
|
||||
{
|
||||
return (bool)GlobalVariableGet(name, value);
|
||||
}
|
||||
static bool set(string name, double value)
|
||||
{
|
||||
return (bool)GlobalVariableSet(name, value);
|
||||
}
|
||||
static bool setOn(string name, double value, double check)
|
||||
{
|
||||
return GlobalVariableSetOnCondition(name, value, check);
|
||||
}
|
||||
|
||||
static bool remove(string name)
|
||||
{
|
||||
return (bool)GlobalVariableDel(name);
|
||||
}
|
||||
static bool removeAll(string prefix = NULL, datetime before = 0)
|
||||
{
|
||||
return (bool)GlobalVariablesDeleteAll(prefix, before);
|
||||
}
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| TempVar is a variable whose life time is the same as the program |
|
||||
//+------------------------------------------------------------------+
|
||||
class TempVar
|
||||
{
|
||||
private:
|
||||
string m_name;
|
||||
bool m_owned;
|
||||
|
||||
public:
|
||||
TempVar(string name, bool create = false) : m_name(name), m_owned(create)
|
||||
{
|
||||
if (create)
|
||||
{
|
||||
GlobalVariable::makeTemp(name);
|
||||
}
|
||||
}
|
||||
~TempVar()
|
||||
{
|
||||
if (m_owned && isValid())
|
||||
{
|
||||
GlobalVariable::remove(m_name);
|
||||
}
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return GlobalVariable::exists(m_name);
|
||||
}
|
||||
string getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
bool set(double value)
|
||||
{
|
||||
return GlobalVariable::set(m_name, value);
|
||||
}
|
||||
double get() const
|
||||
{
|
||||
return GlobalVariable::get(m_name);
|
||||
}
|
||||
bool setOn(double value, double check)
|
||||
{
|
||||
return GlobalVariable::setOn(m_name, value, check);
|
||||
}
|
||||
datetime lastAccess() const
|
||||
{
|
||||
return GlobalVariable::lastAccess(m_name);
|
||||
}
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
class AtomicVar : public TempVar
|
||||
{
|
||||
public:
|
||||
AtomicVar(string name, long initial, bool create = false) : TempVar(name, create)
|
||||
{
|
||||
set(initial);
|
||||
}
|
||||
long increment(long by = 1);
|
||||
long decrement(long by = 1)
|
||||
{
|
||||
return increment(-by);
|
||||
}
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
long AtomicVar::increment(long by)
|
||||
{
|
||||
bool success = false;
|
||||
long value;
|
||||
do
|
||||
{
|
||||
value = (long)get();
|
||||
success = setOn(value + by, value);
|
||||
} while (!success && !IsStopped());
|
||||
return (value + by);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
class Semaphore
|
||||
{
|
||||
private:
|
||||
TempVar m_var;
|
||||
|
||||
public:
|
||||
Semaphore(string name, long initial = 0);
|
||||
bool isValid() const
|
||||
{
|
||||
return m_var.isValid();
|
||||
}
|
||||
bool acquire();
|
||||
void release();
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
Semaphore::Semaphore(string name, long initial)
|
||||
: m_var(name, initial != 0)
|
||||
{
|
||||
if (initial != 0)
|
||||
{
|
||||
m_var.set(initial);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Semaphore::acquire(void)
|
||||
{
|
||||
bool success = false;
|
||||
do
|
||||
{
|
||||
long value = (long)m_var.get();
|
||||
if (value == 0)
|
||||
return false;
|
||||
success = m_var.setOn(value - 1, value);
|
||||
} while (!success && !IsStopped());
|
||||
return success;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void Semaphore::release(void)
|
||||
{
|
||||
bool success = false;
|
||||
do
|
||||
{
|
||||
long value = (long)m_var.get();
|
||||
success = m_var.setOn(value + 1, value);
|
||||
} while (!success && !IsStopped());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| CriticalSection object for making atomic operations |
|
||||
//| |
|
||||
//| An exmaple of creating a global context (the creation and destroy|
|
||||
//| are both enclosed between the SAME critical section): |
|
||||
//| |
|
||||
//| enter() |
|
||||
//| if(refcount==0) create context |
|
||||
//| else refcontext |
|
||||
//| increase refcount |
|
||||
//| leave() |
|
||||
//| |
|
||||
//| enter() |
|
||||
//| decrease refcount |
|
||||
//| if(refcount==0) context destroy |
|
||||
//| leave() |
|
||||
//+------------------------------------------------------------------+
|
||||
class CriticalSection
|
||||
{
|
||||
private:
|
||||
const string m_name;
|
||||
|
||||
public:
|
||||
CriticalSection(string name) : m_name(name) {}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return m_name != NULL;
|
||||
}
|
||||
string getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void enter()
|
||||
{
|
||||
GlobalVariable::remove(m_name);
|
||||
while (!GlobalVariable::makeTemp(m_name) && !IsStopped())
|
||||
Sleep(100);
|
||||
}
|
||||
bool tryEnter()
|
||||
{
|
||||
return GlobalVariable::makeTemp(m_name);
|
||||
}
|
||||
void leave()
|
||||
{
|
||||
GlobalVariable::remove(m_name);
|
||||
}
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| HandleManager should implement 2 methods: create & destroy |
|
||||
//+------------------------------------------------------------------+
|
||||
template <typename T>
|
||||
interface HandleManager
|
||||
{
|
||||
T create();
|
||||
void destroy(T);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| A reference counted global pointer (or handle) |
|
||||
//| Generic type parameter T can be long or int depending the handle |
|
||||
//| length (64bit or 32bit) |
|
||||
//+------------------------------------------------------------------+
|
||||
template <typename T, typename HM>
|
||||
class GlobalHandle
|
||||
{
|
||||
private:
|
||||
CriticalSection m_cs;
|
||||
string m_refName;
|
||||
string m_counterName;
|
||||
|
||||
protected:
|
||||
T m_ref;
|
||||
HandleManager<T> *m_hm;
|
||||
|
||||
public:
|
||||
GlobalHandle(string sharedKey = NULL) : m_cs(sharedKey)
|
||||
{
|
||||
m_refName = m_cs.getName() + "_Ref";
|
||||
m_counterName = m_cs.getName() + "_Count";
|
||||
m_hm = new HM;
|
||||
if (!m_cs.isValid())
|
||||
m_ref = m_hm.create();
|
||||
else
|
||||
{
|
||||
m_cs.enter();
|
||||
if (!GlobalVariable::exists(m_counterName))
|
||||
{
|
||||
GlobalVariable::makeTemp(m_counterName);
|
||||
GlobalVariable::set(m_counterName, 0);
|
||||
}
|
||||
if (long(GlobalVariable::get(m_counterName)) == 0)
|
||||
{
|
||||
m_ref = m_hm.create();
|
||||
if (!GlobalVariable::exists(m_refName))
|
||||
{
|
||||
GlobalVariable::makeTemp(m_refName);
|
||||
GlobalVariable::set(m_refName, m_ref);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ref = (T)(GlobalVariable::get(m_refName));
|
||||
}
|
||||
GlobalVariable::set(m_counterName, GlobalVariable::get(m_counterName) + 1);
|
||||
m_cs.leave();
|
||||
}
|
||||
}
|
||||
~GlobalHandle()
|
||||
{
|
||||
if (!m_cs.isValid())
|
||||
{
|
||||
m_hm.destroy(m_ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cs.enter();
|
||||
GlobalVariable::set(m_counterName, GlobalVariable::get(m_counterName) - 1);
|
||||
if (long(GlobalVariable::get(m_counterName)) == 0)
|
||||
{
|
||||
m_hm.destroy(m_ref);
|
||||
GlobalVariable::remove(m_refName);
|
||||
GlobalVariable::remove(m_counterName);
|
||||
}
|
||||
m_cs.leave();
|
||||
}
|
||||
delete m_hm;
|
||||
}
|
||||
|
||||
T ref() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,155 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: Lang/Mql.mqh |
|
||||
//| This file is part of the mql4-lib project: |
|
||||
//| https://github.com/dingmaotu/mql4-lib |
|
||||
//| |
|
||||
//| Copyright 2017 Li Ding <dingmaotu@126.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
#include "Error.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Mql language specific methods |
|
||||
//+------------------------------------------------------------------+
|
||||
class Mql
|
||||
{
|
||||
public:
|
||||
static int getLastError() { return GetLastError(); }
|
||||
static string getErrorMessage(int errorCode) { return GetErrorDescription(errorCode); }
|
||||
|
||||
//--- Prefer global DoubleToString function
|
||||
static string doubleToString(double value, int precision) { return DoubleToString(value, precision); }
|
||||
//--- Adapted from stdlib.mq4 by using `StringSetCharacter` instead of `StringSetChar`
|
||||
static string integerToHexString(int value)
|
||||
{
|
||||
static const string digits = "0123456789ABCDEF";
|
||||
string hex = "00000000";
|
||||
int digit, shift = 28;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
digit = (value >> shift) & 0x0F;
|
||||
StringSetCharacter(hex, i, digits[digit]);
|
||||
shift -= 4;
|
||||
}
|
||||
return (hex);
|
||||
}
|
||||
//--- Prefer Canvas/Canvas.mqh XRGB
|
||||
static int rgb(int r, int g, int b) { return int(0xFF000000 | (uchar(r) << 16) | (uchar(g) << 8) | uchar(b)); }
|
||||
|
||||
//--- Prefer Lang/Number.mqh Double::IsEqual
|
||||
static bool isEqual(double a, double b) { return NormalizeDouble(a - b, 8) == 0; }
|
||||
|
||||
static bool isStopped() { return IsStopped(); }
|
||||
|
||||
static int getCodePage() { return MQLInfoInteger(MQL_CODEPAGE); }
|
||||
static ENUM_PROGRAM_TYPE getProgramType() { return (ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE); }
|
||||
static bool isScript() { return Mql::getProgramType() == PROGRAM_SCRIPT; }
|
||||
static bool isExpert() { return Mql::getProgramType() == PROGRAM_EXPERT; }
|
||||
static bool isIndicator() { return Mql::getProgramType() == PROGRAM_INDICATOR; }
|
||||
static bool isDllAllowed() { return MQLInfoInteger(MQL_DLLS_ALLOWED) != 0; }
|
||||
static bool isTradeAllowed() { return MQLInfoInteger(MQL_TRADE_ALLOWED) != 0; }
|
||||
static bool isSignalsAllowed() { return MQLInfoInteger(MQL_SIGNALS_ALLOWED) != 0; }
|
||||
static bool isDebug() { return MQLInfoInteger(MQL_DEBUG) != 0; }
|
||||
static bool isProfiling() { return MQLInfoInteger(MQL_PROFILER) != 0; }
|
||||
static bool isTesting() { return MQLInfoInteger(MQL_TESTER) != 0; }
|
||||
static bool isOptimizing() { return MQLInfoInteger(MQL_OPTIMIZATION) != 0; }
|
||||
static bool isVisual() { return MQLInfoInteger(MQL_VISUAL_MODE) != 0; }
|
||||
static bool isFrameMode() { return MQLInfoInteger(MQL_FRAME_MODE) != 0; }
|
||||
static ENUM_LICENSE_TYPE getLicenseType() { return (ENUM_LICENSE_TYPE)MQLInfoInteger(MQL_LICENSE_TYPE); }
|
||||
static bool isFreeLicense() { return Mql::getLicenseType() == LICENSE_FREE; }
|
||||
static bool isDemoLicense() { return Mql::getLicenseType() == LICENSE_DEMO; }
|
||||
static bool isFullLicense() { return Mql::getLicenseType() == LICENSE_FULL; }
|
||||
static bool isTimeLicense() { return Mql::getLicenseType() == LICENSE_TIME; }
|
||||
|
||||
static string getProgramName() { return MQLInfoString(MQL_PROGRAM_NAME); }
|
||||
static string getProgramPath() { return MQLInfoString(MQL_PROGRAM_PATH); }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Object getter/setter generator |
|
||||
//| ObjectAttr generates: |
|
||||
//| 1. private member m_property |
|
||||
//| 2. public method setProperty |
|
||||
//| 3. public method getProperty |
|
||||
//| ObjectAttrBool is specific to boolean type properties: |
|
||||
//| 1. private member m_isProperty |
|
||||
//| 2. public method setProperty |
|
||||
//| 3. public method isProperty |
|
||||
//| Use *Read or *Write versions for read only or write only |
|
||||
//| properties |
|
||||
//+------------------------------------------------------------------+
|
||||
#define ObjectAttr(Type, Private, Public) \
|
||||
public: \
|
||||
Type get##Public() const { return m_##Private; } \
|
||||
void set##Public(Type value) { m_##Private = value; } \
|
||||
\
|
||||
private: \
|
||||
Type m_##Private
|
||||
|
||||
#define ObjectAttrRead(Type, Private, Public) \
|
||||
public: \
|
||||
Type get##Public() const { return m_##Private; } \
|
||||
\
|
||||
private: \
|
||||
Type m_##Private
|
||||
|
||||
#define ObjectAttrWrite(Type, Private, Public) \
|
||||
public: \
|
||||
void set##Public(Type value) { m_##Private = value; } \
|
||||
\
|
||||
private: \
|
||||
Type m_##Private
|
||||
|
||||
#define ObjectAttrBool(Public) \
|
||||
public: \
|
||||
bool is##Public() const { return m_is##Public; } \
|
||||
void set##Public(bool value) { m_is##Public = value; } \
|
||||
\
|
||||
private: \
|
||||
bool m_is##Public
|
||||
|
||||
#define ObjectAttrBoolRead(Public) \
|
||||
public: \
|
||||
bool is##Public() const { return m_is##Public; } \
|
||||
\
|
||||
private: \
|
||||
bool m_is##Public
|
||||
|
||||
#define ObjectAttrBoolWrite(Public) \
|
||||
public: \
|
||||
void set##Public(bool value) { m_is##Public = value; } \
|
||||
\
|
||||
private: \
|
||||
bool m_##Private //+------------------------------------------------------------------+
|
||||
//| Print debug messages: only generate code for debugging runs |
|
||||
//+------------------------------------------------------------------+
|
||||
#ifdef _DEBUG
|
||||
#define Debug(msg) PrintFormat(">>> DEBUG[%s,%d,%s]: %s", __FILE__, __LINE__, __FUNCTION__, msg);
|
||||
#else
|
||||
#define Debug(msg)
|
||||
#endif
|
||||
//+------------------------------------------------------------------+
|
||||
//| Execute some code in the global scope |
|
||||
//+------------------------------------------------------------------+
|
||||
#define BEGIN_EXECUTE(Name) \
|
||||
class __Execute##Name \
|
||||
{ \
|
||||
public: \
|
||||
__Execute##Name() \
|
||||
{
|
||||
#define END_EXECUTE(Name) \
|
||||
} \
|
||||
} \
|
||||
__execute##Name;
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,215 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: Lang/Native.mqh |
|
||||
//| This file is part of the mql4-lib project: |
|
||||
//| https://github.com/dingmaotu/mql4-lib |
|
||||
//| |
|
||||
//| Copyright 2016-2017 Li Ding <dingmaotu@126.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
|
||||
// Assume MT5 is 64bit, which is the default.
|
||||
// Even though MT5 can be 32bit, there is no way to detect this
|
||||
// by using preprocessor macros. Instead, MetaQuotes provides a
|
||||
// function called IsX64 to detect this dynamically
|
||||
|
||||
// This is just absurd. Why do you want to know the bitness of
|
||||
// the runtime? To define pointer related entities at compile time!
|
||||
// All integer types in MQL is uniform on both 32bit or 64bit
|
||||
// architectures, so it is almost useless to have a runtime function IsX64.
|
||||
|
||||
// Why not a __X64__?
|
||||
#ifdef __MQL5__
|
||||
#define __X64__
|
||||
#endif
|
||||
|
||||
#ifdef __X64__
|
||||
#define intptr_t long
|
||||
#define uintptr_t ulong
|
||||
#define size_t long
|
||||
#else
|
||||
#define intptr_t int
|
||||
#define uintptr_t uint
|
||||
#define size_t int
|
||||
#endif
|
||||
|
||||
#import "kernel32.dll"
|
||||
void RtlMoveMemory(intptr_t dest, const uchar &array[], size_t length);
|
||||
void RtlMoveMemory(uchar &array[], intptr_t src, size_t length);
|
||||
void RtlMoveMemory(intptr_t dest, const MqlRates &array[], size_t length);
|
||||
void RtlMoveMemory(MqlRates &array[], intptr_t src, size_t length);
|
||||
void RtlMoveMemory(intptr_t dest, const MqlTick &value, size_t length);
|
||||
void RtlMoveMemory(MqlTick &value, intptr_t src, size_t length);
|
||||
void RtlMoveMemory(intptr_t &dest, intptr_t src, size_t length);
|
||||
int lstrlen(intptr_t psz);
|
||||
int lstrlenW(intptr_t psz);
|
||||
uintptr_t lstrcpynW(string &s1, uintptr_t s2, int length);
|
||||
uintptr_t lstrcpynW(uintptr_t s1, string &s2, int length);
|
||||
|
||||
int MultiByteToWideChar(uint codePage,
|
||||
uint flags,
|
||||
const intptr_t multiByteString,
|
||||
int lengthMultiByte,
|
||||
string &str,
|
||||
int length);
|
||||
#import
|
||||
//+------------------------------------------------------------------+
|
||||
//| Copy the memory contents pointed by src to array |
|
||||
//| array parameter should be initialized to the desired size |
|
||||
//| Need to import RtlMoveMemory with appropriate parameter type T |
|
||||
//+------------------------------------------------------------------+
|
||||
template <typename T>
|
||||
void ArrayFromPointer(T &array[], intptr_t src, int count = WHOLE_ARRAY)
|
||||
{
|
||||
int size = (count == WHOLE_ARRAY) ? ArraySize(array) : count;
|
||||
RtlMoveMemory(array, src, (size_t)(size * sizeof(T)));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Copy array to the memory pointed by dest |
|
||||
//| Need to import RtlMoveMemory with appropriate parameter type T |
|
||||
//+------------------------------------------------------------------+
|
||||
template <typename T>
|
||||
void ArrayToPointer(const T &array[], intptr_t dest, int count = WHOLE_ARRAY)
|
||||
{
|
||||
int size = (count == WHOLE_ARRAY) ? ArraySize(array) : count;
|
||||
RtlMoveMemory(dest, array, (size_t)(size * sizeof(T)));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Copy the memory contents pointed by src to value type T |
|
||||
//| Need to import RtlMoveMemory with appropriate parameter type T |
|
||||
//+------------------------------------------------------------------+
|
||||
template <typename T>
|
||||
void ValueFromPointer(T &value, intptr_t src)
|
||||
{
|
||||
RtlMoveMemory(value, src, (size_t)sizeof(T));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Copy value to the memory pointed by dest |
|
||||
//| Need to import RtlMoveMemory with appropriate parameter type T |
|
||||
//+------------------------------------------------------------------+
|
||||
template <typename T>
|
||||
void ValueToPointer(const T &value, intptr_t dest)
|
||||
{
|
||||
RtlMoveMemory(dest, value, (size_t)sizeof(T));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| For void** type, dereference a level to void* |
|
||||
//+------------------------------------------------------------------+
|
||||
intptr_t DereferencePointer(intptr_t pointer)
|
||||
{
|
||||
intptr_t res = 0;
|
||||
RtlMoveMemory(res, pointer, sizeof(intptr_t));
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Read a valid wide character string to the MQL environment |
|
||||
//+------------------------------------------------------------------+
|
||||
string StringFromPointer(intptr_t psz, int len = 0)
|
||||
{
|
||||
if (len < 0)
|
||||
return NULL;
|
||||
if (len == 0)
|
||||
{
|
||||
len = lstrlenW(psz);
|
||||
}
|
||||
string res;
|
||||
StringInit(res, len + 1);
|
||||
lstrcpynW(res, psz, len + 1);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get the pointer address of a string |
|
||||
//+------------------------------------------------------------------+
|
||||
uintptr_t StringToPointer(string &s)
|
||||
{
|
||||
return lstrcpynW(s, 0, 0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Read a valid utf-8 string to the MQL environment |
|
||||
//| With this function, there is no need to copy the string to char |
|
||||
//| array, and convert with CharArrayToString |
|
||||
//+------------------------------------------------------------------+
|
||||
string StringFromUtf8Pointer(intptr_t psz, int len)
|
||||
{
|
||||
if (len < 0)
|
||||
return NULL;
|
||||
string res;
|
||||
int required = MultiByteToWideChar(CP_UTF8, 0, psz, len, res, 0);
|
||||
// need to include the NULL terminating character
|
||||
StringInit(res, required + 1);
|
||||
int rlen = MultiByteToWideChar(CP_UTF8, 0, psz, len, res, required);
|
||||
return rlen != required ? NULL : res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| for null-terminated string |
|
||||
//+------------------------------------------------------------------+
|
||||
string StringFromUtf8Pointer(intptr_t psz)
|
||||
{
|
||||
if (psz == 0)
|
||||
return NULL;
|
||||
int len = lstrlen(psz);
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
return StringFromUtf8Pointer(psz, len);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Convert a utf-8 byte array to a string |
|
||||
//+------------------------------------------------------------------+
|
||||
string StringFromUtf8(const uchar &utf8[])
|
||||
{
|
||||
return CharArrayToString(utf8, 0, -1, CP_UTF8);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Convert a char array to a string (overload for char arrays) |
|
||||
//+------------------------------------------------------------------+
|
||||
string StringFromUtf8(const char &utf8[])
|
||||
{
|
||||
uchar temp[];
|
||||
int size = ArraySize(utf8);
|
||||
ArrayResize(temp, size);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
temp[i] = (uchar)utf8[i];
|
||||
}
|
||||
return CharArrayToString(temp, 0, -1, CP_UTF8);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Convert a string to a utf-8 byte array |
|
||||
//+------------------------------------------------------------------+
|
||||
void StringToUtf8(const string str, uchar &utf8[], bool ending = true)
|
||||
{
|
||||
if (!ending && str == "")
|
||||
return;
|
||||
int count = ending ? -1 : StringLen(str);
|
||||
StringToCharArray(str, utf8, 0, count, CP_UTF8);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Convert a string to a char array (overload for char arrays) |
|
||||
//+------------------------------------------------------------------+
|
||||
void StringToUtf8(const string str, char &utf8[], bool ending = true)
|
||||
{
|
||||
if (!ending && str == "")
|
||||
return;
|
||||
uchar temp[];
|
||||
int count = ending ? -1 : StringLen(str);
|
||||
StringToCharArray(str, temp, 0, count, CP_UTF8);
|
||||
int size = ArraySize(temp);
|
||||
ArrayResize(utf8, size);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
utf8[i] = (char)temp[i];
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -1,276 +0,0 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: Socket.mqh |
|
||||
//| This file is part of the mql-zmq project: |
|
||||
//| https://github.com/dingmaotu/mql-zmq |
|
||||
//| |
|
||||
//| Copyright 2016-2017 Li Ding <dingmaotu@hotmail.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
|
||||
#include <Mql/Lang/Mql.mqh>
|
||||
#include <Mql/Lang/Native.mqh>
|
||||
#include "Context.mqh"
|
||||
#include "SocketOptions.mqh"
|
||||
#include "ZmqMsg.mqh"
|
||||
|
||||
//--- Socket types
|
||||
#define ZMQ_PAIR 0
|
||||
#define ZMQ_PUB 1
|
||||
#define ZMQ_SUB 2
|
||||
#define ZMQ_REQ 3
|
||||
#define ZMQ_REP 4
|
||||
#define ZMQ_DEALER 5
|
||||
#define ZMQ_ROUTER 6
|
||||
#define ZMQ_PULL 7
|
||||
#define ZMQ_PUSH 8
|
||||
#define ZMQ_XPUB 9
|
||||
#define ZMQ_XSUB 10
|
||||
#define ZMQ_STREAM 11
|
||||
|
||||
//--- Message options
|
||||
#define ZMQ_MORE 1
|
||||
#define ZMQ_SRCFD 2 // Deprecated
|
||||
#define ZMQ_SHARED 3
|
||||
|
||||
//--- Send/recv options
|
||||
#define ZMQ_DONTWAIT 1
|
||||
#define ZMQ_SNDMORE 2
|
||||
|
||||
//--- Socket transport events (TCP, IPC and TIPC only)
|
||||
#define ZMQ_EVENT_CONNECTED 0x0001
|
||||
#define ZMQ_EVENT_CONNECT_DELAYED 0x0002
|
||||
#define ZMQ_EVENT_CONNECT_RETRIED 0x0004
|
||||
#define ZMQ_EVENT_LISTENING 0x0008
|
||||
#define ZMQ_EVENT_BIND_FAILED 0x0010
|
||||
#define ZMQ_EVENT_ACCEPTED 0x0020
|
||||
#define ZMQ_EVENT_ACCEPT_FAILED 0x0040
|
||||
#define ZMQ_EVENT_CLOSED 0x0080
|
||||
#define ZMQ_EVENT_CLOSE_FAILED 0x0100
|
||||
#define ZMQ_EVENT_DISCONNECTED 0x0200
|
||||
#define ZMQ_EVENT_MONITOR_STOPPED 0x0400
|
||||
#define ZMQ_EVENT_ALL 0xFFFF
|
||||
|
||||
//--- I/O multiplexing
|
||||
#define ZMQ_POLLIN 1
|
||||
#define ZMQ_POLLOUT 2
|
||||
// We only use 0MQ sockets on Windows
|
||||
// So POLLERR and POLLPRI is of no use
|
||||
#define ZMQ_POLLERR 4
|
||||
#define ZMQ_POLLPRI 8
|
||||
|
||||
#define ZMQ_POLLITEMS_DFLT 16
|
||||
//--- fd is SOCKET on Win32, which is defined as UINT_PTR
|
||||
struct PollItem
|
||||
{
|
||||
intptr_t socket;
|
||||
uintptr_t fd;
|
||||
short events;
|
||||
short revents;
|
||||
#ifdef __X64__
|
||||
//--- note here that if the program runs on 64bit runtime, we need to pad the
|
||||
//--- struct to align to 8 bytes
|
||||
//--- thanks https://github.com/feng-ye for the solution to https://github.com/dingmaotu/mql-zmq/issues/14
|
||||
int __unused;
|
||||
#endif
|
||||
|
||||
bool hasInput() const {return(revents&ZMQ_POLLIN)!=0;}
|
||||
bool hasOutput() const {return(revents&ZMQ_POLLOUT)!=0;}
|
||||
};
|
||||
#import "libzmq.dll"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Sockets |
|
||||
//+------------------------------------------------------------------+
|
||||
intptr_t zmq_socket(intptr_t context,int type);
|
||||
int zmq_close(intptr_t s);
|
||||
int zmq_bind(intptr_t s,const char &addr[]);
|
||||
int zmq_connect(intptr_t s,const char &addr[]);
|
||||
int zmq_unbind(intptr_t s,const char &addr[]);
|
||||
int zmq_disconnect(intptr_t s,const char &addr[]);
|
||||
int zmq_send(intptr_t s,const uchar &buf[],size_t len,int flags);
|
||||
int zmq_send_const(intptr_t s,const uchar &buf[],size_t len,int flags);
|
||||
int zmq_recv(intptr_t s,uchar &buf[],size_t len,int flags);
|
||||
int zmq_socket_monitor(intptr_t s,const char &addr[],int events);
|
||||
//+------------------------------------------------------------------+
|
||||
//| Message |
|
||||
//+------------------------------------------------------------------+
|
||||
int zmq_msg_send(zmq_msg_t &msg,intptr_t s,int flags);
|
||||
int zmq_msg_recv(zmq_msg_t &msg,intptr_t s,int flags);
|
||||
//+------------------------------------------------------------------+
|
||||
//| I/O multiplexing |
|
||||
//+------------------------------------------------------------------+
|
||||
int zmq_poll(PollItem &items[],int nitems,long timeout);
|
||||
//+------------------------------------------------------------------+
|
||||
//| Message proxying |
|
||||
//+------------------------------------------------------------------+
|
||||
int zmq_proxy(intptr_t frontend_ref,intptr_t backend_ref,intptr_t capture_ref);
|
||||
int zmq_proxy_steerable(intptr_t frontend_ref,intptr_t backend_ref,intptr_t capture_ref,intptr_t control_ref);
|
||||
#import
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wraps a 0MQ socket |
|
||||
//+------------------------------------------------------------------+
|
||||
class Socket: public SocketOptions
|
||||
{
|
||||
public:
|
||||
Socket(const Context &ctx,int type):SocketOptions(zmq_socket(ctx.ref(),type)){}
|
||||
virtual ~Socket() {if(0!=zmq_close(m_ref)){Debug(StringFormat("Failed to close socket 0x%0X",m_ref));}}
|
||||
|
||||
// for better cooperation between objects
|
||||
intptr_t ref() const {return m_ref;}
|
||||
|
||||
bool valid() const {return m_ref!=0;}
|
||||
|
||||
//--- see Zmq::error() if any of the following command failed
|
||||
//--- connection management
|
||||
bool bind(string addr);
|
||||
bool unbind(string addr);
|
||||
bool connect(string addr);
|
||||
bool disconnect(string addr);
|
||||
|
||||
//--- send raw bytes
|
||||
bool send(const uchar &buf[],bool nowait=false) {return -1!=zmq_send(m_ref,buf,ArraySize(buf),nowait?ZMQ_DONTWAIT:0);}
|
||||
bool sendConst(const uchar &buf[],bool nowait=false) {return -1!=zmq_send_const(m_ref,buf,ArraySize(buf),nowait?ZMQ_DONTWAIT:0);}
|
||||
|
||||
//--- send ZmqMsg
|
||||
bool send(ZmqMsg &msg,bool nowait=false) {return -1!=zmq_msg_send(msg,m_ref,nowait?ZMQ_DONTWAIT:0);}
|
||||
//--- send string
|
||||
bool send(string msg,bool nowait=false) {ZmqMsg m(msg); return send(m,nowait);}
|
||||
//--- send empty
|
||||
bool send(bool nowait=false) {ZmqMsg m; return send(m,nowait);}
|
||||
|
||||
//--- same as above 5 but for multipart messages
|
||||
bool sendMore(const uchar &buf[],bool nowait=false);
|
||||
bool sendConstMore(const uchar &buf[],bool nowait=false);
|
||||
bool sendMore(ZmqMsg &msg,bool nowait=false)
|
||||
{
|
||||
int flags=ZMQ_SNDMORE;
|
||||
if(nowait) flags|=ZMQ_DONTWAIT;
|
||||
return -1!=zmq_msg_send(msg,m_ref,flags);
|
||||
}
|
||||
bool sendMore(string msg,bool nowait=false) {ZmqMsg m(msg); return sendMore(m,nowait);}
|
||||
bool sendMore(bool nowait=false) {ZmqMsg m; return sendMore(m,nowait);}
|
||||
|
||||
//--- receive packets
|
||||
bool recv(uchar &buf[],bool nowait=false) {return -1!=zmq_recv(m_ref,buf,ArraySize(buf),nowait?ZMQ_DONTWAIT:0);}
|
||||
bool recv(ZmqMsg &msg,bool nowait=false) {return -1!=zmq_msg_recv(msg,m_ref,nowait?ZMQ_DONTWAIT:0);}
|
||||
|
||||
//--- monitor socket events
|
||||
bool monitor(string addr,int events);
|
||||
|
||||
//--- proxy
|
||||
static bool proxy(Socket *frontend,Socket *backend,Socket *capture);
|
||||
static bool proxySteerable(Socket *frontend,Socket *backend,Socket *capture,Socket *control);
|
||||
|
||||
//--- poll
|
||||
static int poll(PollItem &arr[],long timeout);
|
||||
|
||||
//--- fill a poll item for this socket
|
||||
void fillPollItem(PollItem &item,short events);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::bind(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr,arr);
|
||||
bool res=(0==zmq_bind(m_ref,arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::unbind(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr,arr);
|
||||
bool res=(0==zmq_unbind(m_ref,arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::connect(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr,arr);
|
||||
bool res=(0==zmq_connect(m_ref,arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::disconnect(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr,arr);
|
||||
bool res=(0==zmq_disconnect(m_ref,arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::monitor(string addr,int events)
|
||||
{
|
||||
uchar str[];
|
||||
StringToUtf8(addr,str);
|
||||
bool res=(0==zmq_socket_monitor(m_ref,str,events));
|
||||
ArrayFree(str);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::proxy(Socket *frontend,Socket *backend,Socket *capture)
|
||||
{
|
||||
intptr_t frontend_ref= CheckPointer(frontend)==POINTER_DYNAMIC?frontend.ref():0;
|
||||
intptr_t backend_ref = CheckPointer(backend)==POINTER_DYNAMIC?backend.ref():0;
|
||||
intptr_t capture_ref=CheckPointer(capture)==POINTER_DYNAMIC?capture.ref():0;
|
||||
return 0==zmq_proxy(frontend_ref, backend_ref, capture_ref);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::proxySteerable(Socket *frontend,Socket *backend,Socket *capture,Socket *control)
|
||||
{
|
||||
intptr_t frontend_ref= CheckPointer(frontend)==POINTER_DYNAMIC?frontend.ref():0;
|
||||
intptr_t backend_ref = CheckPointer(backend)==POINTER_DYNAMIC?backend.ref():0;
|
||||
intptr_t capture_ref=CheckPointer(capture)==POINTER_DYNAMIC?capture.ref():0;
|
||||
intptr_t control_ref=CheckPointer(control)==POINTER_DYNAMIC?control.ref():0;
|
||||
return 0==zmq_proxy_steerable(frontend_ref, backend_ref, capture_ref, control_ref);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| poll for events. timeout is milliseconds (-1 for indefinite wait |
|
||||
//| and 0 for immediate return) |
|
||||
//+------------------------------------------------------------------+
|
||||
int Socket::poll(PollItem &arr[],long timeout)
|
||||
{
|
||||
return zmq_poll(arr,ArraySize(arr),timeout);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| fill a poll item for this socket |
|
||||
//+------------------------------------------------------------------+
|
||||
void Socket::fillPollItem(PollItem &item,short events)
|
||||
{
|
||||
item.socket=m_ref;
|
||||
item.fd=0;
|
||||
item.events=events;
|
||||
item.revents=0;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -1,358 +0,0 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: SocketOptions.mqh |
|
||||
//| This file is part of the mql-zmq project: |
|
||||
//| https://github.com/dingmaotu/mql-zmq |
|
||||
//| |
|
||||
//| Copyright 2016-2017 Li Ding <dingmaotu@hotmail.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
|
||||
#include <Mql/Lang/Native.mqh>
|
||||
|
||||
#import "libzmq.dll"
|
||||
// We can overload the same function for different data types
|
||||
// as in the C level the optval paramter is just a pointer
|
||||
#define SOCKOPT_OVERLOAD_ARRAY(TYPE) \
|
||||
int zmq_setsockopt(intptr_t s,int option,const TYPE &optval[],\
|
||||
size_t optvallen);\
|
||||
int zmq_getsockopt(intptr_t s,int option,TYPE &optval[],\
|
||||
size_t &optvallen);\
|
||||
|
||||
#define SOCKOPT_OVERLOAD(TYPE) \
|
||||
int zmq_setsockopt(intptr_t s,int option,const TYPE &optval,\
|
||||
size_t optvallen);\
|
||||
int zmq_getsockopt(intptr_t s,int option,TYPE &optval,\
|
||||
size_t &optvallen);\
|
||||
|
||||
SOCKOPT_OVERLOAD_ARRAY(uchar)
|
||||
SOCKOPT_OVERLOAD(long)
|
||||
SOCKOPT_OVERLOAD(ulong)
|
||||
SOCKOPT_OVERLOAD(int)
|
||||
SOCKOPT_OVERLOAD(uint)
|
||||
#import
|
||||
|
||||
// Socket options
|
||||
#define ZMQ_AFFINITY 4
|
||||
#define ZMQ_IDENTITY 5
|
||||
#define ZMQ_SUBSCRIBE 6
|
||||
#define ZMQ_UNSUBSCRIBE 7
|
||||
#define ZMQ_RATE 8
|
||||
#define ZMQ_RECOVERY_IVL 9
|
||||
#define ZMQ_SNDBUF 11
|
||||
#define ZMQ_RCVBUF 12
|
||||
#define ZMQ_RCVMORE 13
|
||||
#define ZMQ_FD 14
|
||||
#define ZMQ_EVENTS 15
|
||||
#define ZMQ_TYPE 16
|
||||
#define ZMQ_LINGER 17
|
||||
#define ZMQ_RECONNECT_IVL 18
|
||||
#define ZMQ_BACKLOG 19
|
||||
#define ZMQ_RECONNECT_IVL_MAX 21
|
||||
#define ZMQ_MAXMSGSIZE 22
|
||||
#define ZMQ_SNDHWM 23
|
||||
#define ZMQ_RCVHWM 24
|
||||
#define ZMQ_MULTICAST_HOPS 25
|
||||
#define ZMQ_RCVTIMEO 27
|
||||
#define ZMQ_SNDTIMEO 28
|
||||
#define ZMQ_LAST_ENDPOINT 32
|
||||
#define ZMQ_ROUTER_MANDATORY 33
|
||||
#define ZMQ_TCP_KEEPALIVE 34
|
||||
#define ZMQ_TCP_KEEPALIVE_CNT 35
|
||||
#define ZMQ_TCP_KEEPALIVE_IDLE 36
|
||||
#define ZMQ_TCP_KEEPALIVE_INTVL 37
|
||||
#define ZMQ_IMMEDIATE 39
|
||||
#define ZMQ_XPUB_VERBOSE 40
|
||||
#define ZMQ_ROUTER_RAW 41
|
||||
#define ZMQ_IPV6 42
|
||||
#define ZMQ_MECHANISM 43
|
||||
#define ZMQ_PLAIN_SERVER 44
|
||||
#define ZMQ_PLAIN_USERNAME 45
|
||||
#define ZMQ_PLAIN_PASSWORD 46
|
||||
#define ZMQ_CURVE_SERVER 47
|
||||
#define ZMQ_CURVE_PUBLICKEY 48
|
||||
#define ZMQ_CURVE_SECRETKEY 49
|
||||
#define ZMQ_CURVE_SERVERKEY 50
|
||||
#define ZMQ_PROBE_ROUTER 51
|
||||
#define ZMQ_REQ_CORRELATE 52
|
||||
#define ZMQ_REQ_RELAXED 53
|
||||
#define ZMQ_CONFLATE 54
|
||||
#define ZMQ_ZAP_DOMAIN 55
|
||||
#define ZMQ_ROUTER_HANDOVER 56
|
||||
#define ZMQ_TOS 57
|
||||
#define ZMQ_CONNECT_RID 61
|
||||
#define ZMQ_GSSAPI_SERVER 62
|
||||
#define ZMQ_GSSAPI_PRINCIPAL 63
|
||||
#define ZMQ_GSSAPI_SERVICE_PRINCIPAL 64
|
||||
#define ZMQ_GSSAPI_PLAINTEXT 65
|
||||
#define ZMQ_HANDSHAKE_IVL 66
|
||||
#define ZMQ_SOCKS_PROXY 68
|
||||
#define ZMQ_XPUB_NODROP 69
|
||||
#define ZMQ_BLOCKY 70
|
||||
#define ZMQ_XPUB_MANUAL 71
|
||||
#define ZMQ_XPUB_WELCOME_MSG 72
|
||||
#define ZMQ_STREAM_NOTIFY 73
|
||||
#define ZMQ_INVERT_MATCHING 74
|
||||
#define ZMQ_HEARTBEAT_IVL 75
|
||||
#define ZMQ_HEARTBEAT_TTL 76
|
||||
#define ZMQ_HEARTBEAT_TIMEOUT 77
|
||||
#define ZMQ_XPUB_VERBOSER 78
|
||||
#define ZMQ_CONNECT_TIMEOUT 79
|
||||
#define ZMQ_TCP_MAXRT 80
|
||||
#define ZMQ_THREAD_SAFE 81
|
||||
#define ZMQ_MULTICAST_MAXTPDU 84
|
||||
#define ZMQ_VMCI_BUFFER_SIZE 85
|
||||
#define ZMQ_VMCI_BUFFER_MIN_SIZE 86
|
||||
#define ZMQ_VMCI_BUFFER_MAX_SIZE 87
|
||||
#define ZMQ_VMCI_CONNECT_TIMEOUT 88
|
||||
#define ZMQ_USE_FD 89
|
||||
//+------------------------------------------------------------------+
|
||||
//| A dedicated class to get/set socket options |
|
||||
//+------------------------------------------------------------------+
|
||||
class SocketOptions
|
||||
{
|
||||
protected:
|
||||
intptr_t m_ref;
|
||||
|
||||
#define SOCKOPT_WRAP_ARRAY(TYPE) \
|
||||
bool setOption(int option,const TYPE &value[],size_t len) {return 0==zmq_setsockopt(m_ref,option,value,len);}\
|
||||
bool getOption(int option,TYPE &value[],size_t &len) {return 0==zmq_getsockopt(m_ref,option,value,len);}
|
||||
|
||||
#define SOCKOPT_WRAP(TYPE) \
|
||||
bool setOption(int option,TYPE value) {return 0==zmq_setsockopt(m_ref,option,value,sizeof(TYPE));}\
|
||||
bool getOption(int option,TYPE &value) {size_t s=sizeof(TYPE); return 0==zmq_getsockopt(m_ref,option,value,s);}
|
||||
|
||||
SOCKOPT_WRAP_ARRAY(uchar)
|
||||
SOCKOPT_WRAP(int)
|
||||
SOCKOPT_WRAP(uint)
|
||||
SOCKOPT_WRAP(long)
|
||||
SOCKOPT_WRAP(ulong)
|
||||
|
||||
bool setStringOption(int option,string value,bool ending=true);
|
||||
bool getStringOption(int option,string &value,size_t length=1024);
|
||||
SocketOptions(intptr_t ref):m_ref(ref){}
|
||||
public:
|
||||
//--- option templates
|
||||
//--- various integer options
|
||||
#define SOCKOPT_GET(TYPE, NAME, MACRO) \
|
||||
bool get##NAME(TYPE &value) {return getOption(MACRO,value);}
|
||||
#define SOCKOPT_SET(TYPE, NAME, MACRO) \
|
||||
bool set##NAME(TYPE value) {return setOption(MACRO,value);}
|
||||
#define SOCKOPT(TYPE,NAME,MACRO) \
|
||||
SOCKOPT_GET(TYPE,NAME,MACRO) \
|
||||
SOCKOPT_SET(TYPE,NAME,MACRO)
|
||||
|
||||
//--- boolean options
|
||||
#define SOCKOPT_GET_BOOL(NAME, MACRO) \
|
||||
bool is##NAME(bool &value) {int v; bool res=getOption(MACRO,v); value=(v==1);return res;}
|
||||
#define SOCKOPT_SET_BOOL(NAME, MACRO) \
|
||||
bool set##NAME(bool value) {return setOption(MACRO,value?1:0);}
|
||||
#define SOCKOPT_BOOL(NAME,MACRO) \
|
||||
SOCKOPT_GET_BOOL(NAME,MACRO) \
|
||||
SOCKOPT_SET_BOOL(NAME,MACRO)
|
||||
|
||||
//--- null-terminated string options
|
||||
#define SOCKOPT_GET_NTSTR(NAME,MACRO) \
|
||||
bool get##NAME(string &value) {return getStringOption(MACRO,value);}
|
||||
#define SOCKOPT_SET_NTSTR(NAME,MACRO) \
|
||||
bool set##NAME(string value) {return setStringOption(MACRO,value);}
|
||||
#define SOCKOPT_NTSTR(NAME,MACRO) \
|
||||
SOCKOPT_GET_NTSTR(NAME,MACRO) \
|
||||
SOCKOPT_SET_NTSTR(NAME,MACRO)
|
||||
|
||||
//--- bytes array or string converted options
|
||||
#define SOCKOPT_SET_BYTES(OptionName,Macro) \
|
||||
bool set##OptionName(const uchar &value[]) {return setOption(Macro,value,(size_t)ArraySize(value));} \
|
||||
bool set##OptionName(string value) {return setStringOption(Macro,value,false);}
|
||||
#define SOCKOPT_GET_BYTES(OptionName,Macro,InitSize) \
|
||||
bool get##OptionName(uchar &value[]) {size_t len=(size_t)InitSize; ArrayResize(value,(int)len); bool res=getOption(Macro,value,len); if(res){ArrayResize(value,(int)len);}return res;} \
|
||||
bool get##OptionName(string &value) {return getStringOption(Macro,value,InitSize);}
|
||||
#define SOCKOPT_BYTES(OptionName,Macro,InitSize) \
|
||||
SOCKOPT_SET_BYTES(OptionName,Macro) \
|
||||
SOCKOPT_GET_BYTES(OptionName,Macro,InitSize)
|
||||
|
||||
//--- for curve key
|
||||
//--- NOTE that the length of the key array must be 32.
|
||||
//--- since some versions of mt4 and newer versions of mt5 will report error
|
||||
//--- when the length of the array is specified, so the length specification is removed
|
||||
#define SOCKOPT_CURVE_KEY(KeyType,Macro) \
|
||||
bool getCurve##KeyType##Key(uchar &key[]) {size_t len=32; return getOption(Macro,key,len);} \
|
||||
bool getCurve##KeyType##Key(string &key) {return getStringOption(Macro,key,41);} \
|
||||
bool setCurve##KeyType##Key(const uchar &key[]) {return setOption(Macro,key,32);} \
|
||||
bool setCurve##KeyType##Key(string key) {return setStringOption(Macro,key);}
|
||||
|
||||
SOCKOPT_GET(int,Type,ZMQ_TYPE)
|
||||
SOCKOPT(ulong,Affinity,ZMQ_AFFINITY) //64bit bitmask
|
||||
SOCKOPT(int,BackLog,ZMQ_BACKLOG) // number of connections
|
||||
SOCKOPT(int,Timeout,ZMQ_CONNECT_TIMEOUT) // milliseconds
|
||||
SOCKOPT_GET_BOOL(ThreadSafe,ZMQ_THREAD_SAFE)
|
||||
|
||||
SOCKOPT_SET_BOOL(Conflate,ZMQ_CONFLATE) // only for ZMQ_PULL, ZMQ_PUSH, ZMQ_SUB, ZMQ_PUB, ZMQ_DEALER types
|
||||
|
||||
SOCKOPT_GET(int,Events,ZMQ_EVENTS); // bitmask of ZMQ_POLLIN, ZMQ_POLLOUT
|
||||
|
||||
SOCKOPT_GET(uintptr_t,FileDescriptor,ZMQ_FD)
|
||||
|
||||
SOCKOPT_GET(int,Mechanism,ZMQ_MECHANISM) // current security mechanism
|
||||
|
||||
//--- plain
|
||||
SOCKOPT_NTSTR(PlainUsername,ZMQ_PLAIN_USERNAME)
|
||||
SOCKOPT_NTSTR(PlainPassword,ZMQ_PLAIN_PASSWORD)
|
||||
SOCKOPT_BOOL(PlainServer,ZMQ_PLAIN_SERVER)
|
||||
|
||||
//--- gssapi: this is not supported in this binding. Following methods will FAIL if you invoke them
|
||||
SOCKOPT_BOOL(GssApiPlainText,ZMQ_GSSAPI_PLAINTEXT)
|
||||
SOCKOPT_BOOL(GssApiServer,ZMQ_GSSAPI_SERVER)
|
||||
SOCKOPT_NTSTR(GssApiPrincipal,ZMQ_GSSAPI_PRINCIPAL)
|
||||
SOCKOPT_NTSTR(GssApiServicePrincipal,ZMQ_GSSAPI_SERVICE_PRINCIPAL)
|
||||
|
||||
//--- curve
|
||||
SOCKOPT_CURVE_KEY(Public,ZMQ_CURVE_PUBLICKEY)
|
||||
SOCKOPT_CURVE_KEY(Secret,ZMQ_CURVE_SECRETKEY)
|
||||
SOCKOPT_CURVE_KEY(Server,ZMQ_CURVE_SERVERKEY)
|
||||
|
||||
SOCKOPT_SET_BOOL(CurveServer,ZMQ_CURVE_SERVER)
|
||||
|
||||
SOCKOPT_GET_NTSTR(LastEndpoint,ZMQ_LAST_ENDPOINT)
|
||||
|
||||
SOCKOPT(int,HandshakeInterval,ZMQ_HANDSHAKE_IVL) // milliseconds
|
||||
SOCKOPT_SET(int,HeartbeatInterval,ZMQ_HEARTBEAT_IVL) // milliseconds
|
||||
SOCKOPT_SET(int,HeartbeatTimeout,ZMQ_HEARTBEAT_TIMEOUT) // milliseconds
|
||||
SOCKOPT_SET(int,HeartbeatTTL,ZMQ_HEARTBEAT_TTL) // milliseconds
|
||||
|
||||
SOCKOPT_BOOL(Immediate,ZMQ_IMMEDIATE)
|
||||
SOCKOPT_BOOL(Ipv6,ZMQ_IPV6) //--- ZMQ_IPV4ONLY is deprecated, use this instead
|
||||
SOCKOPT(int,Linger,ZMQ_LINGER) // milliseconds
|
||||
SOCKOPT(long,MaxMessageSize,ZMQ_MAXMSGSIZE)
|
||||
|
||||
//--- multicast
|
||||
SOCKOPT(int,MulticastHops,ZMQ_MULTICAST_HOPS) // hops
|
||||
SOCKOPT(int,MulticastMaxTPDU,ZMQ_MULTICAST_MAXTPDU) // bytes
|
||||
SOCKOPT(int,MulticastRate,ZMQ_RATE) // kilobits per second
|
||||
SOCKOPT(int,RecoveryInterval,ZMQ_RECOVERY_IVL) // multicast recovery interval
|
||||
|
||||
//--- there is a problem here: FileDescriptor should be SOCKET type on Windows,
|
||||
//--- while in the zmq doc it is a int. Possible error in the doc
|
||||
SOCKOPT(uintptr_t,UseFileDescriptor,ZMQ_USE_FD)
|
||||
|
||||
SOCKOPT_SET_BOOL(ProbeRouter,ZMQ_PROBE_ROUTER) // only for ZMQ_ROUTER, ZMQ_DEALER, ZMQ_REQ
|
||||
|
||||
SOCKOPT(int,ReceiveBuffer,ZMQ_RCVBUF) // bytes
|
||||
SOCKOPT(int,ReceiveHighWaterMark,ZMQ_RCVHWM) // messages
|
||||
SOCKOPT(int,ReceiveTimeout,ZMQ_RCVTIMEO) // milliseconds
|
||||
SOCKOPT(int,SendBuffer,ZMQ_SNDBUF) // bytes
|
||||
SOCKOPT(int,SendHighWaterMark,ZMQ_SNDHWM) // messages
|
||||
SOCKOPT(int,SendTimeout,ZMQ_SNDTIMEO)
|
||||
|
||||
SOCKOPT_GET_BOOL(ReceiveMore,ZMQ_RCVMORE)
|
||||
|
||||
SOCKOPT(int,ReconnectInterval,ZMQ_RECONNECT_IVL) // milliseconds
|
||||
SOCKOPT(int,ReconnectIntervalMax,ZMQ_RECONNECT_IVL_MAX) // milliseconds
|
||||
|
||||
//--- only for ZMQ_REQ
|
||||
SOCKOPT_SET_BOOL(RequestCorrelated,ZMQ_REQ_CORRELATE)
|
||||
SOCKOPT_SET_BOOL(RequestRelaxed,ZMQ_REQ_RELAXED)
|
||||
|
||||
//--- only for ZMQ_SUB
|
||||
SOCKOPT_SET_BYTES(Subscribe,ZMQ_SUBSCRIBE)
|
||||
SOCKOPT_SET_BYTES(Unsubscribe,ZMQ_UNSUBSCRIBE)
|
||||
|
||||
//--- convenience methods
|
||||
bool subscribe(string channel) {return setSubscribe(channel);}
|
||||
bool unsubscribe(string channel) {return setUnsubscribe(channel);}
|
||||
|
||||
//--- only for ZMQ_XSUB
|
||||
SOCKOPT_BOOL(XpubVerbose,ZMQ_XPUB_VERBOSE)
|
||||
SOCKOPT_BOOL(XpubVerboser,ZMQ_XPUB_VERBOSER)
|
||||
SOCKOPT_BOOL(XpubManual,ZMQ_XPUB_MANUAL)
|
||||
SOCKOPT_BOOL(XpubNoDrop,ZMQ_XPUB_NODROP) // also for ZMQ_PUB
|
||||
SOCKOPT_SET_BYTES(XpubWelcomeMessage,ZMQ_XPUB_WELCOME_MSG)
|
||||
|
||||
SOCKOPT_BOOL(InvertMatching,ZMQ_INVERT_MATCHING) //--- only for ZMQ_PUB, ZMQ_XPUB, ZMQ_SUB
|
||||
|
||||
//--- only for ZMQ_ROUTER
|
||||
SOCKOPT_SET_BOOL(RouterHandover,ZMQ_ROUTER_HANDOVER)
|
||||
SOCKOPT_SET_BOOL(RouterMandatory,ZMQ_ROUTER_MANDATORY)
|
||||
SOCKOPT_SET_BOOL(RouterRaw,ZMQ_ROUTER_RAW)
|
||||
|
||||
//--- only for ZMQ_STREAM
|
||||
SOCKOPT_SET_BOOL(StreamNotify,ZMQ_STREAM_NOTIFY)
|
||||
|
||||
//--- only for ZMQ_ROUTER, ZMQ_STREAM
|
||||
SOCKOPT_SET_BYTES(ConnectRid,ZMQ_CONNECT_RID)
|
||||
|
||||
//--- only for ZMQ_REP, ZMQ_REQ, ZMQ_ROUTER, ZMQ_DEALER
|
||||
SOCKOPT_BYTES(Identity,ZMQ_IDENTITY,255)
|
||||
|
||||
//--- tcp
|
||||
SOCKOPT(int,TcpKeepAlive,ZMQ_TCP_KEEPALIVE)
|
||||
SOCKOPT(int,TcpKeepAliveCount,ZMQ_TCP_KEEPALIVE_CNT)
|
||||
SOCKOPT(int,TcpKeepAliveIdle,ZMQ_TCP_KEEPALIVE_IDLE)
|
||||
SOCKOPT(int,TcpKeepAliveInterval,ZMQ_TCP_KEEPALIVE_INTVL)
|
||||
SOCKOPT(int,TcpMaxRetransmitTimeout,ZMQ_TCP_MAXRT)
|
||||
|
||||
SOCKOPT(int,TypeOfService,ZMQ_TOS) // IP_TOS
|
||||
|
||||
//--- ZMQ_TCP_ACCEPT_FILTER
|
||||
//--- ZMQ_IPC_FILTER_GID
|
||||
//--- ZMQ_IPC_FILTER_PID
|
||||
//--- ZMQ_IPC_FILTER_UID
|
||||
//--- are deprecated in favor of ZAP API and ip address whitelisting/blacklisting
|
||||
SOCKOPT_NTSTR(ZapDomain,ZMQ_ZAP_DOMAIN)
|
||||
|
||||
//--- only for vmci transport
|
||||
SOCKOPT(ulong,VmciBufferSize,ZMQ_VMCI_BUFFER_SIZE) // bytes
|
||||
SOCKOPT(ulong,VmciBufferMinSize,ZMQ_VMCI_BUFFER_MIN_SIZE) // bytes
|
||||
SOCKOPT(ulong,VmciBufferMaxSize,ZMQ_VMCI_BUFFER_MAX_SIZE) // bytes
|
||||
SOCKOPT(int,VmciConnectTimeout,ZMQ_VMCI_CONNECT_TIMEOUT) // milliseconds
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| The option value is a string with predefined byte length |
|
||||
//| |
|
||||
//| If it is a NULL-terminated string without predefined length, |
|
||||
//| The situation is tricky: we do not know the length of the option |
|
||||
//| value beforehand, but the function does not return the correct |
|
||||
//| one, either. So the only option is to guess. |
|
||||
//| |
|
||||
//| Here we adopt the solution of the Java binding. We just guess |
|
||||
//| that the length of a NULL-terminated string option is less than |
|
||||
//| 1024. So hopefully, it is the case. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool SocketOptions::getStringOption(int option,string &value,size_t length)
|
||||
{
|
||||
char buf[];
|
||||
ArrayResize(buf,(int)length);
|
||||
bool res=getOption(option,buf,length);
|
||||
if(res)
|
||||
{
|
||||
value=StringFromUtf8(buf);
|
||||
}
|
||||
ArrayFree(buf);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| The ending means that the converted buffer contains the ending |
|
||||
//| null. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool SocketOptions::setStringOption(int option,const string value,bool ending)
|
||||
{
|
||||
char buf[];
|
||||
StringToUtf8(value,buf,ending);
|
||||
int len = ArraySize(buf);
|
||||
bool res=setOption(option,buf,len);
|
||||
ArrayFree(buf);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
+10
-10
@@ -24,7 +24,7 @@
|
||||
|
||||
#import "libzmq.dll"
|
||||
intptr_t zmq_atomic_counter_new(void);
|
||||
void zmq_atomic_counter_set(intptr_t counter,int value);
|
||||
void zmq_atomic_counter_set(intptr_t counter, int value);
|
||||
int zmq_atomic_counter_inc(intptr_t counter);
|
||||
int zmq_atomic_counter_dec(intptr_t counter);
|
||||
int zmq_atomic_counter_value(intptr_t counter);
|
||||
@@ -34,17 +34,17 @@ void zmq_atomic_counter_destroy(intptr_t &counter_p);
|
||||
//| Atomic counter utility |
|
||||
//+------------------------------------------------------------------+
|
||||
class AtomicCounter
|
||||
{
|
||||
{
|
||||
private:
|
||||
intptr_t m_ref;
|
||||
intptr_t m_ref;
|
||||
|
||||
public:
|
||||
AtomicCounter() {m_ref=zmq_atomic_counter_new();}
|
||||
~AtomicCounter() {zmq_atomic_counter_destroy(m_ref);}
|
||||
AtomicCounter() { m_ref = zmq_atomic_counter_new(); }
|
||||
~AtomicCounter() { zmq_atomic_counter_destroy(m_ref); }
|
||||
|
||||
int increase() {return zmq_atomic_counter_inc(m_ref);}
|
||||
int decrease() {return zmq_atomic_counter_dec(m_ref);}
|
||||
int get() {return zmq_atomic_counter_value(m_ref);}
|
||||
void set(int value) {zmq_atomic_counter_set(m_ref,value);}
|
||||
};
|
||||
int increase() { return zmq_atomic_counter_inc(m_ref); }
|
||||
int decrease() { return zmq_atomic_counter_dec(m_ref); }
|
||||
int get() { return zmq_atomic_counter_value(m_ref); }
|
||||
void set(int value) { zmq_atomic_counter_set(m_ref, value); }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
+74
-39
@@ -33,7 +33,7 @@
|
||||
#define ZMQ_MAX_MSGSZ 5
|
||||
|
||||
//--- Default for new contexts
|
||||
#define ZMQ_IO_THREADS_DFLT 1
|
||||
#define ZMQ_IO_THREADS_DFLT 1
|
||||
#define ZMQ_MAX_SOCKETS_DFLT 1023
|
||||
#define ZMQ_THREAD_PRIORITY_DFLT -1
|
||||
#define ZMQ_THREAD_SCHED_POLICY_DFLT -1
|
||||
@@ -42,23 +42,23 @@
|
||||
intptr_t zmq_ctx_new(void);
|
||||
int zmq_ctx_term(intptr_t context);
|
||||
int zmq_ctx_shutdown(intptr_t context);
|
||||
int zmq_ctx_set(intptr_t context,int option,int optval);
|
||||
int zmq_ctx_get(intptr_t context,int option);
|
||||
int zmq_ctx_set(intptr_t context, int option, int optval);
|
||||
int zmq_ctx_get(intptr_t context, int option);
|
||||
#import
|
||||
class ContextHandleManager: public HandleManager<intptr_t>
|
||||
{
|
||||
intptr_t create() override
|
||||
{
|
||||
return zmq_ctx_new();
|
||||
}
|
||||
void destroy(intptr_t handle) override
|
||||
{
|
||||
if(0!=zmq_ctx_term(handle))
|
||||
class ContextHandleManager : public HandleManager<intptr_t>
|
||||
{
|
||||
intptr_t create() override
|
||||
{
|
||||
return zmq_ctx_new();
|
||||
}
|
||||
void destroy(intptr_t handle) override
|
||||
{
|
||||
if (0 != zmq_ctx_term(handle))
|
||||
{
|
||||
Debug("failed to terminate context");
|
||||
Debug("failed to terminate context");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wraps a 0MZ context |
|
||||
//| |
|
||||
@@ -78,40 +78,75 @@ class ContextHandleManager: public HandleManager<intptr_t>
|
||||
//| and in a manner not easily recognized by humans, for example: |
|
||||
//| "__3kewducdxhkd__" |
|
||||
//+------------------------------------------------------------------+
|
||||
class Context: public GlobalHandle<intptr_t,ContextHandleManager>
|
||||
{
|
||||
class Context : public GlobalHandle<intptr_t, ContextHandleManager>
|
||||
{
|
||||
protected:
|
||||
int get(int option) {return zmq_ctx_get(m_ref,option);}
|
||||
bool set(int option,int optval) {return 0==zmq_ctx_set(m_ref,option,optval);}
|
||||
int get(int option) { return zmq_ctx_get(m_ref, option); }
|
||||
bool set(int option, int optval) { return 0 == zmq_ctx_set(m_ref, option, optval); }
|
||||
|
||||
public:
|
||||
static intptr_t create() { return zmq_ctx_new(); }
|
||||
static void destroy(intptr_t handle)
|
||||
{
|
||||
if (0 != zmq_ctx_term(handle))
|
||||
{
|
||||
Debug("failed to terminate context");
|
||||
}
|
||||
}
|
||||
|
||||
static intptr_t create() {return zmq_ctx_new();}
|
||||
static void destroy(intptr_t handle) {if(0!=zmq_ctx_term(handle)) {Debug("failed to terminate context");}}
|
||||
Context(string shared = NULL) : GlobalHandle<intptr_t, ContextHandleManager>(shared) {}
|
||||
|
||||
Context(string shared=NULL):GlobalHandle<intptr_t,ContextHandleManager>(shared) {}
|
||||
bool shutdown() { return 0 == zmq_ctx_shutdown(m_ref); }
|
||||
|
||||
bool shutdown() {return 0==zmq_ctx_shutdown(m_ref);}
|
||||
int getIoThreads() { return get(ZMQ_IO_THREADS); }
|
||||
void setIoThreads(int value)
|
||||
{
|
||||
if (!set(ZMQ_IO_THREADS, value))
|
||||
{
|
||||
Debug("failed to set ZMQ_IO_THREADS");
|
||||
}
|
||||
}
|
||||
|
||||
int getIoThreads() {return get(ZMQ_IO_THREADS);}
|
||||
void setIoThreads(int value) {if(!set(ZMQ_IO_THREADS,value)) {Debug("failed to set ZMQ_IO_THREADS");}}
|
||||
int getMaxSockets() { return get(ZMQ_MAX_SOCKETS); }
|
||||
void setMaxSockets(int value)
|
||||
{
|
||||
if (!set(ZMQ_MAX_SOCKETS, value))
|
||||
{
|
||||
Debug("failed to set ZMQ_MAX_SOCKETS");
|
||||
}
|
||||
}
|
||||
|
||||
int getMaxSockets() {return get(ZMQ_MAX_SOCKETS);}
|
||||
void setMaxSockets(int value) {if(!set(ZMQ_MAX_SOCKETS,value)) {Debug("failed to set ZMQ_MAX_SOCKETS");}}
|
||||
int getMaxMessageSize() { return get(ZMQ_MAX_MSGSZ); }
|
||||
void setMaxMessageSize(int value)
|
||||
{
|
||||
if (!set(ZMQ_MAX_MSGSZ, value))
|
||||
{
|
||||
Debug("failed to set ZMQ_MAX_MSGSZ");
|
||||
}
|
||||
}
|
||||
|
||||
int getMaxMessageSize() {return get(ZMQ_MAX_MSGSZ);}
|
||||
void setMaxMessageSize(int value) {if(!set(ZMQ_MAX_MSGSZ,value)) {Debug("failed to set ZMQ_MAX_MSGSZ");}}
|
||||
int getSocketLimit() { return get(ZMQ_SOCKET_LIMIT); }
|
||||
|
||||
int getSocketLimit() {return get(ZMQ_SOCKET_LIMIT);}
|
||||
int getIpv6Options() { return get(ZMQ_IPV6); }
|
||||
void setIpv6Options(int value)
|
||||
{
|
||||
if (!set(ZMQ_IPV6, value))
|
||||
{
|
||||
Debug("failed to set ZMQ_IPV6");
|
||||
}
|
||||
}
|
||||
|
||||
int getIpv6Options() {return get(ZMQ_IPV6);}
|
||||
void setIpv6Options(int value) {if(!set(ZMQ_IPV6,value)) {Debug("failed to set ZMQ_IPV6");}}
|
||||
bool isBlocky() { return 1 == get(ZMQ_BLOCKY); }
|
||||
void setBlocky(bool value)
|
||||
{
|
||||
if (!set(ZMQ_BLOCKY, value ? 1 : 0))
|
||||
{
|
||||
Debug("failed to set ZMQ_BLOCKY");
|
||||
}
|
||||
}
|
||||
|
||||
bool isBlocky() {return 1==get(ZMQ_BLOCKY);}
|
||||
void setBlocky(bool value) {if(!set(ZMQ_BLOCKY,value?1:0)) {Debug("failed to set ZMQ_BLOCKY");}}
|
||||
|
||||
//--- Following options is not supported on windows
|
||||
void setSchedulingPolicy(int value) {/*ZMQ_THREAD_SCHED_POLICY*/}
|
||||
void setThreadPriority(int value) {/*ZMQ_THREAD_PRIORITY*/}
|
||||
};
|
||||
//--- Following options is not supported on windows
|
||||
void setSchedulingPolicy(int value) { /*ZMQ_THREAD_SCHED_POLICY*/ }
|
||||
void setThreadPriority(int value) { /*ZMQ_THREAD_PRIORITY*/ }
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
+62
-62
@@ -22,75 +22,75 @@
|
||||
// Following error codes come from Microsoft CRT header errno.h
|
||||
|
||||
// Error codes
|
||||
#define EPERM 1
|
||||
#define ENOENT 2
|
||||
#define ESRCH 3
|
||||
#define EINTR 4
|
||||
#define EIO 5
|
||||
#define ENXIO 6
|
||||
#define E2BIG 7
|
||||
#define ENOEXEC 8
|
||||
#define EBADF 9
|
||||
#define ECHILD 10
|
||||
#define EAGAIN 11
|
||||
#define ENOMEM 12
|
||||
#define EACCES 13
|
||||
#define EFAULT 14
|
||||
#define EBUSY 16
|
||||
#define EEXIST 17
|
||||
#define EXDEV 18
|
||||
#define ENODEV 19
|
||||
#define ENOTDIR 20
|
||||
#define EISDIR 21
|
||||
#define ENFILE 23
|
||||
#define EMFILE 24
|
||||
#define ENOTTY 25
|
||||
#define EFBIG 27
|
||||
#define ENOSPC 28
|
||||
#define ESPIPE 29
|
||||
#define EROFS 30
|
||||
#define EMLINK 31
|
||||
#define EPIPE 32
|
||||
#define EDOM 33
|
||||
#define EDEADLK 36
|
||||
#define ENAMETOOLONG 38
|
||||
#define ENOLCK 39
|
||||
#define ENOSYS 40
|
||||
#define ENOTEMPTY 41
|
||||
#define EPERM 1
|
||||
#define ENOENT 2
|
||||
#define ESRCH 3
|
||||
#define EINTR 4
|
||||
#define EIO 5
|
||||
#define ENXIO 6
|
||||
#define E2BIG 7
|
||||
#define ENOEXEC 8
|
||||
#define EBADF 9
|
||||
#define ECHILD 10
|
||||
#define EAGAIN 11
|
||||
#define ENOMEM 12
|
||||
#define EACCES 13
|
||||
#define EFAULT 14
|
||||
#define EBUSY 16
|
||||
#define EEXIST 17
|
||||
#define EXDEV 18
|
||||
#define ENODEV 19
|
||||
#define ENOTDIR 20
|
||||
#define EISDIR 21
|
||||
#define ENFILE 23
|
||||
#define EMFILE 24
|
||||
#define ENOTTY 25
|
||||
#define EFBIG 27
|
||||
#define ENOSPC 28
|
||||
#define ESPIPE 29
|
||||
#define EROFS 30
|
||||
#define EMLINK 31
|
||||
#define EPIPE 32
|
||||
#define EDOM 33
|
||||
#define EDEADLK 36
|
||||
#define ENAMETOOLONG 38
|
||||
#define ENOLCK 39
|
||||
#define ENOSYS 40
|
||||
#define ENOTEMPTY 41
|
||||
|
||||
// Error codes used in the Secure CRT functions
|
||||
#define EINVAL 22
|
||||
#define ERANGE 34
|
||||
#define EILSEQ 42
|
||||
#define STRUNCATE 80
|
||||
#define EINVAL 22
|
||||
#define ERANGE 34
|
||||
#define EILSEQ 42
|
||||
#define STRUNCATE 80
|
||||
|
||||
// Support EDEADLOCK for compatibility with older Microsoft C versions
|
||||
#define EDEADLOCK EDEADLK
|
||||
#define EDEADLOCK EDEADLK
|
||||
|
||||
// POSIX Supplement
|
||||
#define EALREADY 103
|
||||
#define EBADMSG 104
|
||||
#define ECANCELED 105
|
||||
#define EDESTADDRREQ 109
|
||||
#define EIDRM 111
|
||||
#define EISCONN 113
|
||||
#define ELOOP 114
|
||||
#define ENODATA 120
|
||||
#define ENOLINK 121
|
||||
#define ENOMSG 122
|
||||
#define ENOPROTOOPT 123
|
||||
#define ENOSR 124
|
||||
#define ENOSTR 125
|
||||
#define EALREADY 103
|
||||
#define EBADMSG 104
|
||||
#define ECANCELED 105
|
||||
#define EDESTADDRREQ 109
|
||||
#define EIDRM 111
|
||||
#define EISCONN 113
|
||||
#define ELOOP 114
|
||||
#define ENODATA 120
|
||||
#define ENOLINK 121
|
||||
#define ENOMSG 122
|
||||
#define ENOPROTOOPT 123
|
||||
#define ENOSR 124
|
||||
#define ENOSTR 125
|
||||
#define ENOTRECOVERABLE 127
|
||||
#define EOPNOTSUPP 130
|
||||
#define EOTHER 131
|
||||
#define EOVERFLOW 132
|
||||
#define EOWNERDEAD 133
|
||||
#define EPROTO 134
|
||||
#define EPROTOTYPE 136
|
||||
#define ETIME 137
|
||||
#define ETXTBSY 139
|
||||
#define EWOULDBLOCK 140
|
||||
#define EOPNOTSUPP 130
|
||||
#define EOTHER 131
|
||||
#define EOVERFLOW 132
|
||||
#define EOWNERDEAD 133
|
||||
#define EPROTO 134
|
||||
#define EPROTOTYPE 136
|
||||
#define ETIME 137
|
||||
#define ETXTBSY 139
|
||||
#define EWOULDBLOCK 140
|
||||
|
||||
// Following error codes come from zmq.h
|
||||
// 0MQ errors
|
||||
@@ -0,0 +1,299 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: Socket.mqh |
|
||||
//| This file is part of the mql-zmq project: |
|
||||
//| https://github.com/dingmaotu/mql-zmq |
|
||||
//| |
|
||||
//| Copyright 2016-2017 Li Ding <dingmaotu@hotmail.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
|
||||
#include <Mql/Lang/Mql.mqh>
|
||||
#include <Mql/Lang/Native.mqh>
|
||||
#include "Context.mqh"
|
||||
#include "SocketOptions.mqh"
|
||||
#include "ZmqMsg.mqh"
|
||||
|
||||
//--- Socket types
|
||||
#define ZMQ_PAIR 0
|
||||
#define ZMQ_PUB 1
|
||||
#define ZMQ_SUB 2
|
||||
#define ZMQ_REQ 3
|
||||
#define ZMQ_REP 4
|
||||
#define ZMQ_DEALER 5
|
||||
#define ZMQ_ROUTER 6
|
||||
#define ZMQ_PULL 7
|
||||
#define ZMQ_PUSH 8
|
||||
#define ZMQ_XPUB 9
|
||||
#define ZMQ_XSUB 10
|
||||
#define ZMQ_STREAM 11
|
||||
|
||||
//--- Message options
|
||||
#define ZMQ_MORE 1
|
||||
#define ZMQ_SRCFD 2 // Deprecated
|
||||
#define ZMQ_SHARED 3
|
||||
|
||||
//--- Send/recv options
|
||||
#define ZMQ_DONTWAIT 1
|
||||
#define ZMQ_SNDMORE 2
|
||||
|
||||
//--- Socket transport events (TCP, IPC and TIPC only)
|
||||
#define ZMQ_EVENT_CONNECTED 0x0001
|
||||
#define ZMQ_EVENT_CONNECT_DELAYED 0x0002
|
||||
#define ZMQ_EVENT_CONNECT_RETRIED 0x0004
|
||||
#define ZMQ_EVENT_LISTENING 0x0008
|
||||
#define ZMQ_EVENT_BIND_FAILED 0x0010
|
||||
#define ZMQ_EVENT_ACCEPTED 0x0020
|
||||
#define ZMQ_EVENT_ACCEPT_FAILED 0x0040
|
||||
#define ZMQ_EVENT_CLOSED 0x0080
|
||||
#define ZMQ_EVENT_CLOSE_FAILED 0x0100
|
||||
#define ZMQ_EVENT_DISCONNECTED 0x0200
|
||||
#define ZMQ_EVENT_MONITOR_STOPPED 0x0400
|
||||
#define ZMQ_EVENT_ALL 0xFFFF
|
||||
|
||||
//--- I/O multiplexing
|
||||
#define ZMQ_POLLIN 1
|
||||
#define ZMQ_POLLOUT 2
|
||||
// We only use 0MQ sockets on Windows
|
||||
// So POLLERR and POLLPRI is of no use
|
||||
#define ZMQ_POLLERR 4
|
||||
#define ZMQ_POLLPRI 8
|
||||
|
||||
#define ZMQ_POLLITEMS_DFLT 16
|
||||
//--- fd is SOCKET on Win32, which is defined as UINT_PTR
|
||||
struct PollItem
|
||||
{
|
||||
intptr_t socket;
|
||||
uintptr_t fd;
|
||||
short events;
|
||||
short revents;
|
||||
#ifdef __X64__
|
||||
//--- note here that if the program runs on 64bit runtime, we need to pad the
|
||||
//--- struct to align to 8 bytes
|
||||
//--- thanks https://github.com/feng-ye for the solution to https://github.com/dingmaotu/mql-zmq/issues/14
|
||||
int __unused;
|
||||
#endif
|
||||
|
||||
bool hasInput() const { return (revents & ZMQ_POLLIN) != 0; }
|
||||
bool hasOutput() const { return (revents & ZMQ_POLLOUT) != 0; }
|
||||
};
|
||||
#import "libzmq.dll"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Sockets |
|
||||
//+------------------------------------------------------------------+
|
||||
intptr_t zmq_socket(intptr_t context, int type);
|
||||
int zmq_close(intptr_t s);
|
||||
int zmq_bind(intptr_t s, const char &addr[]);
|
||||
int zmq_connect(intptr_t s, const char &addr[]);
|
||||
int zmq_unbind(intptr_t s, const char &addr[]);
|
||||
int zmq_disconnect(intptr_t s, const char &addr[]);
|
||||
int zmq_send(intptr_t s, const uchar &buf[], size_t len, int flags);
|
||||
int zmq_send_const(intptr_t s, const uchar &buf[], size_t len, int flags);
|
||||
int zmq_recv(intptr_t s, uchar &buf[], size_t len, int flags);
|
||||
int zmq_socket_monitor(intptr_t s, const char &addr[], int events);
|
||||
//+------------------------------------------------------------------+
|
||||
//| Message |
|
||||
//+------------------------------------------------------------------+
|
||||
int zmq_msg_send(zmq_msg_t &msg, intptr_t s, int flags);
|
||||
int zmq_msg_recv(zmq_msg_t &msg, intptr_t s, int flags);
|
||||
//+------------------------------------------------------------------+
|
||||
//| I/O multiplexing |
|
||||
//+------------------------------------------------------------------+
|
||||
int zmq_poll(PollItem &items[], int nitems, long timeout);
|
||||
//+------------------------------------------------------------------+
|
||||
//| Message proxying |
|
||||
//+------------------------------------------------------------------+
|
||||
int zmq_proxy(intptr_t frontend_ref, intptr_t backend_ref, intptr_t capture_ref);
|
||||
int zmq_proxy_steerable(intptr_t frontend_ref, intptr_t backend_ref, intptr_t capture_ref, intptr_t control_ref);
|
||||
#import
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wraps a 0MQ socket |
|
||||
//+------------------------------------------------------------------+
|
||||
class Socket : public SocketOptions
|
||||
{
|
||||
public:
|
||||
Socket(const Context &ctx, int type) : SocketOptions(zmq_socket(ctx.ref(), type)) {}
|
||||
virtual ~Socket()
|
||||
{
|
||||
if (0 != zmq_close(m_ref))
|
||||
{
|
||||
Debug(StringFormat("Failed to close socket 0x%0X", m_ref));
|
||||
}
|
||||
}
|
||||
|
||||
// for better cooperation between objects
|
||||
intptr_t ref() const { return m_ref; }
|
||||
|
||||
bool valid() const { return m_ref != 0; }
|
||||
|
||||
//--- see Zmq::error() if any of the following command failed
|
||||
//--- connection management
|
||||
bool bind(string addr);
|
||||
bool unbind(string addr);
|
||||
bool connect(string addr);
|
||||
bool disconnect(string addr);
|
||||
|
||||
//--- send raw bytes
|
||||
bool send(const uchar &buf[], bool nowait = false) { return -1 != zmq_send(m_ref, buf, ArraySize(buf), nowait ? ZMQ_DONTWAIT : 0); }
|
||||
bool sendConst(const uchar &buf[], bool nowait = false) { return -1 != zmq_send_const(m_ref, buf, ArraySize(buf), nowait ? ZMQ_DONTWAIT : 0); }
|
||||
|
||||
//--- send ZmqMsg
|
||||
bool send(ZmqMsg &msg, bool nowait = false) { return -1 != zmq_msg_send(msg, m_ref, nowait ? ZMQ_DONTWAIT : 0); }
|
||||
//--- send string
|
||||
bool send(string msg, bool nowait = false)
|
||||
{
|
||||
ZmqMsg m(msg);
|
||||
return send(m, nowait);
|
||||
}
|
||||
//--- send empty
|
||||
bool send(bool nowait = false)
|
||||
{
|
||||
ZmqMsg m;
|
||||
return send(m, nowait);
|
||||
}
|
||||
|
||||
//--- same as above 5 but for multipart messages
|
||||
bool sendMore(const uchar &buf[], bool nowait = false);
|
||||
bool sendConstMore(const uchar &buf[], bool nowait = false);
|
||||
bool sendMore(ZmqMsg &msg, bool nowait = false)
|
||||
{
|
||||
int flags = ZMQ_SNDMORE;
|
||||
if (nowait)
|
||||
flags |= ZMQ_DONTWAIT;
|
||||
return -1 != zmq_msg_send(msg, m_ref, flags);
|
||||
}
|
||||
bool sendMore(string msg, bool nowait = false)
|
||||
{
|
||||
ZmqMsg m(msg);
|
||||
return sendMore(m, nowait);
|
||||
}
|
||||
bool sendMore(bool nowait = false)
|
||||
{
|
||||
ZmqMsg m;
|
||||
return sendMore(m, nowait);
|
||||
}
|
||||
|
||||
//--- receive packets
|
||||
bool recv(uchar &buf[], bool nowait = false) { return -1 != zmq_recv(m_ref, buf, ArraySize(buf), nowait ? ZMQ_DONTWAIT : 0); }
|
||||
bool recv(ZmqMsg &msg, bool nowait = false) { return -1 != zmq_msg_recv(msg, m_ref, nowait ? ZMQ_DONTWAIT : 0); }
|
||||
|
||||
//--- monitor socket events
|
||||
bool monitor(string addr, int events);
|
||||
|
||||
//--- proxy
|
||||
static bool proxy(Socket *frontend, Socket *backend, Socket *capture);
|
||||
static bool proxySteerable(Socket *frontend, Socket *backend, Socket *capture, Socket *control);
|
||||
|
||||
//--- poll
|
||||
static int poll(PollItem &arr[], long timeout);
|
||||
|
||||
//--- fill a poll item for this socket
|
||||
void fillPollItem(PollItem &item, short events);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::bind(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr, arr);
|
||||
bool res = (0 == zmq_bind(m_ref, arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::unbind(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr, arr);
|
||||
bool res = (0 == zmq_unbind(m_ref, arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::connect(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr, arr);
|
||||
bool res = (0 == zmq_connect(m_ref, arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::disconnect(string addr)
|
||||
{
|
||||
char arr[];
|
||||
StringToUtf8(addr, arr);
|
||||
bool res = (0 == zmq_disconnect(m_ref, arr));
|
||||
ArrayFree(arr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::monitor(string addr, int events)
|
||||
{
|
||||
char str[];
|
||||
StringToUtf8(addr, str);
|
||||
bool res = (0 == zmq_socket_monitor(m_ref, str, events));
|
||||
ArrayFree(str);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::proxy(Socket *frontend, Socket *backend, Socket *capture)
|
||||
{
|
||||
intptr_t frontend_ref = CheckPointer(frontend) == POINTER_DYNAMIC ? frontend.ref() : 0;
|
||||
intptr_t backend_ref = CheckPointer(backend) == POINTER_DYNAMIC ? backend.ref() : 0;
|
||||
intptr_t capture_ref = CheckPointer(capture) == POINTER_DYNAMIC ? capture.ref() : 0;
|
||||
return 0 == zmq_proxy(frontend_ref, backend_ref, capture_ref);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Socket::proxySteerable(Socket *frontend, Socket *backend, Socket *capture, Socket *control)
|
||||
{
|
||||
intptr_t frontend_ref = CheckPointer(frontend) == POINTER_DYNAMIC ? frontend.ref() : 0;
|
||||
intptr_t backend_ref = CheckPointer(backend) == POINTER_DYNAMIC ? backend.ref() : 0;
|
||||
intptr_t capture_ref = CheckPointer(capture) == POINTER_DYNAMIC ? capture.ref() : 0;
|
||||
intptr_t control_ref = CheckPointer(control) == POINTER_DYNAMIC ? control.ref() : 0;
|
||||
return 0 == zmq_proxy_steerable(frontend_ref, backend_ref, capture_ref, control_ref);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| poll for events. timeout is milliseconds (-1 for indefinite wait |
|
||||
//| and 0 for immediate return) |
|
||||
//+------------------------------------------------------------------+
|
||||
int Socket::poll(PollItem &arr[], long timeout)
|
||||
{
|
||||
return zmq_poll(arr, ArraySize(arr), timeout);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| fill a poll item for this socket |
|
||||
//+------------------------------------------------------------------+
|
||||
void Socket::fillPollItem(PollItem &item, short events)
|
||||
{
|
||||
item.socket = m_ref;
|
||||
item.fd = 0;
|
||||
item.events = events;
|
||||
item.revents = 0;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,383 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: SocketOptions.mqh |
|
||||
//| This file is part of the mql-zmq project: |
|
||||
//| https://github.com/dingmaotu/mql-zmq |
|
||||
//| |
|
||||
//| Copyright 2016-2017 Li Ding <dingmaotu@hotmail.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
|
||||
#include <Mql/Lang/Native.mqh>
|
||||
|
||||
#import "libzmq.dll"
|
||||
// We can overload the same function for different data types
|
||||
// as in the C level the optval paramter is just a pointer
|
||||
#define SOCKOPT_OVERLOAD_ARRAY(TYPE) \
|
||||
int zmq_setsockopt(intptr_t s, int option, const TYPE &optval[], \
|
||||
size_t optvallen); \
|
||||
int zmq_getsockopt(intptr_t s, int option, TYPE &optval[], \
|
||||
size_t &optvallen);
|
||||
|
||||
#define SOCKOPT_OVERLOAD(TYPE) \
|
||||
int zmq_setsockopt(intptr_t s, int option, const TYPE &optval, \
|
||||
size_t optvallen); \
|
||||
int zmq_getsockopt(intptr_t s, int option, TYPE &optval, \
|
||||
size_t &optvallen);
|
||||
|
||||
SOCKOPT_OVERLOAD_ARRAY(uchar)
|
||||
SOCKOPT_OVERLOAD(long)
|
||||
SOCKOPT_OVERLOAD(ulong)
|
||||
SOCKOPT_OVERLOAD(int)
|
||||
SOCKOPT_OVERLOAD(uint)
|
||||
#import
|
||||
|
||||
// Socket options
|
||||
#define ZMQ_AFFINITY 4
|
||||
#define ZMQ_IDENTITY 5
|
||||
#define ZMQ_SUBSCRIBE 6
|
||||
#define ZMQ_UNSUBSCRIBE 7
|
||||
#define ZMQ_RATE 8
|
||||
#define ZMQ_RECOVERY_IVL 9
|
||||
#define ZMQ_SNDBUF 11
|
||||
#define ZMQ_RCVBUF 12
|
||||
#define ZMQ_RCVMORE 13
|
||||
#define ZMQ_FD 14
|
||||
#define ZMQ_EVENTS 15
|
||||
#define ZMQ_TYPE 16
|
||||
#define ZMQ_LINGER 17
|
||||
#define ZMQ_RECONNECT_IVL 18
|
||||
#define ZMQ_BACKLOG 19
|
||||
#define ZMQ_RECONNECT_IVL_MAX 21
|
||||
#define ZMQ_MAXMSGSIZE 22
|
||||
#define ZMQ_SNDHWM 23
|
||||
#define ZMQ_RCVHWM 24
|
||||
#define ZMQ_MULTICAST_HOPS 25
|
||||
#define ZMQ_RCVTIMEO 27
|
||||
#define ZMQ_SNDTIMEO 28
|
||||
#define ZMQ_LAST_ENDPOINT 32
|
||||
#define ZMQ_ROUTER_MANDATORY 33
|
||||
#define ZMQ_TCP_KEEPALIVE 34
|
||||
#define ZMQ_TCP_KEEPALIVE_CNT 35
|
||||
#define ZMQ_TCP_KEEPALIVE_IDLE 36
|
||||
#define ZMQ_TCP_KEEPALIVE_INTVL 37
|
||||
#define ZMQ_IMMEDIATE 39
|
||||
#define ZMQ_XPUB_VERBOSE 40
|
||||
#define ZMQ_ROUTER_RAW 41
|
||||
#define ZMQ_IPV6 42
|
||||
#define ZMQ_MECHANISM 43
|
||||
#define ZMQ_PLAIN_SERVER 44
|
||||
#define ZMQ_PLAIN_USERNAME 45
|
||||
#define ZMQ_PLAIN_PASSWORD 46
|
||||
#define ZMQ_CURVE_SERVER 47
|
||||
#define ZMQ_CURVE_PUBLICKEY 48
|
||||
#define ZMQ_CURVE_SECRETKEY 49
|
||||
#define ZMQ_CURVE_SERVERKEY 50
|
||||
#define ZMQ_PROBE_ROUTER 51
|
||||
#define ZMQ_REQ_CORRELATE 52
|
||||
#define ZMQ_REQ_RELAXED 53
|
||||
#define ZMQ_CONFLATE 54
|
||||
#define ZMQ_ZAP_DOMAIN 55
|
||||
#define ZMQ_ROUTER_HANDOVER 56
|
||||
#define ZMQ_TOS 57
|
||||
#define ZMQ_CONNECT_RID 61
|
||||
#define ZMQ_GSSAPI_SERVER 62
|
||||
#define ZMQ_GSSAPI_PRINCIPAL 63
|
||||
#define ZMQ_GSSAPI_SERVICE_PRINCIPAL 64
|
||||
#define ZMQ_GSSAPI_PLAINTEXT 65
|
||||
#define ZMQ_HANDSHAKE_IVL 66
|
||||
#define ZMQ_SOCKS_PROXY 68
|
||||
#define ZMQ_XPUB_NODROP 69
|
||||
#define ZMQ_BLOCKY 70
|
||||
#define ZMQ_XPUB_MANUAL 71
|
||||
#define ZMQ_XPUB_WELCOME_MSG 72
|
||||
#define ZMQ_STREAM_NOTIFY 73
|
||||
#define ZMQ_INVERT_MATCHING 74
|
||||
#define ZMQ_HEARTBEAT_IVL 75
|
||||
#define ZMQ_HEARTBEAT_TTL 76
|
||||
#define ZMQ_HEARTBEAT_TIMEOUT 77
|
||||
#define ZMQ_XPUB_VERBOSER 78
|
||||
#define ZMQ_CONNECT_TIMEOUT 79
|
||||
#define ZMQ_TCP_MAXRT 80
|
||||
#define ZMQ_THREAD_SAFE 81
|
||||
#define ZMQ_MULTICAST_MAXTPDU 84
|
||||
#define ZMQ_VMCI_BUFFER_SIZE 85
|
||||
#define ZMQ_VMCI_BUFFER_MIN_SIZE 86
|
||||
#define ZMQ_VMCI_BUFFER_MAX_SIZE 87
|
||||
#define ZMQ_VMCI_CONNECT_TIMEOUT 88
|
||||
#define ZMQ_USE_FD 89
|
||||
//+------------------------------------------------------------------+
|
||||
//| A dedicated class to get/set socket options |
|
||||
//+------------------------------------------------------------------+
|
||||
class SocketOptions
|
||||
{
|
||||
protected:
|
||||
intptr_t m_ref;
|
||||
|
||||
#define SOCKOPT_WRAP_ARRAY(TYPE) \
|
||||
bool setOption(int option, const TYPE &value[], size_t len) { return 0 == zmq_setsockopt(m_ref, option, value, len); } \
|
||||
bool getOption(int option, TYPE &value[], size_t &len) { return 0 == zmq_getsockopt(m_ref, option, value, len); }
|
||||
|
||||
#define SOCKOPT_WRAP(TYPE) \
|
||||
bool setOption(int option, TYPE value) { return 0 == zmq_setsockopt(m_ref, option, value, sizeof(TYPE)); } \
|
||||
bool getOption(int option, TYPE &value) \
|
||||
{ \
|
||||
size_t s = sizeof(TYPE); \
|
||||
return 0 == zmq_getsockopt(m_ref, option, value, s); \
|
||||
}
|
||||
|
||||
SOCKOPT_WRAP_ARRAY(uchar)
|
||||
SOCKOPT_WRAP(int)
|
||||
SOCKOPT_WRAP(uint)
|
||||
SOCKOPT_WRAP(long)
|
||||
SOCKOPT_WRAP(ulong)
|
||||
|
||||
bool setStringOption(int option, string value, bool ending = true);
|
||||
bool getStringOption(int option, string &value, size_t length = 1024);
|
||||
SocketOptions(intptr_t ref) : m_ref(ref) {}
|
||||
|
||||
public:
|
||||
//--- option templates
|
||||
//--- various integer options
|
||||
#define SOCKOPT_GET(TYPE, NAME, MACRO) \
|
||||
bool get##NAME(TYPE &value) { return getOption(MACRO, value); }
|
||||
#define SOCKOPT_SET(TYPE, NAME, MACRO) \
|
||||
bool set##NAME(TYPE value) { return setOption(MACRO, value); }
|
||||
#define SOCKOPT(TYPE, NAME, MACRO) \
|
||||
SOCKOPT_GET(TYPE, NAME, MACRO) \
|
||||
SOCKOPT_SET(TYPE, NAME, MACRO)
|
||||
|
||||
//--- boolean options
|
||||
#define SOCKOPT_GET_BOOL(NAME, MACRO) \
|
||||
bool is##NAME(bool &value) \
|
||||
{ \
|
||||
int v; \
|
||||
bool res = getOption(MACRO, v); \
|
||||
value = (v == 1); \
|
||||
return res; \
|
||||
}
|
||||
#define SOCKOPT_SET_BOOL(NAME, MACRO) \
|
||||
bool set##NAME(bool value) { return setOption(MACRO, value ? 1 : 0); }
|
||||
#define SOCKOPT_BOOL(NAME, MACRO) \
|
||||
SOCKOPT_GET_BOOL(NAME, MACRO) \
|
||||
SOCKOPT_SET_BOOL(NAME, MACRO)
|
||||
|
||||
//--- null-terminated string options
|
||||
#define SOCKOPT_GET_NTSTR(NAME, MACRO) \
|
||||
bool get##NAME(string &value) { return getStringOption(MACRO, value); }
|
||||
#define SOCKOPT_SET_NTSTR(NAME, MACRO) \
|
||||
bool set##NAME(string value) { return setStringOption(MACRO, value); }
|
||||
#define SOCKOPT_NTSTR(NAME, MACRO) \
|
||||
SOCKOPT_GET_NTSTR(NAME, MACRO) \
|
||||
SOCKOPT_SET_NTSTR(NAME, MACRO)
|
||||
|
||||
//--- bytes array or string converted options
|
||||
#define SOCKOPT_SET_BYTES(OptionName, Macro) \
|
||||
bool set##OptionName(const uchar &value[]) { return setOption(Macro, value, (size_t)ArraySize(value)); } \
|
||||
bool set##OptionName(string value) { return setStringOption(Macro, value, false); }
|
||||
#define SOCKOPT_GET_BYTES(OptionName, Macro, InitSize) \
|
||||
bool get##OptionName(uchar &value[]) \
|
||||
{ \
|
||||
size_t len = (size_t)InitSize; \
|
||||
ArrayResize(value, (int)len); \
|
||||
bool res = getOption(Macro, value, len); \
|
||||
if (res) \
|
||||
{ \
|
||||
ArrayResize(value, (int)len); \
|
||||
} \
|
||||
return res; \
|
||||
} \
|
||||
bool get##OptionName(string &value) { return getStringOption(Macro, value, InitSize); }
|
||||
#define SOCKOPT_BYTES(OptionName, Macro, InitSize) \
|
||||
SOCKOPT_SET_BYTES(OptionName, Macro) \
|
||||
SOCKOPT_GET_BYTES(OptionName, Macro, InitSize)
|
||||
|
||||
//--- for curve key
|
||||
//--- NOTE that the length of the key array must be 32.
|
||||
//--- since some versions of mt4 and newer versions of mt5 will report error
|
||||
//--- when the length of the array is specified, so the length specification is removed
|
||||
#define SOCKOPT_CURVE_KEY(KeyType, Macro) \
|
||||
bool getCurve##KeyType##Key(uchar &key[]) \
|
||||
{ \
|
||||
size_t len = 32; \
|
||||
return getOption(Macro, key, len); \
|
||||
} \
|
||||
bool getCurve##KeyType##Key(string &key) { return getStringOption(Macro, key, 41); } \
|
||||
bool setCurve##KeyType##Key(const uchar &key[]) { return setOption(Macro, key, 32); } \
|
||||
bool setCurve##KeyType##Key(string key) { return setStringOption(Macro, key); }
|
||||
|
||||
SOCKOPT_GET(int, Type, ZMQ_TYPE)
|
||||
SOCKOPT(ulong, Affinity, ZMQ_AFFINITY) // 64bit bitmask
|
||||
SOCKOPT(int, BackLog, ZMQ_BACKLOG) // number of connections
|
||||
SOCKOPT(int, Timeout, ZMQ_CONNECT_TIMEOUT) // milliseconds
|
||||
SOCKOPT_GET_BOOL(ThreadSafe, ZMQ_THREAD_SAFE)
|
||||
|
||||
SOCKOPT_SET_BOOL(Conflate, ZMQ_CONFLATE) // only for ZMQ_PULL, ZMQ_PUSH, ZMQ_SUB, ZMQ_PUB, ZMQ_DEALER types
|
||||
|
||||
SOCKOPT_GET(int, Events, ZMQ_EVENTS); // bitmask of ZMQ_POLLIN, ZMQ_POLLOUT
|
||||
|
||||
SOCKOPT_GET(uintptr_t, FileDescriptor, ZMQ_FD)
|
||||
|
||||
SOCKOPT_GET(int, Mechanism, ZMQ_MECHANISM) // current security mechanism
|
||||
|
||||
//--- plain
|
||||
SOCKOPT_NTSTR(PlainUsername, ZMQ_PLAIN_USERNAME)
|
||||
SOCKOPT_NTSTR(PlainPassword, ZMQ_PLAIN_PASSWORD)
|
||||
SOCKOPT_BOOL(PlainServer, ZMQ_PLAIN_SERVER)
|
||||
|
||||
//--- gssapi: this is not supported in this binding. Following methods will FAIL if you invoke them
|
||||
SOCKOPT_BOOL(GssApiPlainText, ZMQ_GSSAPI_PLAINTEXT)
|
||||
SOCKOPT_BOOL(GssApiServer, ZMQ_GSSAPI_SERVER)
|
||||
SOCKOPT_NTSTR(GssApiPrincipal, ZMQ_GSSAPI_PRINCIPAL)
|
||||
SOCKOPT_NTSTR(GssApiServicePrincipal, ZMQ_GSSAPI_SERVICE_PRINCIPAL)
|
||||
|
||||
//--- curve
|
||||
SOCKOPT_CURVE_KEY(Public, ZMQ_CURVE_PUBLICKEY)
|
||||
SOCKOPT_CURVE_KEY(Secret, ZMQ_CURVE_SECRETKEY)
|
||||
SOCKOPT_CURVE_KEY(Server, ZMQ_CURVE_SERVERKEY)
|
||||
|
||||
SOCKOPT_SET_BOOL(CurveServer, ZMQ_CURVE_SERVER)
|
||||
|
||||
SOCKOPT_GET_NTSTR(LastEndpoint, ZMQ_LAST_ENDPOINT)
|
||||
|
||||
SOCKOPT(int, HandshakeInterval, ZMQ_HANDSHAKE_IVL) // milliseconds
|
||||
SOCKOPT_SET(int, HeartbeatInterval, ZMQ_HEARTBEAT_IVL) // milliseconds
|
||||
SOCKOPT_SET(int, HeartbeatTimeout, ZMQ_HEARTBEAT_TIMEOUT) // milliseconds
|
||||
SOCKOPT_SET(int, HeartbeatTTL, ZMQ_HEARTBEAT_TTL) // milliseconds
|
||||
|
||||
SOCKOPT_BOOL(Immediate, ZMQ_IMMEDIATE)
|
||||
SOCKOPT_BOOL(Ipv6, ZMQ_IPV6) //--- ZMQ_IPV4ONLY is deprecated, use this instead
|
||||
SOCKOPT(int, Linger, ZMQ_LINGER) // milliseconds
|
||||
SOCKOPT(long, MaxMessageSize, ZMQ_MAXMSGSIZE)
|
||||
|
||||
//--- multicast
|
||||
SOCKOPT(int, MulticastHops, ZMQ_MULTICAST_HOPS) // hops
|
||||
SOCKOPT(int, MulticastMaxTPDU, ZMQ_MULTICAST_MAXTPDU) // bytes
|
||||
SOCKOPT(int, MulticastRate, ZMQ_RATE) // kilobits per second
|
||||
SOCKOPT(int, RecoveryInterval, ZMQ_RECOVERY_IVL) // multicast recovery interval
|
||||
|
||||
//--- there is a problem here: FileDescriptor should be SOCKET type on Windows,
|
||||
//--- while in the zmq doc it is a int. Possible error in the doc
|
||||
SOCKOPT(uintptr_t, UseFileDescriptor, ZMQ_USE_FD)
|
||||
|
||||
SOCKOPT_SET_BOOL(ProbeRouter, ZMQ_PROBE_ROUTER) // only for ZMQ_ROUTER, ZMQ_DEALER, ZMQ_REQ
|
||||
|
||||
SOCKOPT(int, ReceiveBuffer, ZMQ_RCVBUF) // bytes
|
||||
SOCKOPT(int, ReceiveHighWaterMark, ZMQ_RCVHWM) // messages
|
||||
SOCKOPT(int, ReceiveTimeout, ZMQ_RCVTIMEO) // milliseconds
|
||||
SOCKOPT(int, SendBuffer, ZMQ_SNDBUF) // bytes
|
||||
SOCKOPT(int, SendHighWaterMark, ZMQ_SNDHWM) // messages
|
||||
SOCKOPT(int, SendTimeout, ZMQ_SNDTIMEO)
|
||||
|
||||
SOCKOPT_GET_BOOL(ReceiveMore, ZMQ_RCVMORE)
|
||||
|
||||
SOCKOPT(int, ReconnectInterval, ZMQ_RECONNECT_IVL) // milliseconds
|
||||
SOCKOPT(int, ReconnectIntervalMax, ZMQ_RECONNECT_IVL_MAX) // milliseconds
|
||||
|
||||
//--- only for ZMQ_REQ
|
||||
SOCKOPT_SET_BOOL(RequestCorrelated, ZMQ_REQ_CORRELATE)
|
||||
SOCKOPT_SET_BOOL(RequestRelaxed, ZMQ_REQ_RELAXED)
|
||||
|
||||
//--- only for ZMQ_SUB
|
||||
SOCKOPT_SET_BYTES(Subscribe, ZMQ_SUBSCRIBE)
|
||||
SOCKOPT_SET_BYTES(Unsubscribe, ZMQ_UNSUBSCRIBE)
|
||||
|
||||
//--- convenience methods
|
||||
bool subscribe(string channel) { return setSubscribe(channel); }
|
||||
bool unsubscribe(string channel) { return setUnsubscribe(channel); }
|
||||
|
||||
//--- only for ZMQ_XSUB
|
||||
SOCKOPT_BOOL(XpubVerbose, ZMQ_XPUB_VERBOSE)
|
||||
SOCKOPT_BOOL(XpubVerboser, ZMQ_XPUB_VERBOSER)
|
||||
SOCKOPT_BOOL(XpubManual, ZMQ_XPUB_MANUAL)
|
||||
SOCKOPT_BOOL(XpubNoDrop, ZMQ_XPUB_NODROP) // also for ZMQ_PUB
|
||||
SOCKOPT_SET_BYTES(XpubWelcomeMessage, ZMQ_XPUB_WELCOME_MSG)
|
||||
|
||||
SOCKOPT_BOOL(InvertMatching, ZMQ_INVERT_MATCHING) //--- only for ZMQ_PUB, ZMQ_XPUB, ZMQ_SUB
|
||||
|
||||
//--- only for ZMQ_ROUTER
|
||||
SOCKOPT_SET_BOOL(RouterHandover, ZMQ_ROUTER_HANDOVER)
|
||||
SOCKOPT_SET_BOOL(RouterMandatory, ZMQ_ROUTER_MANDATORY)
|
||||
SOCKOPT_SET_BOOL(RouterRaw, ZMQ_ROUTER_RAW)
|
||||
|
||||
//--- only for ZMQ_STREAM
|
||||
SOCKOPT_SET_BOOL(StreamNotify, ZMQ_STREAM_NOTIFY)
|
||||
|
||||
//--- only for ZMQ_ROUTER, ZMQ_STREAM
|
||||
SOCKOPT_SET_BYTES(ConnectRid, ZMQ_CONNECT_RID)
|
||||
|
||||
//--- only for ZMQ_REP, ZMQ_REQ, ZMQ_ROUTER, ZMQ_DEALER
|
||||
SOCKOPT_BYTES(Identity, ZMQ_IDENTITY, 255)
|
||||
|
||||
//--- tcp
|
||||
SOCKOPT(int, TcpKeepAlive, ZMQ_TCP_KEEPALIVE)
|
||||
SOCKOPT(int, TcpKeepAliveCount, ZMQ_TCP_KEEPALIVE_CNT)
|
||||
SOCKOPT(int, TcpKeepAliveIdle, ZMQ_TCP_KEEPALIVE_IDLE)
|
||||
SOCKOPT(int, TcpKeepAliveInterval, ZMQ_TCP_KEEPALIVE_INTVL)
|
||||
SOCKOPT(int, TcpMaxRetransmitTimeout, ZMQ_TCP_MAXRT)
|
||||
|
||||
SOCKOPT(int, TypeOfService, ZMQ_TOS) // IP_TOS
|
||||
|
||||
//--- ZMQ_TCP_ACCEPT_FILTER
|
||||
//--- ZMQ_IPC_FILTER_GID
|
||||
//--- ZMQ_IPC_FILTER_PID
|
||||
//--- ZMQ_IPC_FILTER_UID
|
||||
//--- are deprecated in favor of ZAP API and ip address whitelisting/blacklisting
|
||||
SOCKOPT_NTSTR(ZapDomain, ZMQ_ZAP_DOMAIN)
|
||||
|
||||
//--- only for vmci transport
|
||||
SOCKOPT(ulong, VmciBufferSize, ZMQ_VMCI_BUFFER_SIZE) // bytes
|
||||
SOCKOPT(ulong, VmciBufferMinSize, ZMQ_VMCI_BUFFER_MIN_SIZE) // bytes
|
||||
SOCKOPT(ulong, VmciBufferMaxSize, ZMQ_VMCI_BUFFER_MAX_SIZE) // bytes
|
||||
SOCKOPT(int, VmciConnectTimeout, ZMQ_VMCI_CONNECT_TIMEOUT) // milliseconds
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| The option value is a string with predefined byte length |
|
||||
//| |
|
||||
//| If it is a NULL-terminated string without predefined length, |
|
||||
//| The situation is tricky: we do not know the length of the option |
|
||||
//| value beforehand, but the function does not return the correct |
|
||||
//| one, either. So the only option is to guess. |
|
||||
//| |
|
||||
//| Here we adopt the solution of the Java binding. We just guess |
|
||||
//| that the length of a NULL-terminated string option is less than |
|
||||
//| 1024. So hopefully, it is the case. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool SocketOptions::getStringOption(int option, string &value, size_t length)
|
||||
{
|
||||
uchar buf[];
|
||||
ArrayResize(buf, (int)length);
|
||||
bool res = getOption(option, buf, length);
|
||||
if (res)
|
||||
{
|
||||
value = StringFromUtf8(buf);
|
||||
}
|
||||
ArrayFree(buf);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| The ending means that the converted buffer contains the ending |
|
||||
//| null. |
|
||||
//+------------------------------------------------------------------+
|
||||
bool SocketOptions::setStringOption(int option, const string value, bool ending)
|
||||
{
|
||||
uchar buf[];
|
||||
StringToUtf8(value, buf, ending);
|
||||
int len = ArraySize(buf);
|
||||
bool res = setOption(option, buf, len);
|
||||
ArrayFree(buf);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
+112
-82
@@ -24,130 +24,160 @@
|
||||
|
||||
#import "libzmq.dll"
|
||||
// Encode data with Z85 encoding. Returns 0(NULL) if failed
|
||||
intptr_t zmq_z85_encode(char &str[],const uchar &data[],size_t size);
|
||||
intptr_t zmq_z85_encode(char &str[], const uchar &data[], size_t size);
|
||||
|
||||
// Decode data with Z85 encoding. Returns 0(NULL) if failed
|
||||
intptr_t zmq_z85_decode(uchar &dest[],const char &str[]);
|
||||
intptr_t zmq_z85_decode(uchar &dest[], const char &str[]);
|
||||
|
||||
// Generate z85-encoded public and private keypair with tweetnacl/libsodium
|
||||
int zmq_curve_keypair(char &z85_public_key[],char &z85_secret_key[]);
|
||||
int zmq_curve_keypair(char &z85_public_key[], char &z85_secret_key[]);
|
||||
|
||||
// Derive the z85-encoded public key from the z85-encoded secret key
|
||||
int zmq_curve_public(char &z85_public_key[],const char &z85_secret_key[]);
|
||||
int zmq_curve_public(char &z85_public_key[], const char &z85_secret_key[]);
|
||||
#import
|
||||
//+------------------------------------------------------------------+
|
||||
//| Z85 encoding/decoding |
|
||||
//+------------------------------------------------------------------+
|
||||
class Z85
|
||||
{
|
||||
{
|
||||
public:
|
||||
static bool encode(string &secret,const uchar &data[]);
|
||||
static bool decode(const string secret,uchar &data[]);
|
||||
static bool encode(string &secret, const uchar &data[]);
|
||||
static bool decode(const string secret, uchar &data[]);
|
||||
|
||||
static string encode(string data);
|
||||
static string decode(string secret);
|
||||
static string encode(string data);
|
||||
static string decode(string secret);
|
||||
|
||||
static bool generateKeyPair(uchar &publicKey[],uchar &secretKey[]);
|
||||
static bool derivePublic(uchar &publicKey[],const uchar &secretKey[]);
|
||||
static bool generateKeyPair(uchar &publicKey[], uchar &secretKey[]);
|
||||
static bool derivePublic(uchar &publicKey[], const uchar &secretKey[]);
|
||||
|
||||
static bool generateKeyPair(string &publicKey,string &secretKey);
|
||||
static string derivePublic(const string secretKey);
|
||||
};
|
||||
static bool generateKeyPair(string &publicKey, string &secretKey);
|
||||
static string derivePublic(const string secretKey);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| data must have size multiple of 4 |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Z85::encode(string &secret,const uchar &data[])
|
||||
{
|
||||
int size=ArraySize(data);
|
||||
if(size%4 != 0) return false;
|
||||
bool Z85::encode(string &secret, const uchar &data[])
|
||||
{
|
||||
int size = ArraySize(data);
|
||||
if (size % 4 != 0)
|
||||
return false;
|
||||
|
||||
char str[];
|
||||
ArrayResize(str,(int)(1.25*size+1));
|
||||
char str[];
|
||||
ArrayResize(str, (int)(1.25 * size + 1));
|
||||
|
||||
intptr_t res=zmq_z85_encode(str,data,size);
|
||||
if(res == 0) return false;
|
||||
secret = StringFromUtf8(str);
|
||||
return true;
|
||||
}
|
||||
intptr_t res = zmq_z85_encode(str, data, size);
|
||||
if (res == 0)
|
||||
return false;
|
||||
secret = StringFromUtf8(str);
|
||||
return true;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| secret must be multiples of 5 |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Z85::decode(const string secret,uchar &data[])
|
||||
{
|
||||
int len=StringLen(secret);
|
||||
if(len%5 != 0) return false;
|
||||
bool Z85::decode(const string secret, uchar &data[])
|
||||
{
|
||||
int len = StringLen(secret);
|
||||
if (len % 5 != 0)
|
||||
return false;
|
||||
|
||||
char str[];
|
||||
StringToUtf8(secret,str);
|
||||
ArrayResize(data,(int)(0.8*len));
|
||||
return 0 != zmq_z85_decode(data,str);
|
||||
}
|
||||
char str[];
|
||||
StringToUtf8(secret, str);
|
||||
ArrayResize(data, (int)(0.8 * len));
|
||||
return 0 != zmq_z85_decode(data, str);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| data length should be multiples of 4 and only ascii is supported |
|
||||
//+------------------------------------------------------------------+
|
||||
string Z85::encode(string data)
|
||||
{
|
||||
char str[];
|
||||
StringToUtf8(data,str,false);
|
||||
string res;
|
||||
if(encode(res,str))
|
||||
return res;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
{
|
||||
uchar str[];
|
||||
StringToUtf8(data, str, false);
|
||||
string res;
|
||||
if (encode(res, str))
|
||||
return res;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| secret must be multiples of 5 |
|
||||
//+------------------------------------------------------------------+
|
||||
string Z85::decode(string secret)
|
||||
{
|
||||
uchar data[];
|
||||
decode(secret,data);
|
||||
return StringFromUtf8(data);
|
||||
}
|
||||
string Z85::decode(string secret)
|
||||
{
|
||||
uchar data[];
|
||||
decode(secret, data);
|
||||
return StringFromUtf8(data);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Z85::generateKeyPair(uchar &publicKey[],uchar &secretKey[])
|
||||
{
|
||||
ArrayResize(publicKey,41);
|
||||
ArrayResize(secretKey,41);
|
||||
return 0==zmq_curve_keypair(publicKey, secretKey);
|
||||
}
|
||||
bool Z85::generateKeyPair(uchar &publicKey[], uchar &secretKey[])
|
||||
{
|
||||
char pubKey[41], secKey[41];
|
||||
bool result = (0 == zmq_curve_keypair(pubKey, secKey));
|
||||
if (result)
|
||||
{
|
||||
ArrayResize(publicKey, 41);
|
||||
ArrayResize(secretKey, 41);
|
||||
for (int i = 0; i < 41; i++)
|
||||
{
|
||||
publicKey[i] = (uchar)pubKey[i];
|
||||
secretKey[i] = (uchar)secKey[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Z85::derivePublic(uchar &publicKey[],const uchar &secretKey[])
|
||||
{
|
||||
ArrayResize(publicKey,41);
|
||||
return 0==zmq_curve_public(publicKey, secretKey);
|
||||
}
|
||||
bool Z85::derivePublic(uchar &publicKey[], const uchar &secretKey[])
|
||||
{
|
||||
char pubKey[41];
|
||||
char secKey[41];
|
||||
// Convert uchar array to char array
|
||||
int size = ArraySize(secretKey);
|
||||
for (int i = 0; i < size && i < 41; i++)
|
||||
{
|
||||
secKey[i] = (char)secretKey[i];
|
||||
}
|
||||
|
||||
bool result = (0 == zmq_curve_public(pubKey, secKey));
|
||||
if (result)
|
||||
{
|
||||
ArrayResize(publicKey, 41);
|
||||
for (int i = 0; i < 41; i++)
|
||||
{
|
||||
publicKey[i] = (uchar)pubKey[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Z85::generateKeyPair(string &publicKey,string &secretKey)
|
||||
{
|
||||
uchar sec[],pub[];
|
||||
bool res=generateKeyPair(pub,sec);
|
||||
if(res)
|
||||
{
|
||||
secretKey=StringFromUtf8(sec);
|
||||
publicKey=StringFromUtf8(pub);
|
||||
}
|
||||
ArrayFree(sec);
|
||||
ArrayFree(pub);
|
||||
return res;
|
||||
}
|
||||
bool Z85::generateKeyPair(string &publicKey, string &secretKey)
|
||||
{
|
||||
uchar sec[], pub[];
|
||||
bool res = generateKeyPair(pub, sec);
|
||||
if (res)
|
||||
{
|
||||
secretKey = StringFromUtf8(sec);
|
||||
publicKey = StringFromUtf8(pub);
|
||||
}
|
||||
ArrayFree(sec);
|
||||
ArrayFree(pub);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
string Z85::derivePublic(const string secrect)
|
||||
{
|
||||
uchar sec[],pub[];
|
||||
StringToUtf8(secrect,sec);
|
||||
derivePublic(pub,sec);
|
||||
string pubstr=StringFromUtf8(pub);
|
||||
ArrayFree(sec);
|
||||
ArrayFree(pub);
|
||||
return pubstr;
|
||||
}
|
||||
{
|
||||
uchar sec[], pub[];
|
||||
StringToUtf8(secrect, sec);
|
||||
derivePublic(pub, sec);
|
||||
string pubstr = StringFromUtf8(pub);
|
||||
ArrayFree(sec);
|
||||
ArrayFree(pub);
|
||||
return pubstr;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,98 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Module: Zmq.mqh |
|
||||
//| This file is part of the mql-zmq project: |
|
||||
//| https://github.com/dingmaotu/mql-zmq |
|
||||
//| |
|
||||
//| Copyright 2016-2017 Li Ding <dingmaotu@hotmail.com> |
|
||||
//| |
|
||||
//| Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
//| you may not use this file except in compliance with the License. |
|
||||
//| You may obtain a copy of the License at |
|
||||
//| |
|
||||
//| http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
//| |
|
||||
//| Unless required by applicable law or agreed to in writing, |
|
||||
//| software distributed under the License is distributed on an |
|
||||
//| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
||||
//| either express or implied. |
|
||||
//| See the License for the specific language governing permissions |
|
||||
//| and limitations under the License. |
|
||||
//+------------------------------------------------------------------+
|
||||
#property strict
|
||||
|
||||
#include <Mql/Lang/Native.mqh>
|
||||
#include "AtomicCounter.mqh"
|
||||
#include "Z85.mqh"
|
||||
#include "Socket.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Definitions from zmq.h |
|
||||
//+------------------------------------------------------------------+
|
||||
#define ZMQ_VERSION_MAJOR 4
|
||||
#define ZMQ_VERSION_MINOR 2
|
||||
#define ZMQ_VERSION_PATCH 0
|
||||
|
||||
#define ZMQ_HAS_CAPABILITIES 1
|
||||
|
||||
#import "libzmq.dll"
|
||||
// Error code
|
||||
int zmq_errno(void);
|
||||
// Resolves system errors and 0MQ errors to human-readable string
|
||||
intptr_t zmq_strerror(int errnum);
|
||||
// Run-time API version detection
|
||||
void zmq_version(int &major, int &minor, int &patch);
|
||||
// Probe library capabilities
|
||||
int zmq_has(const char &capability[]);
|
||||
#import
|
||||
//+------------------------------------------------------------------+
|
||||
//| ZMQ global utilities |
|
||||
//+------------------------------------------------------------------+
|
||||
class Zmq
|
||||
{
|
||||
protected:
|
||||
static bool has(string cap);
|
||||
|
||||
public:
|
||||
//--- Capabilities
|
||||
static bool hasIpc() { return has("ipc"); } // ipc - the library supports the ipc:// protocol
|
||||
static bool hasPgm() { return has("pgm"); } // pgm - the library supports the pgm:// protocol
|
||||
static bool hasTipc() { return has("tipc"); }; // tipc - the library supports the tipc:// protocol
|
||||
static bool hasNorm() { return has("norm"); }; // norm - the library supports the norm:// protocol
|
||||
static bool hasCurve() { return has("curve"); }; // curve-the library supports the CURVE security mechanism
|
||||
static bool hasGssApi() { return has("gssapi"); }; // gssapi-the library supports the GSSAPI security mechanism
|
||||
|
||||
//--- Error handling
|
||||
static int errorNumber() { return zmq_errno(); }
|
||||
static string errorMessage(int error = 0);
|
||||
|
||||
//--- Version
|
||||
static string getVersion();
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wrap zmq_has |
|
||||
//+------------------------------------------------------------------+
|
||||
bool Zmq::has(string cap)
|
||||
{
|
||||
char capstr[];
|
||||
StringToUtf8(cap, capstr);
|
||||
bool res = (ZMQ_HAS_CAPABILITIES == zmq_has(capstr));
|
||||
ArrayFree(capstr);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wraps zmq_strerror |
|
||||
//+------------------------------------------------------------------+
|
||||
string Zmq::errorMessage(int error)
|
||||
{
|
||||
intptr_t ref = error > 0 ? zmq_strerror(error) : zmq_strerror(zmq_errno());
|
||||
return StringFromUtf8Pointer(ref);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get version string of current zmq |
|
||||
//+------------------------------------------------------------------+
|
||||
string Zmq::getVersion(void)
|
||||
{
|
||||
int major, minor, patch;
|
||||
zmq_version(major, minor, patch);
|
||||
return StringFormat("%d.%d.%d", major, minor, patch);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
+102
-75
@@ -30,123 +30,150 @@
|
||||
// hopefully MetaQuotes do malloc structs
|
||||
// aligned on pointer address boundaries
|
||||
struct zmq_msg_t
|
||||
{
|
||||
uchar _[64];
|
||||
};
|
||||
{
|
||||
uchar _[64];
|
||||
};
|
||||
|
||||
#import "libzmq.dll"
|
||||
int zmq_msg_init(zmq_msg_t &msg);
|
||||
int zmq_msg_init_size(zmq_msg_t &msg,size_t size);
|
||||
// As mt4 can not provide a zmq_free_fn, and can not let
|
||||
int zmq_msg_init_size(zmq_msg_t &msg, size_t size);
|
||||
// As mt4 can not provide a zmq_free_fn, and can not let
|
||||
// zmq library own the array data, copying is always needed.
|
||||
// Therefore this function will not be used by this binding.
|
||||
// int zmq_msg_init_data(zmq_msg_t &msg,uchar &data[],
|
||||
// int size,int ffn,int hint);
|
||||
int zmq_msg_close(zmq_msg_t &msg);
|
||||
int zmq_msg_move(zmq_msg_t &dest,zmq_msg_t &src);
|
||||
int zmq_msg_copy(zmq_msg_t &dest,zmq_msg_t &src);
|
||||
int zmq_msg_move(zmq_msg_t &dest, zmq_msg_t &src);
|
||||
int zmq_msg_copy(zmq_msg_t &dest, zmq_msg_t &src);
|
||||
// char *
|
||||
intptr_t zmq_msg_data(zmq_msg_t &msg);
|
||||
int zmq_msg_size(zmq_msg_t &msg);
|
||||
int zmq_msg_more(zmq_msg_t &msg);
|
||||
int zmq_msg_get(zmq_msg_t &msg,int property);
|
||||
int zmq_msg_set(zmq_msg_t &msg,int property,int optval);
|
||||
int zmq_msg_get(zmq_msg_t &msg, int property);
|
||||
int zmq_msg_set(zmq_msg_t &msg, int property, int optval);
|
||||
// const char *
|
||||
intptr_t zmq_msg_gets(zmq_msg_t &msg,const char &property[]);
|
||||
intptr_t zmq_msg_gets(zmq_msg_t &msg, const char &property[]);
|
||||
#import
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wraps a zmq_msg_t |
|
||||
//+------------------------------------------------------------------+
|
||||
struct ZmqMsg: public zmq_msg_t
|
||||
{
|
||||
struct ZmqMsg : public zmq_msg_t
|
||||
{
|
||||
protected:
|
||||
int get(int property) {return zmq_msg_get(this,property);}
|
||||
bool set(int property,int value) {return 0==zmq_msg_set(this,property,value);}
|
||||
intptr_t data() {return zmq_msg_data(this);}
|
||||
bool setStringData(string data,bool nullterminated=false);
|
||||
int get(int property) { return zmq_msg_get(this, property); }
|
||||
bool set(int property, int value) { return 0 == zmq_msg_set(this, property, value); }
|
||||
intptr_t data() { return zmq_msg_data(this); }
|
||||
bool setStringData(string data, bool nullterminated = false);
|
||||
|
||||
public:
|
||||
ZmqMsg() {zmq_msg_init(this);}
|
||||
ZmqMsg(int size) {if(0!=zmq_msg_init_size(this,size)){Debug("Failed to init size msg: insufficient space");}}
|
||||
ZmqMsg(string data,bool nullterminated=false) {setStringData(data,nullterminated);}
|
||||
~ZmqMsg() {if(0!=zmq_msg_close(this)){Debug("Failed to close msg");}}
|
||||
ZmqMsg() { zmq_msg_init(this); }
|
||||
ZmqMsg(int size)
|
||||
{
|
||||
if (0 != zmq_msg_init_size(this, size))
|
||||
{
|
||||
Debug("Failed to init size msg: insufficient space");
|
||||
}
|
||||
}
|
||||
ZmqMsg(string data, bool nullterminated = false) { setStringData(data, nullterminated); }
|
||||
~ZmqMsg()
|
||||
{
|
||||
if (0 != zmq_msg_close(this))
|
||||
{
|
||||
Debug("Failed to close msg");
|
||||
}
|
||||
}
|
||||
|
||||
bool rebuild()
|
||||
{
|
||||
if(0!=zmq_msg_close(this)){Debug("Failed to close msg");return false;}
|
||||
return 0==zmq_msg_init(this);
|
||||
}
|
||||
bool rebuild(int size)
|
||||
{
|
||||
if(0!=zmq_msg_close(this)){Debug("Failed to close msg");return false;}
|
||||
return 0==zmq_msg_init_size(this,size);
|
||||
}
|
||||
bool rebuild(string data,bool nullterminated=false)
|
||||
{
|
||||
if(0!=zmq_msg_close(this)){Debug("Failed to close msg");return false;}
|
||||
return setStringData(data,nullterminated);
|
||||
}
|
||||
bool rebuild()
|
||||
{
|
||||
if (0 != zmq_msg_close(this))
|
||||
{
|
||||
Debug("Failed to close msg");
|
||||
return false;
|
||||
}
|
||||
return 0 == zmq_msg_init(this);
|
||||
}
|
||||
bool rebuild(int size)
|
||||
{
|
||||
if (0 != zmq_msg_close(this))
|
||||
{
|
||||
Debug("Failed to close msg");
|
||||
return false;
|
||||
}
|
||||
return 0 == zmq_msg_init_size(this, size);
|
||||
}
|
||||
bool rebuild(string data, bool nullterminated = false)
|
||||
{
|
||||
if (0 != zmq_msg_close(this))
|
||||
{
|
||||
Debug("Failed to close msg");
|
||||
return false;
|
||||
}
|
||||
return setStringData(data, nullterminated);
|
||||
}
|
||||
|
||||
size_t size() {return zmq_msg_size(this);}
|
||||
size_t size() { return zmq_msg_size(this); }
|
||||
|
||||
void getData(uchar &bytes[]);
|
||||
string getData();
|
||||
void setData(const uchar &bytes[]);
|
||||
void getData(uchar &bytes[]);
|
||||
string getData();
|
||||
void setData(const uchar &bytes[]);
|
||||
|
||||
bool more() {return 1==zmq_msg_more(this);}
|
||||
bool more() { return 1 == zmq_msg_more(this); }
|
||||
|
||||
bool copy(ZmqMsg &msg) {return 0 == zmq_msg_copy(this, msg);}
|
||||
bool move(ZmqMsg &msg) {return 0 == zmq_msg_move(this, msg);}
|
||||
bool copy(ZmqMsg &msg) { return 0 == zmq_msg_copy(this, msg); }
|
||||
bool move(ZmqMsg &msg) { return 0 == zmq_msg_move(this, msg); }
|
||||
|
||||
string meta(const string property);
|
||||
};
|
||||
string meta(const string property);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize a utf-8 string message |
|
||||
//+------------------------------------------------------------------+
|
||||
bool ZmqMsg::setStringData(string data,bool nullterminated)
|
||||
{
|
||||
uchar array[];
|
||||
StringToUtf8(data,array,nullterminated);
|
||||
bool res=(0==zmq_msg_init_size(this,ArraySize(array)));
|
||||
if(res)setData(array);
|
||||
return res;
|
||||
}
|
||||
bool ZmqMsg::setStringData(string data, bool nullterminated)
|
||||
{
|
||||
uchar array[];
|
||||
StringToUtf8(data, array, nullterminated);
|
||||
bool res = (0 == zmq_msg_init_size(this, ArraySize(array)));
|
||||
if (res)
|
||||
setData(array);
|
||||
return res;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get message data as bytes array |
|
||||
//+------------------------------------------------------------------+
|
||||
void ZmqMsg::getData(uchar &bytes[])
|
||||
{
|
||||
size_t size=size();
|
||||
intptr_t src=data();
|
||||
if(ArraySize(bytes)<size) ArrayResize(bytes,(int)size);
|
||||
ArrayFromPointer(bytes,src);
|
||||
}
|
||||
{
|
||||
size_t size = size();
|
||||
intptr_t src = data();
|
||||
if (ArraySize(bytes) < size)
|
||||
ArrayResize(bytes, (int)size);
|
||||
ArrayFromPointer(bytes, src);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get message data as utf-8 string |
|
||||
//+------------------------------------------------------------------+
|
||||
string ZmqMsg::getData()
|
||||
{
|
||||
size_t size=size();
|
||||
intptr_t psz=data();
|
||||
return StringFromUtf8Pointer(psz,(int)size);
|
||||
}
|
||||
{
|
||||
size_t size = size();
|
||||
intptr_t psz = data();
|
||||
return StringFromUtf8Pointer(psz, (int)size);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| copy data to message internal storage |
|
||||
//+------------------------------------------------------------------+
|
||||
void ZmqMsg::setData(const uchar &bytes[])
|
||||
{
|
||||
intptr_t dest=data();
|
||||
size_t size=size();
|
||||
ArrayToPointer(bytes,dest,(int)size);
|
||||
}
|
||||
{
|
||||
intptr_t dest = data();
|
||||
size_t size = size();
|
||||
ArrayToPointer(bytes, dest, (int)size);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Wraps zmq_msg_gets: get metadata associated with the msg |
|
||||
//+------------------------------------------------------------------+
|
||||
string ZmqMsg::meta(const string property)
|
||||
{
|
||||
uchar buf[];
|
||||
StringToUtf8(property,buf);
|
||||
intptr_t ref=zmq_msg_gets(this,buf);
|
||||
ArrayFree(buf);
|
||||
return StringFromUtf8Pointer(ref);
|
||||
}
|
||||
{
|
||||
char buf[];
|
||||
StringToUtf8(property, buf);
|
||||
intptr_t ref = zmq_msg_gets(this, buf);
|
||||
ArrayFree(buf);
|
||||
return StringFromUtf8Pointer(ref);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
+1
-1
Submodule Modules/xIdentityService updated: c8669bf493...bc5efed076
+1
-1
Submodule Modules/xServices updated: 5035bab4a4...5875c766a1
@@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xLoggingService", "Modules\
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xBotService", "Modules\xBotService\xBotService.csproj", "{4E14B377-E4FB-4AD4-BD93-B2587FB01D1F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xMQL5Bridge", "Modules\xMQL5Bridge\xMQL5Bridge.csproj", "{95741BBF-E75F-4697-AE30-ADB6E25B7905}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -407,6 +409,18 @@ Global
|
||||
{4E14B377-E4FB-4AD4-BD93-B2587FB01D1F}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4E14B377-E4FB-4AD4-BD93-B2587FB01D1F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4E14B377-E4FB-4AD4-BD93-B2587FB01D1F}.Release|x86.Build.0 = Release|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Release|x64.Build.0 = Release|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -435,5 +449,6 @@ Global
|
||||
{BDD08088-B2A2-48C5-90C3-F19D7813F8C1} = {CA253913-39DE-BFD0-C9A3-4B7EC6FBDF17}
|
||||
{BEFA4CA9-70B0-476D-95A3-E4D066AD48FE} = {CA253913-39DE-BFD0-C9A3-4B7EC6FBDF17}
|
||||
{4E14B377-E4FB-4AD4-BD93-B2587FB01D1F} = {CA253913-39DE-BFD0-C9A3-4B7EC6FBDF17}
|
||||
{95741BBF-E75F-4697-AE30-ADB6E25B7905} = {CA253913-39DE-BFD0-C9A3-4B7EC6FBDF17}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user